Changeset 95 for trunk


Ignore:
Timestamp:
Jan 16, 2003 12:49:22 PM (17 years ago)
Author:
forrest
Message:

Was trying something for dual - didn't really work

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/ClpPrimalColumnSteepest.cpp

    r92 r95  
    1111#include "CoinHelperFunctions.hpp"
    1212#include <stdio.h>
     13
     14
     15// bias for free variables
     16
     17#define FREE_BIAS 1.0e1
    1318//#############################################################################
    1419// Constructors / Destructor / Assignment
     
    237242          if (fabs(value)>1.0e2*tolerance) {
    238243            // we are going to bias towards free (but only if reasonable)
    239             value *= 1000.0;
     244            value *= FREE_BIAS;
    240245            // store square in list
    241246            if (infeas[iSequence+addSequence])
     
    297302        if (fabs(value)>1.0e2*tolerance) {
    298303          // we are going to bias towards free (but only if reasonable)
    299           value *= 1000.0;
     304          value *= FREE_BIAS;
    300305          // store square in list
    301306          if (infeas[sequenceOut])
     
    361366        if (fabs(value)>tolerance) {
    362367          // we are going to bias towards free (but only if reasonable)
    363           value *= 1000.0;
     368          value *= FREE_BIAS;
    364369          // store square in list
    365370          if (infeas[iSequence+addSequence])
     
    707712        if (fabs(value)>1.0e2*tolerance) {
    708713          // we are going to bias towards free (but only if reasonable)
     714          value *= FREE_BIAS;
    709715          // store square in list
    710           infeasible_->quickAdd(iSequence,1.0e6*value*value);
     716          infeasible_->quickAdd(iSequence,value*value);
    711717        }
    712718        break;
  • trunk/ClpSimplex.cpp

    r92 r95  
    33353335  }
    33363336}
     3337int
     3338ClpSimplex::nextSuperBasic()
     3339{
     3340  if (firstFree_>=0) {
     3341    int returnValue=firstFree_;
     3342    int iColumn=firstFree_+1;
     3343    if (algorithm_>0) {
     3344      // primal
     3345      for (;iColumn<numberRows_+numberColumns_;iColumn++) {
     3346        if (getStatus(iColumn)==superBasic) {
     3347          if (fabs(solution_[iColumn]-lower_[iColumn])<=primalTolerance_) {
     3348            solution_[iColumn]=lower_[iColumn];
     3349            setStatus(iColumn,atLowerBound);
     3350          } else if (fabs(solution_[iColumn]-upper_[iColumn])
     3351                     <=primalTolerance_) {
     3352            solution_[iColumn]=upper_[iColumn];
     3353            setStatus(iColumn,atUpperBound);
     3354          } else if (lower_[iColumn]<-1.0e20&&upper_[iColumn]>1.0e20) {
     3355            setStatus(iColumn,isFree);
     3356          } else {
     3357            break;
     3358          }
     3359        }
     3360      }
     3361    } else {
     3362      // dual
     3363      for (;iColumn<numberRows_+numberColumns_;iColumn++) {
     3364        if (getStatus(iColumn)==isFree)
     3365          if (fabs(dj_[iColumn])>1.0e2*dualTolerance_)
     3366            break;
     3367      }
     3368    }
     3369    firstFree_ = iColumn;
     3370    if (firstFree_==numberRows_+numberColumns_)
     3371      firstFree_=-1;
     3372    return returnValue;
     3373  } else {
     3374    return -1;
     3375  }
     3376}
  • trunk/ClpSimplexDual.cpp

    r92 r95  
     1
    12// Copyright (C) 2002, International Business Machines
    23// Corporation and others.  All Rights Reserved.
     
    530531          assert(dualOut_<=oldOut);
    531532#endif
    532           if(dualOut_<0.0&&factorization_->pivots()&&
     533          if(dualOut_<-10.0e-8&&factorization_->pivots()&&
    533534             getStatus(sequenceIn_)!=isFree) {
    534535            // going backwards - factorize
     
    882883{
    883884  // get pivot row using whichever method it is
    884   pivotRow_=dualRowPivot_->pivotRow();
     885#if 0
     886  // Doesnt seem to help - think harder about free variables
     887  // first see if any free variables and put them in basis
     888  int nextFree = nextSuperBasic();
     889  int chosenRow=-1;
     890  //nextFree=-1; //off
     891  if (nextFree>=0) {
     892    // unpack vector and find a good pivot
     893    int saveIn=sequenceIn_;
     894    sequenceIn_=nextFree;
     895    unpack(rowArray_[1]);
     896    factorization_->updateColumn(rowArray_[2],rowArray_[1],false);
     897
     898    double * work=rowArray_[1]->denseVector();
     899    int number=rowArray_[1]->getNumElements();
     900    int * which=rowArray_[1]->getIndices();
     901    double bestFeasibleAlpha=0.0;
     902    int bestFeasibleRow=-1;
     903    double bestInfeasibleAlpha=0.0;
     904    int bestInfeasibleRow=-1;
     905    int i;
     906
     907    for (i=0;i<number;i++) {
     908      int iRow = which[i];
     909      double alpha = fabs(work[iRow]);
     910      if (alpha>1.0e-3) {
     911        int iSequence=pivotVariable_[iRow];
     912        double value = solution_[iSequence];
     913        double lower = lower_[iSequence];
     914        double upper = upper_[iSequence];
     915        double infeasibility=0.0;
     916        if (value>upper)
     917          infeasibility = value-upper;
     918        else if (value<lower)
     919          infeasibility = lower-value;
     920        if (infeasibility*alpha>bestInfeasibleAlpha&&alpha>1.0e-1) {
     921          if (!flagged(iSequence)) {
     922            bestInfeasibleAlpha = infeasibility*alpha;
     923            bestInfeasibleRow=iRow;
     924          }
     925        }
     926        if (alpha>bestFeasibleAlpha&&(lower>-1.0e20||upper<1.0e20)) {
     927          bestFeasibleAlpha = alpha;
     928          bestFeasibleRow=iRow;
     929        }
     930      }
     931    }
     932    if (bestInfeasibleRow>=0)
     933      chosenRow = bestInfeasibleRow;
     934    else if (bestFeasibleAlpha>1.0e-2)
     935      chosenRow = bestFeasibleRow;
     936    if (chosenRow>=0)
     937      pivotRow_=chosenRow;
     938    sequenceIn_=saveIn;
     939    rowArray_[1]->clear();
     940  }
     941  if (chosenRow<0)
     942#endif
     943    pivotRow_=dualRowPivot_->pivotRow();
     944
    885945  if (pivotRow_>=0) {
    886946    sequenceOut_ = pivotVariable_[pivotRow_];
     
    897957      dualOut_ = lowerOut_ - valueOut_;
    898958    } else {
    899       // odd - it's feasible - go to nearest
     959      // odd (could be free) - it's feasible - go to nearest
    900960      if (valueOut_-lowerOut_<upperOut_-valueOut_) {
    901961        directionOut_ = 1;
  • trunk/Makefile.Clp

    r82 r95  
    5555
    5656# Say Idiot code can use Clp interface
    57 CXXFLAGS += -DCLP_IDIOT
     57CXXFLAGS += -DCLP_IDIOT 
    5858CXXFLAGS += -DUSE_PRESOLVE
    5959ifeq ($(OptLevel),-g)
    6060#     CXXFLAGS += -DCLP_DEBUG
    6161#    CXXFLAGS += -DPRESOLVE_SUMMARY=1 -DDEBUG_PRESOLVE -DCHECK_CONSISTENCY=1
     62endif
     63ifeq ($(OptLevel),-O2)
     64#     CXXFLAGS += -DNDEBUG
    6265endif
    6366
  • trunk/PresolveForcing.cpp

    r63 r95  
    240240        prob->messageHandler()->message(CLP_PRESOLVE_ROWINFEAS,
    241241                                             prob->messages())
    242                                                <<irow
     242                                               <<irow
    243243                                               <<rlo[irow]
    244244                                               <<rup[irow]
  • trunk/PresolveSubst.cpp

    r63 r95  
    12801280        acty += rowelsy[k] * sol[col];
    12811281      }
    1282       PRESOLVEASSERT(fabs(acty - acts[jrowy]) < 100*ZTOLDP);
     1282
     1283#if     DEBUG_PRESOLVE
     1284       PRESOLVEASSERT(fabs(acty - acts[jrowy]) < 100*ZTOLDP);
     1285#endif
    12831286
    12841287      // RECOMPUTING
  • trunk/Test/unitTest.cpp

    r65 r95  
    2929#include "Idiot.hpp"
    3030#endif
     31
     32
     33#include <time.h>
     34#ifndef _MSC_VER
     35#include <sys/times.h>
     36#include <sys/resource.h>
     37#include <unistd.h>
     38#endif
     39
     40static double cpuTime()
     41{
     42  double cpu_temp;
     43#if defined(_MSC_VER)
     44  unsigned int ticksnow;        /* clock_t is same as int */
     45 
     46  ticksnow = (unsigned int)clock();
     47 
     48  cpu_temp = (double)((double)ticksnow/CLOCKS_PER_SEC);
     49#else
     50  struct rusage usage;
     51  getrusage(RUSAGE_SELF,&usage);
     52  cpu_temp = usage.ru_utime.tv_sec;
     53  cpu_temp += 1.0e-6*((double) usage.ru_utime.tv_usec);
     54#endif
     55  return cpu_temp;
     56}
     57
    3158
    3259//#############################################################################
     
    233260    mpsName.push_back("wood1p");min.push_back(true);nRows.push_back(245);nCols.push_back(2594);objValueTol.push_back(1.e-10);objValue.push_back(1.4429024116e+00);
    234261    mpsName.push_back("woodw");min.push_back(true);nRows.push_back(1099);nCols.push_back(8405);objValueTol.push_back(1.e-10);objValue.push_back(1.3044763331E+00);
     262
     263    double timeTaken =0.0;
    235264  // Loop once for each Mps File
    236265    for (m=0; m<mpsName.size(); m++ ) {
     
    242271      CoinMpsIO mps;
    243272      mps.readMps(fn.c_str(),"mps");
     273      double time1 = cpuTime();
    244274      ClpSimplex solution=empty;
    245275      solution.loadProblem(*mps.getMatrixByCol(),mps.getColLower(),
     
    277307       
    278308        delete model2;
     309#if 1
    279310        printf("Resolving from postsolved model\n");
    280311        // later try without (1) and check duals before solve
     
    289320               solution.sumPrimalInfeasibilities(),
    290321               solution.numberPrimalInfeasibilities());
     322#endif
    291323        if (0) {
    292324          Presolve pinfoA;
     
    324356        }
    325357      }
     358      double time2 = cpuTime()-time1;
     359      timeTaken += time2;
     360      printf("Took %g seconds\n",time2);
    326361      // Test objective solution value
    327362      {
     
    334369      }
    335370    }
    336    
     371    printf("Total time %g seconds\n",timeTaken);
    337372  }
    338373  else {
     
    340375    testingMessage( "***use -netlib to test class***\n" );
    341376  }
    342 
     377 
    343378  testingMessage( "All tests completed successfully\n" );
    344379  return 0;
  • trunk/include/ClpSimplex.hpp

    r92 r95  
    416416  /// Sanity check on input rim data (after scaling) - returns true if okay
    417417  bool sanityCheck();
     418  /** Get next superbasic (primal) or next free (dual), -1 if none */
     419  int nextSuperBasic();
    418420  //@}
    419421  public:
Note: See TracChangeset for help on using the changeset viewer.