Changeset 33 for branches


Ignore:
Timestamp:
Oct 9, 2002 1:39:34 PM (17 years ago)
Author:
forrest
Message:

Presolve in as option

Location:
branches/devel-1
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-1/ClpModel.cpp

    r28 r33  
    9292  maximumIterations_(1000000000),
    9393  defaultHandler_(true),
     94  status_(NULL),
    9495  lengthNames_(0),
    9596  rowNames_(),
     
    152153  delete [] integerType_;
    153154  integerType_ = NULL;
     155  delete [] status_;
     156  status_=NULL;
    154157}
    155158//#############################################################################
     
    384387    objective_ = copyOfArray ( rhs.objective_, numberColumns_ );
    385388    rowObjective_ = copyOfArray ( rhs.rowObjective_, numberRows_ );
     389    if (rhs.status_)
     390      status_ = copyOfArray( rhs.status_,numberColumns_+numberRows_);
     391    else
     392      status_ = NULL;
    386393    ray_ = NULL;
    387394    if (problemStatus_==1)
     
    416423    columnNames_ = std::vector<std::string> ();
    417424    integerType_ = NULL;
     425    status_ = rhs.status_;
    418426  }
    419427}
     
    458466  otherModel.ray_ = ray_;
    459467  ray_ = NULL;
     468  // do status
     469  if (otherModel.status_!=status_) {
     470    delete [] otherModel.status_;
     471    otherModel.status_ = status_;
     472  }
     473  status_ = NULL;
    460474}
    461475//#############################################################################
     
    577591}
    578592char * deleteChar(char * array , int size,
    579                       int number, const int * which,int & newSize)
     593                  int number, const int * which,int & newSize,
     594                  bool ifDelete)
    580595{
    581596  if (array) {
     
    599614      }
    600615    }
    601     delete [] array;
     616    if (ifDelete)
     617      delete [] array;
    602618    array = newArray;
    603619    delete [] deleted;
     
    643659    ray_ = NULL;
    644660  }
     661  if (status_) {
     662    unsigned char * tempC = new unsigned char [newNumberColumns+newNumberRows];
     663    unsigned char * tempR = tempC + newNumberColumns;
     664    memset(tempC,0,(newNumberColumns+newNumberRows)*sizeof(unsigned char));
     665    memcpy(tempC,status_,min(newNumberColumns,numberColumns_)*sizeof(unsigned char));
     666    memcpy(tempR,status_+numberColumns_,min(newNumberRows,numberRows_)*sizeof(unsigned char));
     667    delete [] status_;
     668    status_ = tempC;
     669  }
    645670  numberRows_ = newNumberRows;
    646671  if (newNumberColumns<numberColumns_) {
     
    691716  rowNames_ = std::vector<std::string> ();
    692717  columnNames_ = std::vector<std::string> ();
     718  // status
     719  if (status_) {
     720    unsigned char * tempR  = (unsigned char *) deleteChar((char *)status_+numberColumns_,
     721                                        numberRows_,
     722                                        number, which, newSize,false);
     723    unsigned char * tempC = new unsigned char [numberColumns_+newSize];
     724    memcpy(tempC,status_,numberColumns_*sizeof(unsigned char));
     725    memcpy(tempC+numberColumns_,tempR,newSize*sizeof(unsigned char));
     726    delete [] tempR;
     727    delete [] status_;
     728    status_ = tempC;
     729  }
    693730}
    694731// Deletes columns
     
    718755  columnNames_ = std::vector<std::string> ();
    719756  integerType_ = deleteChar(integerType_,numberColumns_,
    720                             number, which, newSize);
     757                            number, which, newSize,true);
     758  // status
     759  if (status_) {
     760    unsigned char * tempC  = (unsigned char *) deleteChar((char *)status_,
     761                                        numberColumns_,
     762                                        number, which, newSize,false);
     763    unsigned char * temp = new unsigned char [numberRows_+newSize];
     764    memcpy(temp,status_,newSize*sizeof(unsigned char));
     765    memcpy(temp+newSize,status_+numberColumns_,
     766           numberRows_*sizeof(unsigned char));
     767    delete [] tempC;
     768    delete [] status_;
     769    status_ = temp;
     770  }
    721771}
    722772// Infeasibility/unbounded ray (NULL returned if none/wrong)
     
    897947  integerType_ = NULL;
    898948}
     949/* Return copy of status array (char[numberRows+numberColumns]),
     950   use delete [] */
     951unsigned char * 
     952ClpModel::statusCopy() const
     953{
     954  return copyOfArray(status_,numberRows_+numberColumns_);
     955}
     956// Copy in status vector
     957void
     958ClpModel::copyinStatus(const unsigned char * statusArray)
     959{
     960  delete [] status_;
     961  if (statusArray) {
     962    status_ = new unsigned char [numberRows_+numberColumns_];
     963    memcpy(status_,statusArray,(numberRows_+numberColumns_)*sizeof(unsigned char));
     964  } else {
     965    status_=NULL;
     966  }
     967}
  • branches/devel-1/ClpSimplex.cpp

    r31 r33  
    9797  directionOut_(-1),
    9898  pivotRow_(-1),
    99   status_(NULL),
    10099  dj_(NULL),
    101100  rowReducedCost_(NULL),
     
    11051104  directionOut_(-1),
    11061105  pivotRow_(-1),
    1107   status_(NULL),
    11081106  dj_(NULL),
    11091107  rowReducedCost_(NULL),
     
    11941192  directionOut_(-1),
    11951193  pivotRow_(-1),
    1196   status_(NULL),
    11971194  dj_(NULL),
    11981195  rowReducedCost_(NULL),
     
    12981295    if (rhs.columnArray_[i])
    12991296      columnArray_[i] = new CoinIndexedVector(*rhs.columnArray_[i]);
    1300   }
    1301   if (rhs.status_) {
    1302     status_ = copyOfArray( rhs.status_,numberColumns_+numberRows_);
    13031297  }
    13041298  if (rhs.saveStatus_) {
     
    14151409    delete primalColumnPivot_;
    14161410    primalColumnPivot_ = NULL;
    1417     delete status_;
     1411    delete [] status_;
    14181412    status_=NULL;
    14191413  } else {
     
    29972991ClpSimplex::createStatus()
    29982992{
    2999   delete [] status_;
    3000   status_ = new unsigned char [numberColumns_+numberRows_];
     2993  if(!status_)
     2994    status_ = new unsigned char [numberColumns_+numberRows_];
    30012995  memset(status_,0,(numberColumns_+numberRows_)*sizeof(char));
    30022996  int i;
  • branches/devel-1/Makefile.Clp

    r26 r33  
    88OptLevel := -O2
    99
    10 ifeq ($(OptLevel),-g)
    11     CXXFLAGS += -DCLP_DEBUG
    12 endif
    1310
    1411LIBNAME := Clp
     
    2926LIBSRC += ClpSimplexDual.cpp
    3027LIBSRC += ClpSimplexPrimal.cpp
     28# and Presolve stuff
     29LIBSRC += Presolve.cpp
     30LIBSRC += PresolveDoubleton.cpp
     31LIBSRC += PresolveEmpty.cpp
     32LIBSRC += PresolveFixed.cpp
     33LIBSRC += PresolveMatrix.cpp
     34LIBSRC += PresolvePsdebug.cpp
     35LIBSRC += PresolveSingleton.cpp
     36LIBSRC += PresolveZeros.cpp
     37LIBSRC += PresolveDual.cpp                 
     38LIBSRC += PresolveDupcol.cpp               
     39LIBSRC += PresolveForcing.cpp               
     40LIBSRC += PresolveImpliedFree.cpp           
     41LIBSRC += PresolveIsolated.cpp     
     42LIBSRC += PresolveSubst.cpp                 
     43LIBSRC += PresolveTighten.cpp               
     44LIBSRC += PresolveUseless.cpp             
    3145
    3246##############################################################################
     
    3852include ${MakefileDir}/Makefile.coin
    3953include ${MakefileDir}/Makefile.location
     54
     55CXXFLAGS += -DUSE_PRESOLVE
     56ifeq ($(OptLevel),-g)
     57     CXXFLAGS += -DCLP_DEBUG
     58#    CXXFLAGS += -DPRESOLVE_SUMMARY=1 -DDEBUG_PRESOLVE
     59endif
    4060
    4161export ExtraIncDir  := ${CoinIncDir} ${zlibIncDir} ${bzlibIncDir}
  • branches/devel-1/Presolve.cpp

    r31 r33  
    4242  ncols_(0),
    4343  nrows_(0),
    44   nelems_(0)
     44  nelems_(0),
     45  numberPasses_(5)
    4546{
    4647}
     
    166167Presolve::presolvedModel(ClpSimplex & si,
    167168                         double feasibilityTolerance,
    168                          bool keepIntegers)
     169                         bool keepIntegers,
     170                         int numberPasses)
    169171{
    170172  ncols_ = si.getNumCols();
    171173  nrows_ = si.getNumRows();
    172174  nelems_ = si.getNumElements();
     175  numberPasses_ = numberPasses;
    173176
    174177  double maxmin = si.getObjSense();
     
    414417       
    415418
    416     int iLoop1,numberLoops1 = 10;
    417 
    418     for (iLoop1=0;iLoop1<numberLoops1;iLoop1++) {
    419       printf("Starting major pass %d\n",iLoop1+1);
     419    int iLoop;
     420
     421    for (iLoop=0;iLoop<numberPasses_;iLoop++) {
     422      printf("Starting major pass %d\n",iLoop+1);
    420423      const PresolveAction * const paction0 = paction_;
    421424      // look for substitutions with no fill
  • branches/devel-1/PresolveImpliedFree.cpp

    r31 r33  
    240240      const bool nonzero_cost = (cost[j] != 0.0);
    241241
    242       double *save_costs = nonzero_cost ? new double[hinrow[row]] : 0;
     242      double *save_costs = nonzero_cost ? new double[hinrow[row]] : NULL;
    243243
    244244      {
     
    431431      rup[irow] = f->rup;
    432432    }
     433    delete [] save_costs;
    433434    // coeff has now been initialized
    434435
  • branches/devel-1/PresolveMatrix.cpp

    r31 r33  
    477477    acts_ = new double [nrows_];
    478478    memcpy(acts_,si.primalRowSolution(),nrows_*sizeof(double));
     479    if (!si.statusArray())
     480      si.createStatus();
    479481    colstat_ = new unsigned char [nrows_+ncols_];
    480482    memcpy(colstat_,si.statusArray(),
  • branches/devel-1/Test/ClpMain.cpp

    r30 r33  
    7474  DUALTOLERANCE=1,PRIMALTOLERANCE,DUALBOUND,PRIMALWEIGHT,
    7575
    76   LOGLEVEL=101,MAXFACTOR,PERTURBATION,MAXITERATION,
     76  LOGLEVEL=101,MAXFACTOR,PERTURBATION,MAXITERATION,PRESOLVE,
    7777 
    7878  DIRECTION=201,DUALPIVOT,SCALING,ERRORSALLOWED,KEEPNAMES,SPARSEFACTOR,
    79   PRIMALPIVOT,PRESOLVE,
     79  PRIMALPIVOT,
    8080 
    8181  DIRECTORY=301,IMPORT,EXPORT,RESTORE,SAVE,DUALSIMPLEX,PRIMALSIMPLEX,BAB,
     
    796796    parameters[numberParameters-1].append("off");
    797797    parameters[numberParameters++]=
    798       ClpItem("presolve","Whether to presolve problem",
    799               "off",PRESOLVE);
    800     parameters[numberParameters-1].append("on");
     798      ClpItem("presolve","Whether to presolve problem - how many passes",
     799              0,100,PRESOLVE);
    801800    parameters[numberParameters++]=
    802801      ClpItem("spars!eFactor","Whether factorization treated as sparse",
     
    994993          int value = getIntField(argc,argv,&valid);
    995994          if (!valid) {
    996             parameters[iParam].setIntParameter(models+iModel,value);
     995            if (parameters[iParam].type()==PRESOLVE)
     996              preSolve = value;
     997            else
     998              parameters[iParam].setIntParameter(models+iModel,value);
    997999          } else if (valid==1) {
    9981000            abort();
     
    10571059              keepImportNames = 1-action;
    10581060              break;
    1059             case PRESOLVE:
    1060               preSolve = action;
    1061               break;
    10621061            default:
    10631062              abort();
     
    10771076              Presolve pinfo;
    10781077              if (preSolve)
    1079                 model2 = pinfo.presolvedModel(models[iModel],1.0e-8);
     1078                model2 = pinfo.presolvedModel(models[iModel],1.0e-8,preSolve);
    10801079#endif
    10811080#ifdef READLINE     
  • branches/devel-1/Test/Makefile.test

    r22 r33  
    2323##############################################################################
    2424
    25 CXXFLAGS += $(OPTFLAG)
     25CXXFLAGS += $(OPTFLAG)
     26CXXFLAGS += -DUSE_PRESOLVE
     27#ifeq ($(OPTFLAG),-g)
     28    CXXFLAGS += -DCLP_DEBUG -DPRESOLVE_SUMMARY=1
     29#endif
    2630
    2731TESTSRC := ClpMain.cpp
     
    5458        LDFLAGS += -lhistory -lreadline -ltermcap
    5559endif
     60#LDFLAGS += -lefence
    5661
    5762###############################################################################
  • branches/devel-1/include/ClpModel.hpp

    r28 r33  
    230230   double * infeasibilityRay() const;
    231231   double * unboundedRay() const;
     232  /// See if status array exists (partly for OsiClp)
     233  inline bool statusExists() const
     234  { return (status_!=NULL);};
     235  /// Return address of status array (char[numberRows+numberColumns])
     236  inline unsigned char *  statusArray() const
     237  { return status_;};
     238  /** Return copy of status array (char[numberRows+numberColumns]),
     239      use delete [] */
     240  unsigned char *  statusCopy() const;
     241  /// Copy in status vector
     242  void copyinStatus(const unsigned char * statusArray);
     243
    232244  //@}
    233245  /**@name Message handling */
     
    395407  /// Messages
    396408  CoinMessages messages_;
     409  /** Status Region.  I know that not all algorithms need a status
     410      array, but it made sense for things like crossover and put
     411      all permanent stuff in one place.  No assumption is made
     412      about what is in status array (although it might be good to reserve
     413      bottom 3 bits (i.e. 0-7 numeric) for classic status).  This
     414      is number of columns + number of rows long (in that order).
     415  */
     416  unsigned char * status_;
    397417  /// length of names (0 means no names)
    398418  int lengthNames_;
  • branches/devel-1/include/ClpSimplex.hpp

    r28 r33  
    525525  inline bool flagged(int sequence) const
    526526  {return (((status_[sequence]>>6)&1)!=0);};
    527   /// See if status array exists (partly for OsiClp)
    528   inline bool statusExists() const
    529   { return (status_!=NULL);};
    530   /// Return address of status array (char[numberRows+numberColumns])
    531   inline unsigned char *  statusArray()
    532   { return status_;};
    533527  /** Set up status array (can be used by OsiClp).
    534528      Also can be used to set up all slack basis */
     
    634628  /// Pivot Row
    635629  int pivotRow_;
    636   /// Status Region (Owner of array below)
    637   unsigned char * status_;
    638630  /// Working copy of reduced costs (Owner of arrays below)
    639631  double * dj_;
  • branches/devel-1/include/Presolve.hpp

    r29 r33  
    6464  virtual ClpSimplex * presolvedModel(ClpSimplex & si,
    6565                                      double feasibilityTolerance=0.0,
    66                                       bool keepIntegers=true);
     66                                      bool keepIntegers=true,
     67                                      int numberPasses=5);
    6768
    6869  /** Return pointer to presolved model,
     
    9899  int nrows_;
    99100  int nelems_;
     101  /// Number of major passes
     102  int numberPasses_;
    100103
    101104protected:
Note: See TracChangeset for help on using the changeset viewer.