Changeset 1010
 Timestamp:
 Jul 17, 2008 10:27:44 AM (12 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

stable/2.1/Cbc/src/CbcHeuristicFPump.cpp
r942 r1010 215 215 int numberIntegers = model_>numberIntegers(); 216 216 const int * integerVariableOrig = model_>integerVariable(); 217 217 #ifdef COIN_DEVELOP 218 double totalNumberIterations=0.0; 219 #endif 218 220 // 1. initially check 01 219 221 int i,j; … … 324 326 int numberPasses=0; 325 327 artificialFactor *= 10.0; 328 int lastMove= (!numberTries) ? 10 : 1000000; 329 double lastSumInfeas=COIN_DBL_MAX; 326 330 numberTries++; 327 331 // Clone solver  otherwise annoys root node computations … … 468 472 } 469 473 if (numberPasses>=maximumPasses_) { 470 break; 474 // If going well then keep going if maximumPasses_ small 475 if (lastMove<numberPasses4lastMove==1000000) 476 break; 477 if (maximumPasses_>20numberPasses>=40) 478 break; 471 479 } 472 480 if (maximumTime_>0.0&&CoinCpuTime()>=startTime_+maximumTime_) break; … … 519 527 } 520 528 if (numberLeft) { 529 sprintf(pumpPrint,"Branch and bound needed to clear up %d general integers",numberLeft); 530 model_>messageHandler()>message(CBC_FPUMP1,model_>messages()) 531 << pumpPrint 532 <<CoinMessageEol; 521 533 returnCode = smallBranchAndBound(solver,numberNodes_,newSolution,newSolutionValue, 522 534 solutionValue,"CbcHeuristicFpump"); … … 548 560 model_>setBestSolution(betterSolution,numberColumns,newSolutionValue); 549 561 int action = handler>event(CbcEventHandler::heuristicSolution); 550 if (saveOldSolution ) {562 if (saveOldSolution&&saveObjectiveValue<model_>getMinimizationObjValue()) 551 563 model_>setBestSolution(saveOldSolution,numberColumns,saveObjectiveValue); 552 delete [] saveOldSolution; 553 } 564 delete [] saveOldSolution; 554 565 if (!actionmodel_>getCurrentSeconds()>model_>getMaximumSeconds()) { 555 566 exitAll=true; // exit … … 578 589 } else { 579 590 sprintf(pumpPrint,"After further testing solution no better than previous of %g",solutionValue); 580 581 591 model_>messageHandler()>message(CBC_FPUMP1,model_>messages()) 582 592 << pumpPrint … … 781 791 model_>setBestSolution(betterSolution,numberColumns,newSolutionValue); 782 792 int action = handler>event(CbcEventHandler::heuristicSolution); 783 if (saveOldSolution ) {793 if (saveOldSolution&&saveObjectiveValue<model_>getMinimizationObjValue()) 784 794 model_>setBestSolution(saveOldSolution,numberColumns,saveObjectiveValue); 785 delete [] saveOldSolution; 786 } 795 delete [] saveOldSolution; 787 796 if (!actionmodel_>getCurrentSeconds()>model_>getMaximumSeconds()) { 788 797 exitAll=true; // exit … … 855 864 } 856 865 newTrueSolutionValue *= direction; 857 OsiSolverInterface * saveSolver = model_>swapSolver(solver);858 CbcRounding heuristic1(*model_);859 heuristic1.setHeuristicName("rounding in feaspump!");860 heuristic1.setWhen(1);861 double testObjectiveValue = CoinMin(solutionValue,roundingObjective);862 int returnCode = heuristic1.solution(testObjectiveValue,roundingSolution,newTrueSolutionValue) ;863 if (returnCode==1) {864 assert(testObjectiveValue < CoinMin(solutionValue,roundingObjective));865 roundingObjective = testObjectiveValue;866 }867 model_>swapSolver(saveSolver);868 866 } 869 867 if (!solver>isProvenOptimal()) { … … 952 950 } 953 951 } 952 if (lastMove!=1000000) { 953 if (newSumInfeas<lastSumInfeas) { 954 lastMove=numberPasses; 955 lastSumInfeas=newSumInfeas; 956 } else if (newSumInfeas>lastSumInfeas+1.0e5) { 957 lastMove=1000000; // going up 958 } 959 } 960 #ifdef COIN_DEVELOP 961 totalNumberIterations += solver>getIterationCount(); 962 #endif 954 963 if (solver>getNumRows()<3000) 955 964 sprintf(pumpPrint,"Pass %3d: suminf. %10.5f obj. %g iterations %d", numberPasses+totalNumberPasses, … … 983 992 sprintf(pumpPrint,"Rounding solution of %g is better than previous of %g !\n", 984 993 roundingObjective,solutionValue); 994 model_>messageHandler()>message(CBC_FPUMP1,model_>messages()) 995 << pumpPrint 996 <<CoinMessageEol; 985 997 solutionValue=roundingObjective; 986 998 memcpy(betterSolution,roundingSolution,numberColumns*sizeof(double)); … … 1075 1087 <<CoinMessageEol; 1076 1088 double saveValue = newSolutionValue; 1077 returnCode = smallBranchAndBound(newSolver,numberNodes_,newSolution,newSolutionValue, 1078 cutoff,"CbcHeuristicLocalAfterFPump"); 1089 if (newSolutionValuemodel_>getCutoffIncrement() 1090 >continuousObjectiveValue1.0e7) { 1091 // Give branch and bound a bit more freedom 1092 double cutoff2=newSolutionValuemodel_>getCutoffIncrement(); 1093 returnCode = smallBranchAndBound(newSolver,numberNodes_,newSolution,newSolutionValue, 1094 cutoff2,"CbcHeuristicLocalAfterFPump"); 1095 } else { 1096 // no need 1097 exitAll=true; 1098 returnCode=0; 1099 } 1079 1100 if (returnCode<0) { 1080 1101 if (returnCode==2) … … 1085 1106 // could add cut 1086 1107 returnCode &= ~2; 1108 } 1109 // recompute solution value 1110 if (returnCode&&true) { 1111 delete newSolver; 1112 newSolver = model_>continuousSolver()>clone(); 1113 newSolutionValue = saveOffset; 1114 double newSumInfeas=0.0; 1115 const double * obj = newSolver>getObjCoefficients(); 1116 for (int i=0 ; i<numberColumns ; i++ ) { 1117 if (newSolver>isInteger(i)) { 1118 double value = newSolution[i]; 1119 double nearest = floor(value+0.5); 1120 newSumInfeas += fabs(valuenearest); 1121 } 1122 newSolutionValue += obj[i]*newSolution[i]; 1123 } 1124 newSolutionValue *= direction; 1087 1125 } 1088 1126 if (returnCode&&newSolutionValue<saveValue) { … … 1141 1179 model_>setBestSolution(betterSolution,numberColumns,newSolutionValue); 1142 1180 int action = handler>event(CbcEventHandler::heuristicSolution); 1143 if (saveOldSolution) { 1181 //printf("cutoff %g\n",model_>getCutoff()); 1182 if (saveOldSolution&&saveObjectiveValue<model_>getMinimizationObjValue()) 1144 1183 model_>setBestSolution(saveOldSolution,numberColumns,saveObjectiveValue); 1145 delete [] saveOldSolution; 1146 } 1184 delete [] saveOldSolution; 1147 1185 if (!actionmodel_>getCurrentSeconds()>model_>getMaximumSeconds()) { 1148 1186 exitAll=true; // exit … … 1161 1199 } 1162 1200 if (solutionFound) finalReturnCode=1; 1163 cutoff = CoinMin(cutoff,solutionValue );1201 cutoff = CoinMin(cutoff,solutionValuemodel_>getCutoffIncrement()); 1164 1202 if (numberTries>=maximumRetries_!solutionFoundexitAllcutoff<continuousObjectiveValue+1.0e7) { 1165 1203 break; … … 1250 1288 model_>setNumberHeuristicSolutions(1); 1251 1289 } 1290 #ifdef COIN_DEVELOP 1291 { 1292 double ncol = model_>solver()>getNumCols(); 1293 double nrow = model_>solver()>getNumRows(); 1294 printf("XXX total iterations %g ratios  %g %g %g\n", 1295 totalNumberIterations, 1296 totalNumberIterations/nrow, 1297 totalNumberIterations/ncol, 1298 totalNumberIterations/(2*nrow+2*ncol)); 1299 } 1300 #endif 1252 1301 return finalReturnCode; 1253 1302 }
Note: See TracChangeset
for help on using the changeset viewer.