Changeset 426
 Timestamp:
 Sep 19, 2006 3:17:46 PM (14 years ago)
 Location:
 branches/devel/Cbc/src
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

branches/devel/Cbc/src/CbcModel.cpp
r424 r426 54 54 55 55 #include "CoinTime.hpp" 56 #include "CoinMpsIO.hpp" 56 57 57 58 #include "CbcCompareActual.hpp" … … 5567 5568 */ 5568 5569 delete [] integerVariable_; 5570 integerVariable_ = NULL; 5569 5571 numberIntegers_=0; 5570 5572 int numberColumns = getNumCols(); … … 5586 5588 oldObject[nObjects++]=oldObject[iObject]; 5587 5589 } 5590 // See if there any SOS 5591 #ifdef COIN_HAS_CLP 5592 if (!nObjects) { 5593 OsiClpSolverInterface * clpSolver 5594 = dynamic_cast<OsiClpSolverInterface *> (solver_); 5595 if (clpSolver&&clpSolver>numberSOS()) { 5596 // deal with sos 5597 const CoinSet * setInfo = clpSolver>setInfo(); 5598 int numberSOS = clpSolver>numberSOS(); 5599 nObjects=0; 5600 delete [] oldObject; 5601 oldObject = new CbcObject * [numberSOS]; 5602 for (int i=0;i<numberSOS;i++) { 5603 int type = setInfo[i].setType(); 5604 int n=setInfo[i].numberEntries(); 5605 const int * which = setInfo[i].which(); 5606 const double * weights = setInfo[i].weights(); 5607 oldObject[nObjects++] = new CbcSOS(this,n,which,weights,i,type); 5608 } 5609 } 5610 } 5611 #endif 5588 5612 5589 5613 /* … … 5591 5615 Make a large enough array for all objects 5592 5616 */ 5617 delete [] integerVariable_; 5593 5618 object_ = new CbcObject * [numberIntegers_+nObjects]; 5594 5619 numberObjects_=numberIntegers_+nObjects; … … 7960 7985 solverCharacteristics_ = solverCharacteristics; 7961 7986 } 7987 /* preProcess problem  replacing solver 7988 If makeEquality true then <= cliques converted to ==. 7989 Presolve will be done numberPasses times. 7990 7991 Returns NULL if infeasible 7992 7993 If makeEquality is 1 add slacks to get cliques, 7994 if 2 add slacks to get sos (but only if looks plausible) and keep sos info 7995 */ 7996 CglPreProcess * 7997 CbcModel::preProcess( int makeEquality, int numberPasses, int tuning) 7998 { 7999 CglPreProcess * process = new CglPreProcess(); 8000 // Default set of cut generators 8001 CglProbing generator1; 8002 generator1.setUsingObjective(true); 8003 generator1.setMaxPass(3); 8004 generator1.setMaxProbeRoot(solver_>getNumCols()); 8005 generator1.setMaxElements(100); 8006 generator1.setMaxLookRoot(50); 8007 generator1.setRowCuts(3); 8008 // Add in generators 8009 process>addCutGenerator(&generator1); 8010 process>messageHandler()>setLogLevel(this>logLevel()); 8011 /* model may not have created objects 8012 If none then create 8013 */ 8014 if (!numberIntegers_!numberObjects_) { 8015 this>findIntegers(true,1); 8016 } 8017 // Do SOS 8018 int i; 8019 int numberSOS2=0; 8020 for (i=0;i<numberObjects_;i++) { 8021 CbcSOS * objSOS = 8022 dynamic_cast <CbcSOS *>(object_[i]) ; 8023 if (objSOS) { 8024 int type = objSOS>sosType(); 8025 if (type==2) 8026 numberSOS2++; 8027 } 8028 } 8029 if (numberSOS2) { 8030 // SOS 8031 int numberColumns = solver_>getNumCols(); 8032 char * prohibited = new char[numberColumns]; 8033 memset(prohibited,0,numberColumns); 8034 for (i=0;i<numberObjects_;i++) { 8035 CbcSOS * objSOS = 8036 dynamic_cast <CbcSOS *>(object_[i]) ; 8037 if (objSOS) { 8038 int type = objSOS>sosType(); 8039 if (type==2) { 8040 int n=objSOS>numberMembers(); 8041 const int * which = objSOS>members(); 8042 for (int j=0;j<n;j++) { 8043 int iColumn = which[j]; 8044 prohibited[iColumn]=1; 8045 } 8046 } 8047 } 8048 } 8049 process>passInProhibited(prohibited,numberColumns); 8050 delete [] prohibited; 8051 } 8052 // Tell solver we are not in Branch and Cut 8053 solver_>setHintParam(OsiDoInBranchAndCut,true,OsiHintDo) ; 8054 OsiSolverInterface * newSolver = process>preProcessNonDefault(*solver_, makeEquality, 8055 numberPasses, tuning); 8056 // Tell solver we are not in Branch and Cut 8057 solver_>setHintParam(OsiDoInBranchAndCut,false,OsiHintDo) ; 8058 if (newSolver) { 8059 int numberOriginalObjects=numberObjects_; 8060 OsiSolverInterface * originalSolver = solver_; 8061 solver_=newSolver>clone(); // clone as process owns solver 8062 // redo sequence 8063 numberIntegers_=0; 8064 int numberColumns = solver_>getNumCols(); 8065 int nOrig = originalSolver>getNumCols(); 8066 const int * originalColumns = process>originalColumns(); 8067 // allow for cliques etc 8068 nOrig = CoinMax(nOrig,originalColumns[numberColumns1]+1); 8069 CbcObject ** originalObject = object_; 8070 // object number or 1 8071 int * temp = new int[nOrig]; 8072 int iColumn; 8073 for (iColumn=0;iColumn<nOrig;iColumn++) 8074 temp[iColumn]=1; 8075 int iObject; 8076 numberObjects_=0; 8077 int nNonInt=0; 8078 for (iObject=0;iObject<numberOriginalObjects;iObject++) { 8079 iColumn = originalObject[iObject]>columnNumber(); 8080 if (iColumn<0) { 8081 nNonInt++; 8082 } else { 8083 temp[iColumn]=iObject; 8084 } 8085 } 8086 int numberNewIntegers=0; 8087 int numberOldIntegers=0; 8088 int numberOldOther=0; 8089 for (iColumn=0;iColumn<numberColumns;iColumn++) { 8090 int jColumn = originalColumns[iColumn]; 8091 if (temp[jColumn]>=0) { 8092 int iObject= temp[jColumn]; 8093 CbcSimpleInteger * obj = 8094 dynamic_cast <CbcSimpleInteger *>(originalObject[iObject]) ; 8095 if (obj) 8096 numberOldIntegers++; 8097 else 8098 numberOldOther++; 8099 } else if (isInteger(iColumn)) { 8100 numberNewIntegers++; 8101 } 8102 } 8103 /* 8104 Allocate an array to hold the indices of the integer variables. 8105 Make a large enough array for all objects 8106 */ 8107 numberObjects_= numberNewIntegers+numberOldIntegers+numberOldOther+nNonInt; 8108 object_ = new CbcObject * [numberObjects_]; 8109 delete [] integerVariable_; 8110 integerVariable_ = new int [numberNewIntegers+numberOldIntegers]; 8111 /* 8112 Walk the variables again, filling in the indices and creating objects for 8113 the integer variables. Initially, the objects hold the index and upper & 8114 lower bounds. 8115 */ 8116 numberIntegers_=0; 8117 for (iColumn=0;iColumn<numberColumns;iColumn++) { 8118 int jColumn = originalColumns[iColumn]; 8119 if (temp[jColumn]>=0) { 8120 int iObject= temp[jColumn]; 8121 CbcSimpleInteger * obj = 8122 dynamic_cast <CbcSimpleInteger *>(originalObject[iObject]) ; 8123 if (obj) { 8124 object_[numberIntegers_] = originalObject[iObject]>clone(); 8125 // redo ids etc 8126 object_[numberIntegers_]>redoSequenceEtc(this,numberColumns,originalColumns); 8127 integerVariable_[numberIntegers_++]=iColumn; 8128 } 8129 } else if (isInteger(iColumn)) { 8130 object_[numberIntegers_] = 8131 new CbcSimpleInteger(this,numberIntegers_,iColumn); 8132 integerVariable_[numberIntegers_++]=iColumn; 8133 } 8134 } 8135 numberObjects_=numberIntegers_; 8136 // Now append other column stuff 8137 for (iColumn=0;iColumn<numberColumns;iColumn++) { 8138 int jColumn = originalColumns[iColumn]; 8139 if (temp[jColumn]>=0) { 8140 int iObject= temp[jColumn]; 8141 CbcSimpleInteger * obj = 8142 dynamic_cast <CbcSimpleInteger *>(originalObject[iObject]) ; 8143 if (!obj) { 8144 object_[numberObjects_] = originalObject[iObject]>clone(); 8145 // redo ids etc 8146 object_[numberObjects_]>redoSequenceEtc(this,numberColumns,originalColumns); 8147 numberObjects_++; 8148 } 8149 } 8150 } 8151 // now append non column stuff 8152 for (iObject=0;iObject<numberOriginalObjects;iObject++) { 8153 iColumn = originalObject[iObject]>columnNumber(); 8154 if (iColumn<0) { 8155 object_[numberObjects_] = originalObject[iObject]>clone(); 8156 // redo ids etc 8157 object_[numberObjects_]>redoSequenceEtc(this,numberColumns,originalColumns); 8158 numberObjects_++; 8159 } 8160 delete originalObject[iObject]; 8161 } 8162 delete [] originalObject; 8163 delete [] temp; 8164 if (!numberObjects_) 8165 handler_>message(CBC_NOINT,messages_) << CoinMessageEol ; 8166 return process; 8167 } else { 8168 // infeasible 8169 delete process; 8170 return NULL; 8171 } 8172 8173 } 8174 /* Does postprocessing  original solver back. 8175 User has to delete process */ 8176 void 8177 CbcModel::postProcess(CglPreProcess * process) 8178 { 8179 process>postProcess(*solver_); 8180 delete solver_; 8181 solver_ = process>originalModel(); 8182 } 7962 8183 // Create C++ lines to get to current state 7963 8184 void 
branches/devel/Cbc/src/CbcModel.hpp
r424 r426 28 28 class CbcStatistics; 29 29 class CbcEventHandler ; 30 class CglPreProcess; 30 31 31 32 //############################################################################# … … 220 221 */ 221 222 OsiSolverInterface * strengthenedModel(); 223 /** preProcess problem  replacing solver 224 If makeEquality true then <= cliques converted to ==. 225 Presolve will be done numberPasses times. 226 227 Returns NULL if infeasible 228 229 If makeEquality is 1 add slacks to get cliques, 230 if 2 add slacks to get sos (but only if looks plausible) and keep sos info 231 */ 232 CglPreProcess * preProcess( int makeEquality=0, int numberPasses=5, 233 int tuning=5); 234 /** Does postprocessing  original solver back. 235 User has to delete process */ 236 void postProcess(CglPreProcess * process); 222 237 private: 223 238 /** \brief Evaluate a subproblem using cutting planes and heuristics 
branches/devel/Cbc/src/CoinSolve.cpp
r424 r426 16 16 #include "CoinHelperFunctions.hpp" 17 17 // Same version as CBC 18 #define CBCVERSION "1.0 1.00"18 #define CBCVERSION "1.02.00" 19 19 20 20 #include "CoinMpsIO.hpp"
Note: See TracChangeset
for help on using the changeset viewer.