Changeset 435 for branches/devel/Cbc/src/CbcHeuristicFPump.cpp
 Timestamp:
 Sep 25, 2006 2:22:16 PM (14 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/devel/Cbc/src/CbcHeuristicFPump.cpp
r356 r435 120 120 121 121 int numberColumns = model_>getNumCols(); 122 char * usedColumn = NULL; 123 double * lastSolution=NULL; 124 bool fixContinuous=false; 125 bool fixInternal=false; 126 if (when_>=11&&when_<=13) { 127 fixInternal = when_ >11; 128 fixContinuous = when_==13; 129 when_=1; 130 usedColumn = new char [numberColumns]; 131 memset(usedColumn,0,numberColumns); 132 lastSolution = CoinCopyOfArray(solver>getColSolution(),numberColumns); 133 } 122 134 int numberIntegers = model_>numberIntegers(); 123 135 const int * integerVariable = model_>integerVariable(); … … 175 187 // 5. MAIN WHILE LOOP 176 188 int numberPasses=0; 189 double newSolutionValue=COIN_DBL_MAX; 177 190 bool newLineNeeded=false; 178 191 while (!finished) { 179 192 returnCode=0; 193 // see what changed 194 if (usedColumn) { 195 const double * solution = solver>getColSolution(); 196 for (i=0;i<numberColumns;i++) { 197 if (fabs(solution[i]lastSolution[i])>1.0e8) 198 usedColumn[i]=1; 199 lastSolution[i]=solution[i]; 200 } 201 } 180 202 if (numberPasses>=maximumPasses_) { 181 203 break; … … 194 216 // Compute using dot product 195 217 solver>setDblParam(OsiObjOffset,saveOffset); 196 doublenewSolutionValue = direction*solver>OsiSolverInterface::getObjValue();218 newSolutionValue = direction*solver>OsiSolverInterface::getObjValue(); 197 219 if (model_>logLevel()) 198 220 printf("  solution found\n"); … … 294 316 solver>resolve(); 295 317 if (model_>logLevel()) 296 printf("\npass %3d: obj. %10.5 lf > ", numberPasses,solver>getObjValue());318 printf("\npass %3d: obj. %10.5f > ", numberPasses,solver>getObjValue()); 297 319 newLineNeeded=true; 298 320 … … 302 324 printf("  no solution found\n"); 303 325 delete solver; 304 delete [] newSolution;305 326 for ( j=0;j<NUMBER_OLD;j++) 306 327 delete [] oldSolution[j]; 307 328 delete [] oldSolution; 308 329 delete [] saveObjective; 330 if (usedColumn) { 331 OsiSolverInterface * newSolver = model_>continuousSolver()>clone(); 332 const double * colLower = newSolver>getColLower(); 333 const double * colUpper = newSolver>getColUpper(); 334 int i; 335 int nFix=0; 336 int nFixI=0; 337 int nFixC=0; 338 for (i=0;i<numberIntegers;i++) { 339 int iColumn=integerVariable[i]; 340 const CbcObject * object = model_>object(i); 341 const CbcSimpleInteger * integerObject = 342 dynamic_cast<const CbcSimpleInteger *> (object); 343 assert(integerObject); 344 // get original bounds 345 double originalLower = integerObject>originalLowerBound(); 346 assert(colLower[iColumn]==originalLower); 347 newSolver>setColLower(iColumn,CoinMax(colLower[iColumn],originalLower)); 348 double originalUpper = integerObject>originalUpperBound(); 349 assert(colUpper[iColumn]==originalUpper); 350 newSolver>setColUpper(iColumn,CoinMin(colUpper[iColumn],originalUpper)); 351 if (!usedColumn[iColumn]) { 352 double value=lastSolution[iColumn]; 353 double nearest = floor(value+0.5); 354 if (fabs(valuenearest)<1.0e7) { 355 if (nearest==colLower[iColumn]) { 356 newSolver>setColUpper(iColumn,colLower[iColumn]); 357 nFix++; 358 } else if (nearest==colUpper[iColumn]) { 359 newSolver>setColLower(iColumn,colUpper[iColumn]); 360 nFix++; 361 } else if (fixInternal) { 362 newSolver>setColLower(iColumn,nearest); 363 newSolver>setColUpper(iColumn,nearest); 364 nFix++; 365 nFixI++; 366 } 367 } 368 } 369 } 370 if (fixContinuous) { 371 for (int iColumn=0;iColumn<numberColumns;iColumn++) { 372 if (!newSolver>isInteger(iColumn)&&!usedColumn[iColumn]) { 373 double value=lastSolution[iColumn]; 374 if (value<colLower[iColumn]+1.0e8) { 375 newSolver>setColUpper(iColumn,colLower[iColumn]); 376 nFix++; 377 nFixC++; 378 } else if (value>colUpper[iColumn]1.0e8) { 379 newSolver>setColLower(iColumn,colUpper[iColumn]); 380 nFix++; 381 nFixC++; 382 } 383 } 384 } 385 } 386 newSolver>initialSolve(); 387 assert (newSolver>isProvenOptimal()); 388 printf("%d integers at bound fixed, %d internal and %d continuous\n", 389 nFix,nFixI,nFixC); 390 double saveValue = newSolutionValue; 391 returnCode = smallBranchAndBound(newSolver,200,newSolution,newSolutionValue, 392 newSolutionValue,"CbcHeuristicLocalAfterFPump"); 393 if (returnCode) { 394 printf("old sol of %g new of %g\n",saveValue,newSolutionValue); 395 memcpy(betterSolution,newSolution,numberColumns*sizeof(double)); 396 solutionValue=newSolutionValue; 397 } 398 delete newSolver; 399 delete [] usedColumn; 400 delete [] lastSolution; 401 } 402 delete [] newSolution; 309 403 return returnCode; 310 404 }
Note: See TracChangeset
for help on using the changeset viewer.