- Timestamp:
- Aug 10, 2007 7:52:05 AM (14 years ago)
- Location:
- trunk/Cbc/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cbc/src/CbcHeuristicFPump.cpp
r723 r738 15 15 #include "CbcBranchActual.hpp" 16 16 #include "CoinHelperFunctions.hpp" 17 #include "CoinWarmStartBasis.hpp" 17 18 #include "CoinTime.hpp" 18 19 … … 271 272 int totalNumberPasses=0; 272 273 int numberTries=0; 274 CoinWarmStartBasis bestBasis; 273 275 while (true) { 274 276 int numberPasses=0; … … 412 414 } 413 415 } 414 if (returnCode ) {416 if (returnCode&&newSolutionValue<saveValue) { 415 417 memcpy(betterSolution,newSolution,numberColumns*sizeof(double)); 418 CoinWarmStartBasis * basis = 419 dynamic_cast<CoinWarmStartBasis *>(solver->getWarmStart()) ; 420 if (basis) { 421 bestBasis = * basis; 422 delete basis; 423 } 416 424 if ((accumulate_&1)!=0) 417 425 model_->incrementUsed(betterSolution); // for local search … … 426 434 pumpPrint[0]='\0'; 427 435 } else { 428 sprintf(pumpPrint+strlen(pumpPrint)," - not good enough aftermini branch and bound");436 sprintf(pumpPrint+strlen(pumpPrint)," - not improved by mini branch and bound"); 429 437 model_->messageHandler()->message(CBC_FPUMP1,model_->messages()) 430 438 << pumpPrint … … 555 563 if (newSolutionValue<solutionValue) { 556 564 memcpy(betterSolution,newSolution,numberColumns*sizeof(double)); 565 CoinWarmStartBasis * basis = 566 dynamic_cast<CoinWarmStartBasis *>(solver->getWarmStart()) ; 567 if (basis) { 568 bestBasis = * basis; 569 delete basis; 570 } 557 571 if ((accumulate_&1)!=0) 558 572 model_->incrementUsed(betterSolution); // for local search … … 768 782 returnCode &= ~2; 769 783 } 770 if (returnCode ) {784 if (returnCode&&newSolutionValue<saveValue) { 771 785 sprintf(pumpPrint+strlen(pumpPrint),"Mini branch and bound improved solution from %g to %g (%.2f seconds)", 772 786 saveValue,newSolutionValue,model_->getCurrentSeconds()); … … 810 824 solutionValue=newSolutionValue; 811 825 solutionFound=true; 826 CoinWarmStartBasis * basis = 827 dynamic_cast<CoinWarmStartBasis *>(newSolver->getWarmStart()) ; 828 if (basis) { 829 bestBasis = * basis; 830 delete basis; 831 } 812 832 } else { 813 833 sprintf(pumpPrint+strlen(pumpPrint),"Mini branch and bound did not improve solution (%.2f seconds)", … … 890 910 << pumpPrint 891 911 <<CoinMessageEol; 912 if (bestBasis.getNumStructural()) 913 model_->setBestSolutionBasis(bestBasis); 892 914 return finalReturnCode; 893 915 } -
trunk/Cbc/src/CbcHeuristicLocal.cpp
r708 r738 547 547 // new solution 548 548 memcpy(betterSolution,newSolution,numberColumns*sizeof(double)); 549 CoinWarmStartBasis * basis = 550 dynamic_cast<CoinWarmStartBasis *>(solver->getWarmStart()) ; 551 if (basis) { 552 model_->setBestSolutionBasis(* basis); 553 delete basis; 554 } 549 555 returnCode=1; 550 556 solutionValue = newSolutionValue + bestChange; -
trunk/Cbc/src/CbcModel.cpp
r724 r738 2261 2261 pthread_cond_signal(threadInfo[i].condition2); // unlock 2262 2262 //if (!stopped) 2263 pthread_join(threadId[i],NULL); 2263 //pthread_join(threadId[i],NULL); 2264 int returnCode; 2265 returnCode=pthread_join(threadId[i],NULL); 2266 assert (!returnCode); 2264 2267 //else 2265 2268 //pthread_kill(threadId[i]); // kill rather than try and synchronize … … 3088 3091 { 3089 3092 // resize best solution if exists 3090 if (bestSolution_ ) {3093 if (bestSolution_&&solver&&solver_) { 3091 3094 int nOld = solver_->getNumCols(); 3092 3095 int nNew = solver->getNumCols(); … … 3113 3116 { delete emptyWarmStart_ ; 3114 3117 emptyWarmStart_ = 0 ; } 3118 bestSolutionBasis_ = CoinWarmStartBasis(); 3115 3119 /* 3116 3120 Initialize integer variable vector. … … 3389 3393 addedCuts_ = NULL; 3390 3394 } 3395 bestSolutionBasis_ = rhs.bestSolutionBasis_; 3391 3396 nextRowCut_ = NULL; 3392 3397 currentNode_ = NULL; … … 3650 3655 addedCuts_ = NULL; 3651 3656 } 3657 bestSolutionBasis_ = rhs.bestSolutionBasis_; 3652 3658 nextRowCut_ = NULL; 3653 3659 currentNode_ = NULL; … … 4907 4913 // add to global list 4908 4914 OsiRowCut newCut(*thisCut); 4909 newCut.setGloballyValid( 2);4915 newCut.setGloballyValid(true); 4910 4916 newCut.mutableRow().setTestForDuplicateIndex(false); 4911 4917 globalCuts_.insert(newCut) ; … … 4927 4933 // add to global list 4928 4934 OsiRowCut newCut(*thisCut); 4929 newCut.setGloballyValid( 2);4935 newCut.setGloballyValid(true); 4930 4936 newCut.mutableRow().setTestForDuplicateIndex(false); 4931 4937 globalCuts_.insert(newCut) ; … … 4939 4945 // add to global list 4940 4946 OsiColCut newCut(*thisCut); 4941 newCut.setGloballyValid( 2);4947 newCut.setGloballyValid(true); 4942 4948 globalCuts_.insert(newCut) ; 4943 4949 } … … 5162 5168 // add to global list 5163 5169 OsiRowCut newCut(*thisCut); 5164 newCut.setGloballyValid( 2);5170 newCut.setGloballyValid(true); 5165 5171 newCut.mutableRow().setTestForDuplicateIndex(false); 5166 5172 globalCuts_.insert(newCut) ; … … 5173 5179 // add to global list 5174 5180 OsiColCut newCut(*thisCut); 5175 newCut.setGloballyValid( 2);5181 newCut.setGloballyValid(true); 5176 5182 globalCuts_.insert(newCut) ; 5177 5183 } … … 5347 5353 */ 5348 5354 int numberRowsNow = solver_->getNumRows() ; 5355 #ifndef NDEBUG 5349 5356 assert(numberRowsNow == numberRowsAtStart+lastNumberCuts) ; 5357 #else 5358 // ? maybe clue to threaded problems 5359 if(numberRowsNow != numberRowsAtStart+lastNumberCuts) { 5360 fprintf(stderr,"*** threaded error - numberRowsNow(%d) != numberRowsAtStart(%d)+lastNumberCuts(%d)\n", 5361 numberRowsNow,numberRowsAtStart,lastNumberCuts); 5362 fprintf(stdout,"*** threaded error - numberRowsNow(%d) != numberRowsAtStart(%d)+lastNumberCuts(%d)\n", 5363 numberRowsNow,numberRowsAtStart,lastNumberCuts); 5364 abort(); 5365 } 5366 #endif 5350 5367 int numberToAdd = theseCuts.sizeRowCuts() ; 5351 5368 numberNewCuts_ = lastNumberCuts+numberToAdd ; … … 7327 7344 solver_->setWarmStart(slack); 7328 7345 delete slack ; 7346 } else { 7347 if (bestSolutionBasis_.getNumStructural()==solver_->getNumCols()&& 7348 bestSolutionBasis_.getNumArtificial()==solver_->getNumRows()) 7349 solver_->setWarmStart(&bestSolutionBasis_); 7329 7350 } 7330 7351 // Give a hint to do dual … … 7378 7399 objectiveValue = solver_->getObjValue()*solver_->getObjSense(); 7379 7400 } 7401 bestSolutionBasis_ = CoinWarmStartBasis(); 7380 7402 7381 7403 /* … … 7527 7549 // add to global list 7528 7550 OsiRowCut newCut(*thisCut); 7529 newCut.setGloballyValid( 2);7551 newCut.setGloballyValid(true); 7530 7552 newCut.mutableRow().setTestForDuplicateIndex(false); 7531 7553 globalCuts_.insert(newCut) ; … … 7704 7726 // add to global list 7705 7727 OsiRowCut newCut(*thisCut); 7706 newCut.setGloballyValid( 2);7728 newCut.setGloballyValid(true); 7707 7729 newCut.mutableRow().setTestForDuplicateIndex(false); 7708 7730 globalCuts_.insert(newCut) ; … … 7718 7740 // add to global list 7719 7741 OsiColCut newCut(*thisCut); 7720 newCut.setGloballyValid( 2);7742 newCut.setGloballyValid(true); 7721 7743 globalCuts_.insert(newCut) ; 7722 7744 } … … 9203 9225 int start = rowStart[iRow]; 9204 9226 thisCut.setRow(rowLength[iRow],column+start,elementByRow+start,false); 9205 thisCut.setGloballyValid( 2);9227 thisCut.setGloballyValid(true); 9206 9228 globalCuts_.insert(thisCut) ; 9207 9229 } … … 9226 9248 { 9227 9249 OsiRowCut newCut(cut); 9228 newCut.setGloballyValid( 2);9250 newCut.setGloballyValid(true); 9229 9251 newCut.mutableRow().setTestForDuplicateIndex(false); 9230 9252 globalCuts_.insert(newCut) ; -
trunk/Cbc/src/CbcModel.hpp
r715 r738 1659 1659 /// Generate an OsiBranchingInformation object 1660 1660 OsiBranchingInformation usefulInformation() const; 1661 /** Warm start object produced by heuristic or strong branching 1662 1663 If get a valid integer solution outside branch and bound then it can take 1664 a reasonable time to solve LP which produces clean solution. If this object has 1665 any size then it will be used in solve. 1666 */ 1667 inline void setBestSolutionBasis(const CoinWarmStartBasis & bestSolutionBasis) 1668 { bestSolutionBasis_ = bestSolutionBasis;} 1661 1669 //@} 1662 1670 … … 1734 1742 */ 1735 1743 mutable const double * testSolution_; 1744 /** Warm start object produced by heuristic or strong branching 1745 1746 If get a valid integer solution outside branch and bound then it can take 1747 a reasonable time to solve LP which produces clean solution. If this object has 1748 any size then it will be used in solve. 1749 */ 1750 CoinWarmStartBasis bestSolutionBasis_ ; 1736 1751 /// Global cuts 1737 1752 OsiCuts globalCuts_; … … 2067 2082 int callCbc1(const char * input2, CbcModel & babSolver); 2068 2083 int callCbc1(const std::string input2, CbcModel & babSolver); 2084 // And when CbcMain0 already called to initialize (with call back) (see CbcMain1 for whereFrom) 2085 int callCbc1(const char * input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom)); 2086 int callCbc1(const std::string input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom)); 2087 int CbcMain1 (int argc, const char *argv[],CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom)); 2069 2088 #endif -
trunk/Cbc/src/CbcSolver.cpp
r725 r738 82 82 } 83 83 #endif 84 //#define DMALLOC 84 85 #ifdef DMALLOC 85 86 #include "dmalloc.h" … … 170 171 } 171 172 } 173 //#define CBC_SIG_TRAP 174 #ifdef CBC_SIG_TRAP 175 #include <setjmp.h> 176 static sigjmp_buf cbc_seg_buffer; 177 extern "C" { 178 static void signal_handler_error(int whichSignal) 179 { 180 siglongjmp(cbc_seg_buffer,1); 181 } 182 } 183 #endif 172 184 173 185 int CbcOrClpRead_mode=1; … … 1180 1192 #endif 1181 1193 } 1182 int callCbc1(const char * input2, CbcModel & model )1194 int callCbc1(const char * input2, CbcModel & model, int callBack(CbcModel * currentSolver, int whereFrom)) 1183 1195 { 1184 1196 char * input = strdup(input2); … … 1231 1243 CbcOrClpReadCommand=stdin; 1232 1244 noPrinting=false; 1233 int returnCode = CbcMain1(n+2,const_cast<const char **>(argv),model );1245 int returnCode = CbcMain1(n+2,const_cast<const char **>(argv),model,callBack); 1234 1246 for (int k=0;k<n+2;k++) 1235 1247 free(argv[k]); … … 1284 1296 return returnCode; 1285 1297 } 1286 1298 static int dummyCallBack(CbcModel * model, int whereFrom) 1299 { 1300 return 0; 1301 } 1302 int CbcMain1 (int argc, const char *argv[], 1303 CbcModel & model) 1304 { 1305 return CbcMain1(argc,argv,model,dummyCallBack); 1306 } 1307 int callCbc1(const std::string input2, CbcModel & babSolver, int callBack(CbcModel * currentSolver, int whereFrom)) 1308 { 1309 char * input3 = strdup(input2.c_str()); 1310 int returnCode=callCbc1(input3,babSolver,callBack); 1311 free(input3); 1312 return returnCode; 1313 } 1314 int callCbc1(const char * input2, CbcModel & model) 1315 { 1316 return callCbc1(input2,model,dummyCallBack); 1317 } 1287 1318 int CbcMain (int argc, const char *argv[], 1288 1319 CbcModel & model) … … 1402 1433 parameters[whichParam(COSTSTRATEGY,numberParameters,parameters)].setCurrentOption("off"); 1403 1434 } 1435 /* Meaning of whereFrom: 1436 1 after initial solve by dualsimplex etc 1437 2 after preprocessing 1438 3 just before branchAndBound (so user can override) 1439 4 just after branchAndBound (before postprocessing) 1440 5 after postprocessing 1441 */ 1404 1442 int CbcMain1 (int argc, const char *argv[], 1405 CbcModel & model )1443 CbcModel & model, int callBack(CbcModel * currentSolver, int whereFrom)) 1406 1444 { 1407 1445 /* Note … … 2622 2660 babModel->setProblemStatus(iStatus); 2623 2661 babModel->setSecondaryStatus(iStatus2); 2662 } 2663 int returnCode=callBack(&model,1); 2664 if (returnCode) { 2665 // exit if user wants 2666 delete babModel; 2667 return returnCode; 2624 2668 } 2625 2669 } … … 3038 3082 dynamic_cast<OsiClpSolverInterface *>(solver) ; 3039 3083 ClpSimplex * clpSolver = si->getModelPtr(); 3084 int iStatus = clpSolver->status(); 3085 int iStatus2 = clpSolver->secondaryStatus(); 3086 if (iStatus==0) { 3087 iStatus2=0; 3088 } else if (iStatus==1) { 3089 iStatus=0; 3090 iStatus2=1; // say infeasible 3091 } else if (iStatus==2) { 3092 iStatus=0; 3093 iStatus2=7; // say unbounded 3094 } else if (iStatus==3) { 3095 iStatus=1; 3096 if (iStatus2==9) 3097 iStatus2=4; 3098 else 3099 iStatus2=3; // Use nodes - as closer than solutions 3100 } else if (iStatus==4) { 3101 iStatus=2; // difficulties 3102 iStatus2=0; 3103 } 3104 model.setProblemStatus(iStatus); 3105 model.setSecondaryStatus(iStatus2); 3106 si->setWarmStart(NULL); 3107 int returnCode=callBack(&model,1); 3108 if (returnCode) { 3109 // exit if user wants 3110 delete babModel; 3111 return returnCode; 3112 } 3040 3113 clpSolver->setSpecialOptions(clpSolver->specialOptions()|0x01000000); // say is Cbc (and in branch and bound) 3041 3114 if (!noPrinting) { … … 3353 3426 << generalPrint 3354 3427 <<CoinMessageEol; 3355 break;3356 3428 } else { 3357 3429 //printf("processed model has %d rows, %d columns and %d elements\n", 3358 3430 // solver2->getNumRows(),solver2->getNumCols(),solver2->getNumElements()); 3359 3431 } 3360 } 3432 } 3433 if (!solver2) { 3434 model.setProblemStatus(0); 3435 model.setSecondaryStatus(1); 3436 babModel->setProblemStatus(0); 3437 babModel->setSecondaryStatus(1); 3438 } else { 3439 model.setProblemStatus(-1); 3440 babModel->setProblemStatus(-1); 3441 } 3442 int returnCode=callBack(babModel,2); 3443 if (returnCode) { 3444 // exit if user wants 3445 delete babModel; 3446 return returnCode; 3447 } 3448 if (!solver2) 3449 break; 3361 3450 //solver2->resolve(); 3362 3451 if (preProcess==2) { … … 4691 4780 babModel->setThreadMode(numberThreads/100); 4692 4781 #endif 4782 int returnCode=callBack(babModel,3); 4783 if (returnCode) { 4784 // exit if user wants 4785 delete babModel; 4786 return returnCode; 4787 } 4693 4788 babModel->branchAndBound(statistics); 4789 returnCode=callBack(babModel,4); 4790 if (returnCode) { 4791 // exit if user wants 4792 model.moveInfo(*babModel); 4793 delete babModel; 4794 return returnCode; 4795 } 4694 4796 #ifdef CLP_MALLOC_STATISTICS 4695 4797 malloc_stats(); … … 4850 4952 << generalPrint 4851 4953 <<CoinMessageEol; 4954 } 4955 int returnCode=callBack(babModel,5); 4956 if (returnCode) { 4957 // exit if user wants 4958 model.moveInfo(*babModel); 4959 delete babModel; 4960 return returnCode; 4852 4961 } 4853 4962 #ifdef COIN_HAS_ASL … … 6478 6587 // By now all memory should be freed 6479 6588 #ifdef DMALLOC 6480 dmalloc_log_unfreed();6481 dmalloc_shutdown();6589 //dmalloc_log_unfreed(); 6590 //dmalloc_shutdown(); 6482 6591 #endif 6483 if (babModel) 6592 if (babModel) { 6484 6593 model.moveInfo(*babModel); 6485 delete babModel; 6594 //babModel->setModelOwnsSolver(false); 6595 } 6596 #ifdef CBC_SIG_TRAP 6597 // On Sun sometimes seems to be error - try and get round it 6598 CoinSighandler_t saveSignal=SIG_DFL; 6599 // register signal handler 6600 saveSignal=signal(SIGSEGV,signal_handler_error); 6601 // to force failure!babModel->setNumberObjects(20000); 6602 if (!sigsetjmp(cbc_seg_buffer,1)) { 6603 #endif 6604 delete babModel; 6605 #ifdef CBC_SIG_TRAP 6606 } else { 6607 std::cerr<<"delete babModel failed"<<std::endl; 6608 } 6609 #endif 6486 6610 model.solver()->setWarmStart(NULL); 6487 6611 return 0;
Note: See TracChangeset
for help on using the changeset viewer.