Changeset 758
- Timestamp:
- Aug 16, 2007 6:34:37 AM (14 years ago)
- Location:
- trunk/Cbc/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cbc/src/CbcHeuristicFPump.cpp
r753 r758 34 34 maximumRetries_(1), 35 35 accumulate_(0), 36 fixOnReducedCosts_(1), 36 37 roundExpensive_(false) 37 38 { … … 54 55 maximumRetries_(1), 55 56 accumulate_(0), 57 fixOnReducedCosts_(1), 56 58 roundExpensive_(roundExpensive) 57 59 { … … 90 92 else 91 93 fprintf(fp,"4 heuristicFPump.setAccumulate(%d);\n",accumulate_); 94 if (fixOnReducedCosts_!=other.fixOnReducedCosts_) 95 fprintf(fp,"3 heuristicFPump.setFixOnReducedCosts(%d);\n",fixOnReducedCosts_); 96 else 97 fprintf(fp,"4 heuristicFPump.setFixOnReducedCosts(%d);\n",fixOnReducedCosts_); 92 98 if (maximumTime_!=other.maximumTime_) 93 99 fprintf(fp,"3 heuristicFPump.setMaximumTime(%g);\n",maximumTime_); … … 136 142 maximumRetries_(rhs.maximumRetries_), 137 143 accumulate_(rhs.accumulate_), 144 fixOnReducedCosts_(rhs.fixOnReducedCosts_), 138 145 roundExpensive_(rhs.roundExpensive_) 139 146 { … … 157 164 maximumRetries_ = rhs.maximumRetries_; 158 165 accumulate_ = rhs.accumulate_; 166 fixOnReducedCosts_ = rhs.fixOnReducedCosts_; 159 167 roundExpensive_ = rhs.roundExpensive_; 160 168 } … … 264 272 if (gap>0.0) { 265 273 gap += 100.0*tolerance; 266 model_->solver()->reducedCostFix(gap); 274 int nFix=model_->solver()->reducedCostFix(gap); 275 printf("dj fixing fixed %d variables\n",nFix); 267 276 } 268 277 } … … 308 317 double tolerance; 309 318 solver->getDblParam(OsiDualTolerance,tolerance) ; 310 if (gap>0.0 ) {319 if (gap>0.0&&(fixOnReducedCosts_==1||(numberTries==1&&fixOnReducedCosts_==2))) { 311 320 gap += 100.0*tolerance; 312 solver->reducedCostFix(gap); 321 int nFix=solver->reducedCostFix(gap); 322 if (nFix) { 323 sprintf(pumpPrint,"Reduced cost fixing fixed %d variables on pass %d",nFix,numberTries); 324 model_->messageHandler()->message(CBC_FPUMP1,model_->messages()) 325 << pumpPrint 326 <<CoinMessageEol; 327 pumpPrint[0]='\0'; 328 } 313 329 } 314 330 } -
trunk/Cbc/src/CbcHeuristicFPump.hpp
r706 r758 120 120 inline int accumulate() const 121 121 { return accumulate_;} 122 /** Set whether to fix variables on known solution 123 0 - do not fix 124 1 - fix integers on reduced costs 125 2 - fix integers on reduced costs but only on entry 126 */ 127 inline void setFixOnReducedCosts(int value) 128 { fixOnReducedCosts_=value;} 129 /// Get reduced cost option 130 inline int fixOnReducedCosts() const 131 { return fixOnReducedCosts_;} 122 132 123 133 protected: … … 155 165 */ 156 166 int accumulate_; 167 /** Set whether to fix variables on known solution 168 0 - do not fix 169 1 - fix integers on reduced costs 170 2 - fix integers on reduced costs but only on entry 171 */ 172 int fixOnReducedCosts_; 157 173 /// If true round to expensive 158 174 bool roundExpensive_; -
trunk/Cbc/src/CbcModel.cpp
r751 r758 9872 9872 memcpy(bestSolution_,solution,numberColumns*sizeof(double)); 9873 9873 } 9874 // Do heuristics at root 9874 /* Do heuristics at root. 9875 0 - don't delete 9876 1 - delete 9877 2 - just delete - don't even use 9878 */ 9875 9879 void 9876 CbcModel::doHeuristicsAtRoot( booldeleteHeuristicsAfterwards)9880 CbcModel::doHeuristicsAtRoot(int deleteHeuristicsAfterwards) 9877 9881 { 9882 9878 9883 int numberColumns = getNumCols() ; 9879 if (deleteHeuristicsAfterwards) {9880 assert (!usedInSolution_);9881 usedInSolution_ = new int [numberColumns];9882 CoinZeroN(usedInSolution_,numberColumns);9883 }9884 9884 double * newSolution = new double [numberColumns] ; 9885 double heuristicValue = getCutoff() ;9886 int found = -1; // no solution found9887 CbcEventHandler *eventHandler = getEventHandler() ;9888 if (eventHandler)9889 eventHandler->setModel(this);9890 9891 currentPassNumber_ = 1; // so root heuristics will run9892 9885 int i; 9893 for (i = 0;i<numberHeuristics_;i++) { 9894 // see if heuristic will do anything 9895 double saveValue = heuristicValue ; 9896 int ifSol = heuristic_[i]->solution(heuristicValue, 9897 newSolution); 9898 if (ifSol>0) { 9899 // better solution found 9900 found = i ; 9901 incrementUsed(newSolution); 9902 // increment number of solutions so other heuristics can test 9903 numberSolutions_++; 9904 numberHeuristicSolutions_++; 9905 } else { 9906 heuristicValue = saveValue ; 9907 } 9908 } 9909 currentPassNumber_ = 0; 9910 /* 9911 Did any of the heuristics turn up a new solution? Record it before we free 9912 the vector. 9913 */ 9914 if (found >= 0) { 9915 // For compiler error on terra cluster! 9916 if (found<numberHeuristics_) 9917 lastHeuristic_ = heuristic_[found]; 9918 else 9919 lastHeuristic_ = heuristic_[0]; 9920 setBestSolution(CBC_ROUNDING,heuristicValue,newSolution) ; 9921 CbcTreeLocal * tree 9922 = dynamic_cast<CbcTreeLocal *> (tree_); 9923 if (tree) 9924 tree->passInSolution(bestSolution_,heuristicValue); 9925 if (eventHandler) { 9926 if (!eventHandler->event(CbcEventHandler::solution)) { 9927 eventHappened_=true; // exit 9886 if (deleteHeuristicsAfterwards!=2) { 9887 if (deleteHeuristicsAfterwards) { 9888 assert (!usedInSolution_); 9889 usedInSolution_ = new int [numberColumns]; 9890 CoinZeroN(usedInSolution_,numberColumns); 9891 } 9892 double heuristicValue = getCutoff() ; 9893 int found = -1; // no solution found 9894 CbcEventHandler *eventHandler = getEventHandler() ; 9895 if (eventHandler) 9896 eventHandler->setModel(this); 9897 9898 currentPassNumber_ = 1; // so root heuristics will run 9899 for (i = 0;i<numberHeuristics_;i++) { 9900 // see if heuristic will do anything 9901 double saveValue = heuristicValue ; 9902 int ifSol = heuristic_[i]->solution(heuristicValue, 9903 newSolution); 9904 if (ifSol>0) { 9905 // better solution found 9906 found = i ; 9907 incrementUsed(newSolution); 9908 // increment number of solutions so other heuristics can test 9909 numberSolutions_++; 9910 numberHeuristicSolutions_++; 9911 } else { 9912 heuristicValue = saveValue ; 9913 } 9914 } 9915 currentPassNumber_ = 0; 9916 /* 9917 Did any of the heuristics turn up a new solution? Record it before we free 9918 the vector. 9919 */ 9920 if (found >= 0) { 9921 // For compiler error on terra cluster! 9922 if (found<numberHeuristics_) 9923 lastHeuristic_ = heuristic_[found]; 9924 else 9925 lastHeuristic_ = heuristic_[0]; 9926 setBestSolution(CBC_ROUNDING,heuristicValue,newSolution) ; 9927 CbcTreeLocal * tree 9928 = dynamic_cast<CbcTreeLocal *> (tree_); 9929 if (tree) 9930 tree->passInSolution(bestSolution_,heuristicValue); 9931 if (eventHandler) { 9932 if (!eventHandler->event(CbcEventHandler::solution)) { 9933 eventHappened_=true; // exit 9934 } 9928 9935 } 9929 9936 } -
trunk/Cbc/src/CbcModel.hpp
r750 r758 1634 1634 /// Fill in useful estimates 1635 1635 void pseudoShadow(double * down, double * up); 1636 /// Do heuristics at root 1637 void doHeuristicsAtRoot(bool deleteHeuristicsAfterwards=false); 1636 /** Do heuristics at root. 1637 0 - don't delete 1638 1 - delete 1639 2 - just delete - don't even use 1640 */ 1641 void doHeuristicsAtRoot(int deleteHeuristicsAfterwards=0); 1638 1642 /// Get the hotstart solution 1639 1643 inline const double * hotstartSolution() const -
trunk/Cbc/src/CbcSolver.cpp
r755 r758 1526 1526 } 1527 1527 heuristic4.setHeuristicName("feasibility pump"); 1528 //#define ROLF 1529 #ifdef ROLF 1530 CbcHeuristicFPump pump(*model); 1531 pump.setMaximumTime(60); 1532 pump.setMaximumPasses(100); 1533 pump.setMaximumRetries(1); 1534 pump.setFixOnReducedCosts(0); 1535 pump.setHeuristicName("Feasibility pump"); 1536 pump.setFractionSmall(1.0); 1537 pump.setWhen(13); 1538 model->addHeuristic(&pump); 1539 #else 1528 1540 model->addHeuristic(&heuristic4); 1541 #endif 1529 1542 } 1530 1543 if (useRounding>=type) { … … 1563 1576 // clean copy 1564 1577 CbcModel model2(*model); 1578 // But get rid of heuristics in model 1579 model->doHeuristicsAtRoot(2); 1565 1580 if (logLevel<=1) 1566 1581 model2.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry); … … 1573 1588 bool cleanModel = !model2.numberIntegers()&&!model2.numberObjects(); 1574 1589 model2.findIntegers(false); 1575 model2.doHeuristicsAtRoot( true);1590 model2.doHeuristicsAtRoot(1); 1576 1591 if (cleanModel) 1577 1592 model2.zapIntegerInformation(false); … … 3630 3645 if (!solver2) 3631 3646 break; 3647 if (model.bestSolution()) { 3648 // need to redo - in case no better found in BAB 3649 // just get integer part right 3650 const int * originalColumns = process.originalColumns(); 3651 int numberColumns = solver2->getNumCols(); 3652 double * bestSolution = babModel->bestSolution(); 3653 const double * oldBestSolution = model.bestSolution(); 3654 for (int i=0;i<numberColumns;i++) { 3655 int jColumn = originalColumns[i]; 3656 bestSolution[i]=oldBestSolution[jColumn]; 3657 } 3658 } 3632 3659 //solver2->resolve(); 3633 3660 if (preProcess==2) {
Note: See TracChangeset
for help on using the changeset viewer.