Changeset 68
 Timestamp:
 Feb 25, 2005 3:58:02 PM (16 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Samples/sample2.cpp
r58 r68 33 33 #include "CglFlowCover.hpp" 34 34 #include "CglMixedIntegerRounding.hpp" 35 // Preprocessing 36 #include "CglPreProcess.hpp" 35 37 36 38 // Heuristics … … 73 75 #ifdef COIN_USE_CLP 74 76 OsiClpSolverInterface solver1; 75 //solver1.messageHandler()>setLogLevel(0);76 CbcModel model(solver1);77 77 #elif COIN_USE_OSL 78 78 OsiOslSolverInterface solver1; 79 //solver1.messageHandler()>setLogLevel(0); 80 CbcModel model(solver1); 81 #endif 82 model.solver()>setHintParam(OsiDoReducePrint,true,OsiHintTry); 79 #endif 83 80 84 81 // Read in model using argv[1] … … 86 83 std::string mpsFileName = "../../Mps/Sample/p0033.mps"; 87 84 if (argc>=2) mpsFileName = argv[1]; 88 int numMpsReadErrors = model.solver()>readMps(mpsFileName.c_str(),"");85 int numMpsReadErrors = solver1.readMps(mpsFileName.c_str(),""); 89 86 assert(numMpsReadErrors==0); 90 87 double time1 = CoinCpuTime(); 88 89 /* Options are: 90 preprocess to do preprocessing 91 time in minutes 92 if 2 parameters and numeric taken as time 93 */ 94 bool preProcess=false; 95 double minutes=1.0; 96 int nGoodParam=0; 97 for (int iParam=2; iParam<argc;iParam++) { 98 if (!strcmp(argv[iParam],"preprocess")) { 99 preProcess=true; 100 nGoodParam++; 101 } else if (!strcmp(argv[iParam],"time")) { 102 if (iParam+1<argc&&isdigit(argv[iParam+1][0])) { 103 minutes=atof(argv[iParam+1]); 104 if (minutes>=0.0) { 105 nGoodParam+=2; 106 iParam++; // skip time 107 } 108 } 109 } 110 } 111 if (nGoodParam==0&&argc==3&&isdigit(argv[2][0])) { 112 // If time is given then stop after that number of minutes 113 minutes = atof(argv[2]); 114 if (minutes>=0.0) 115 nGoodParam=1; 116 } 117 if (nGoodParam!=argc2) { 118 printf("Usage <file> [preprocess] [time <minutes>] or <file> <minutes>\n"); 119 exit(1); 120 } 121 solver1.initialSolve(); 122 // Reduce printout 123 solver1.setHintParam(OsiDoReducePrint,true,OsiHintTry); 124 // See if we want preprocessing 125 OsiSolverInterface * solver2=&solver1; 126 CglPreProcess process; 127 if (preProcess) { 128 /* Do not try and produce equality cliques and 129 do up to 5 passes */ 130 solver2 = process.preProcess(solver1,false,5); 131 if (!solver2) { 132 printf("Preprocessing says infeasible\n"); 133 exit(2); 134 } 135 solver2>resolve(); 136 } 137 CbcModel model(*solver2); 138 model.solver()>setHintParam(OsiDoReducePrint,true,OsiHintTry); 91 139 // Set up some cut generators and defaults 92 140 // Probing first as gets tight bounds on continuous … … 95 143 generator1.setUsingObjective(true); 96 144 generator1.setMaxPass(3); 97 generator1.setMaxProbe(100); 145 // Number of unsatisfied variables to look at 146 generator1.setMaxProbe(10); 147 // How far to follow the consequences 98 148 generator1.setMaxLook(50); 149 // Only look at rows with fewer than this number of elements 150 generator1.setMaxElements(200); 99 151 generator1.setRowCuts(3); 100 // generator1.snapshot(*model.solver());101 //generator1.createCliques(*model.solver(),2,1000,true);102 //generator1.setMode(0);103 152 104 153 CglGomory generator2; … … 122 171 123 172 // Add in generators 173 // Experiment with 1 and 99 etc 124 174 model.addCutGenerator(&generator1,1,"Probing"); 125 175 model.addCutGenerator(&generator2,1,"Gomory"); … … 129 179 model.addCutGenerator(&flowGen,1,"FlowCover"); 130 180 model.addCutGenerator(&mixedGen,1,"MixedIntegerRounding"); 131 181 // Say we want timings 182 int numberGenerators = model.numberCutGenerators(); 183 int iGenerator; 184 for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) { 185 CbcCutGenerator * generator = model.cutGenerator(iGenerator); 186 generator>setTiming(true); 187 } 132 188 #ifdef COIN_USE_CLP 133 189 OsiClpSolverInterface * osiclp = dynamic_cast< OsiClpSolverInterface*> (model.solver()); … … 182 238 183 239 // If time is given then stop after that number of minutes 184 if (argc>2) { 185 int minutes = atoi(argv[2]); 240 if (minutes>=0.0) { 186 241 std::cout<<"Stopping after "<<minutes<<" minutes"<<std::endl; 187 assert (minutes>=0);188 242 model.setDblParam(CbcModel::CbcMaximumSeconds,60.0*minutes); 189 243 } 190 244 // Switch off most output 191 if (model.getNumCols()< 3000) {245 if (model.getNumCols()<3000) { 192 246 model.messageHandler()>setLogLevel(1); 193 247 //model.solver()>messageHandler()>setLogLevel(0); … … 199 253 //model.solver()>messageHandler()>setLogLevel(2); 200 254 //model.setPrintFrequency(50); 201 //#define DEBUG_CUTS 2 202 #if DEBUG_CUTS==1 203 // Set up debugger by value 204 { 205 int numberColumns=model.getNumCols(); 206 double * solution = new double[numberColumns]; 207 memset(solution, 0,numberColumns*sizeof(double)); 208 // Set nonzero integers 209 solution[1]=1.0; 210 solution[18]=1.0; 211 solution[33]=1.0; 212 solution[59]=1.0; 213 model.solver()>activateRowCutDebugger(solution); 214 delete [] solution; 215 } 216 #elif DEBUG_CUTS==2 217 // Set up debugger by name 218 { 255 #ifdef DEBUG_CUTS 256 // Set up debugger by name (only if no preprocesing) 257 if (!preProcess) { 219 258 std::string problemName ; 220 259 model.solver()>getStrParam(OsiProbName,problemName) ; … … 222 261 } 223 262 #endif 224 double time1 = CoinCpuTime(); 225 226 if (0) { 227 // integer presolve 228 CbcModel * model2 = model.integerPresolve(); 229 if (model2) { 230 // Do complete search 263 264 // Do complete search 231 265 232 model2>branchAndBound(); 233 // get back solution 234 model.originalModel(model2,false); 235 } else { 236 // infeasible 237 exit(1); 238 } 239 } else { 240 // Do complete search 241 242 model.branchAndBound(); 243 } 266 model.branchAndBound(); 244 267 245 268 std::cout<<mpsFileName<<" took "<<CoinCpuTime()time1<<" seconds, " … … 249 272 <<std::endl; 250 273 251 printf("Exact obj %18.18g\n",model.getObjValue());252 274 // Print more statistics 253 275 std::cout<<"Cuts at root node changed objective from "<<model.getContinuousObjective() 254 276 <<" to "<<model.rootObjectiveAfterCuts()<<std::endl; 255 277 256 int numberGenerators = model.numberCutGenerators(); 257 for (int iGenerator=0;iGenerator<numberGenerators;iGenerator++) { 278 for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) { 258 279 CbcCutGenerator * generator = model.cutGenerator(iGenerator); 259 280 std::cout<<generator>cutGeneratorName()<<" was tried " 260 281 <<generator>numberTimesEntered()<<" times and created " 261 282 <<generator>numberCutsInTotal()<<" cuts of which " 262 <<generator>numberCutsActive()<<" were active after adding rounds of cuts" 263 <<std::endl; 283 <<generator>numberCutsActive()<<" were active after adding rounds of cuts"; 284 if (generator>timing()) 285 std::cout<<" ( "<<generator>timeInCutGenerator()<<" seconds)"<<std::endl; 286 else 287 std::cout<<std::endl; 264 288 } 265 289 // Print solution if finished  we can't get names from Osi! 266 290 267 291 if (model.getMinimizationObjValue()<1.0e50) { 292 // post process 293 if (preProcess) 294 process.postProcess(*model.solver()); 268 295 int numberColumns = model.solver()>getNumCols(); 269 296
Note: See TracChangeset
for help on using the changeset viewer.