Changeset 97
- Timestamp:
- Mar 31, 2005 4:42:42 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CbcBranchActual.cpp
r74 r97 2189 2189 //printf("way %d\n",way); 2190 2190 // create object 2191 //printf("would fix %d down and %d up\n",nDown,nUp); 2191 2192 CbcBranchingObject * branch 2192 2193 = new CbcFixingBranchingObject(model_,way, … … 2270 2271 printf("Down Fix "); 2271 2272 #endif 2273 //printf("Down Fix %d\n",numberDown_); 2272 2274 for (i=0;i<numberDown_;i++) { 2273 2275 int iColumn = downList_[i]; … … 2282 2284 printf("Up Fix "); 2283 2285 #endif 2286 //printf("Up Fix %d\n",numberUp_); 2284 2287 for (i=0;i<numberUp_;i++) { 2285 2288 int iColumn = upList_[i]; -
trunk/CbcCompareActual.cpp
r27 r97 113 113 : CbcCompareBase(), 114 114 weight_(-1.0), 115 saveWeight_(0.0), 115 116 numberSolutions_(0), 116 117 treeSize_(0) … … 123 124 : CbcCompareBase(), 124 125 weight_(weight) , 126 saveWeight_(0.0), 125 127 numberSolutions_(0), 126 128 treeSize_(0) … … 136 138 { 137 139 weight_=rhs.weight_; 140 saveWeight_ = rhs.saveWeight_; 138 141 numberSolutions_=rhs.numberSolutions_; 139 142 treeSize_ = rhs.treeSize_; … … 154 157 CbcCompareBase::operator=(rhs); 155 158 weight_=rhs.weight_; 159 saveWeight_ = rhs.saveWeight_; 156 160 numberSolutions_=rhs.numberSolutions_; 157 161 treeSize_ = rhs.treeSize_; … … 169 173 CbcCompareDefault::test (CbcNode * x, CbcNode * y) 170 174 { 175 #if 0 176 // was 171 177 if (weight_<0.0||treeSize_>100000) { 172 178 // before solution … … 185 191 y->objectiveValue() + weight_*y->numberUnsatisfied(); 186 192 } 193 #else 194 if (weight_==-1.0) { 195 // before solution 196 /* printf("x %d %d %g, y %d %d %g\n", 197 x->numberUnsatisfied(),x->depth(),x->objectiveValue(), 198 y->numberUnsatisfied(),y->depth(),y->objectiveValue()); */ 199 if (x->numberUnsatisfied() > y->numberUnsatisfied()) 200 return true; 201 else if (x->numberUnsatisfied() < y->numberUnsatisfied()) 202 return false; 203 else 204 return x->depth() < y->depth(); 205 } else { 206 // after solution 207 double weight = CoinMax(weight_,0.0); 208 return x->objectiveValue()+ weight*x->numberUnsatisfied() > 209 y->objectiveValue() + weight*y->numberUnsatisfied(); 210 } 211 #endif 187 212 } 188 213 // This allows method to change behavior as it is called … … 208 233 CbcCompareDefault::every1000Nodes(CbcModel * model, int numberNodes) 209 234 { 235 #if 0 236 // was 210 237 if (numberNodes>10000) 211 238 weight_ =0.0; // this searches on objective 212 239 // get size of tree 213 240 treeSize_ = model->tree()->size(); 241 #else 242 if (numberNodes>10000) 243 weight_ =0.0; // this searches on objective 244 else if (numberNodes==1000&&weight_==-2.0) 245 weight_=-1.0; // Go to depth first 246 // get size of tree 247 treeSize_ = model->tree()->size(); 248 if (treeSize_>10000) { 249 // set weight to reduce size most of time 250 if (treeSize_>20000) 251 weight_=-1.0; 252 else if ((numberNodes%4000)!=0) 253 weight_=-1.0; 254 else 255 weight_=saveWeight_; 256 } 257 #endif 214 258 return numberNodes==11000; // resort if first time 215 259 } -
trunk/CbcModel.cpp
r96 r97 19 19 #include "CbcHeuristic.hpp" 20 20 #include "CbcModel.hpp" 21 #include "CbcStrategy.hpp" 21 22 #include "CbcMessage.hpp" 22 23 #include "OsiRowCut.hpp" … … 376 377 377 378 { 379 // Set up strategies 380 if (strategy_) { 381 strategy_->setupCutGenerators(*this); 382 strategy_->setupHeuristics(*this); 383 strategy_->setupPrinting(*this); 384 strategy_->setupOther(*this); 385 } 378 386 # ifdef CBC_DEBUG 379 387 std::string problemName ; … … 489 497 (problems which require further exploration). 490 498 */ 491 CbcCompareObjective compareObjective ; 492 CbcCompareDepth compareDepth ; 493 CbcCompareDefault compareDefault ; 494 if (!nodeCompare_) 495 tree_->setComparison(compareDefault) ; 496 else 497 tree_->setComparison(*nodeCompare_) ; 499 tree_->setComparison(*nodeCompare_) ; 498 500 /* 499 501 Used to record the path from a node to the root of the search tree, so that … … 728 730 // Do from deepest 729 731 tree_->cleanTree(this, getCutoff(),bestPossibleObjective_) ; 730 if (!nodeCompare_) { 731 if (!compareDefault.getWeight()) { 732 // set to get close to this 733 double costPerInteger = 734 (bestObjective_-continuousObjective_)/ 735 ((double) continuousInfeasibilities_) ; 736 compareDefault.setWeight(0.98*costPerInteger) ; 737 /*printf("Setting weight per infeasibility to %g\n", 738 0.98*costPerInteger);*/ 739 } 740 tree_->setComparison(compareDefault) ; 741 //tree_->setComparison(compareObjective) ; 742 } else { 743 nodeCompare_->newSolution(this) ; 744 nodeCompare_->newSolution(this,continuousObjective_, 745 continuousInfeasibilities_) ; 746 tree_->setComparison(*nodeCompare_) ; 747 } 732 nodeCompare_->newSolution(this) ; 733 nodeCompare_->newSolution(this,continuousObjective_, 734 continuousInfeasibilities_) ; 735 tree_->setComparison(*nodeCompare_) ; 748 736 if (tree_->empty()) 749 737 break; // finished … … 756 744 + print a summary line to let the user know we're working 757 745 */ 758 if ((numberNodes_%1000) == 0 &&nodeCompare_) {746 if ((numberNodes_%1000) == 0) { 759 747 bool redoTree=nodeCompare_->every1000Nodes(this, numberNodes_) ; 760 748 // redo tree if wanted … … 1297 1285 dblParam_[CbcMaximumSeconds] = 1.0e100; 1298 1286 dblParam_[CbcStartSeconds] = 0.0; 1299 nodeCompare_= NULL;1287 nodeCompare_=new CbcCompareDefault();; 1300 1288 tree_= new CbcTree(); 1301 1289 branchingMethod_=NULL; 1290 strategy_=NULL; 1291 parentModel_=NULL; 1302 1292 appData_=NULL; 1303 1293 handler_ = new CoinMessageHandler(); … … 1371 1361 dblParam_[CbcStartSeconds] = 0.0; 1372 1362 1373 nodeCompare_= NULL;1363 nodeCompare_=new CbcCompareDefault();; 1374 1364 tree_= new CbcTree(); 1375 1365 branchingMethod_=NULL; 1366 strategy_=NULL; 1367 parentModel_=NULL; 1376 1368 appData_=NULL; 1377 1369 handler_ = new CoinMessageHandler(); … … 1576 1568 originalColumns_=NULL; 1577 1569 } 1578 nodeCompare_=rhs.nodeCompare_ ;1570 nodeCompare_=rhs.nodeCompare_->clone(); 1579 1571 tree_= rhs.tree_->clone(); 1580 1572 branchingMethod_=rhs.branchingMethod_; 1573 if (rhs.strategy_) 1574 strategy_=rhs.strategy_->clone(); 1575 else 1576 strategy_=NULL; 1577 parentModel_=rhs.parentModel_; 1581 1578 appData_=rhs.appData_; 1582 1579 messages_ = rhs.messages_; … … 1786 1783 originalColumns_=NULL; 1787 1784 } 1788 nodeCompare_=rhs.nodeCompare_ ;1785 nodeCompare_=rhs.nodeCompare_->clone(); 1789 1786 delete tree_; 1790 1787 tree_= rhs.tree_->clone(); 1791 1788 branchingMethod_=rhs.branchingMethod_; 1789 delete strategy_; 1790 if (rhs.strategy_) 1791 strategy_=rhs.strategy_->clone(); 1792 else 1793 strategy_=NULL; 1794 parentModel_=rhs.parentModel_; 1792 1795 appData_=rhs.appData_; 1793 1796 … … 1865 1868 delete [] heuristic_; 1866 1869 heuristic_=NULL; 1870 delete nodeCompare_; 1871 nodeCompare_=NULL; 1867 1872 delete [] addedCuts_; 1868 1873 addedCuts_=NULL; … … 1879 1884 delete [] originalColumns_; 1880 1885 originalColumns_=NULL; 1886 delete strategy_; 1881 1887 } 1882 1888 // Are there a numerical difficulties? … … 5323 5329 return CoinMin(bestPossibleObjective_,bestObjective_) * solver_->getObjSense() ; 5324 5330 } 5331 // Make given rows (L or G) into global cuts and remove from lp 5332 void 5333 CbcModel::makeGlobalCuts(int number,const int * which) 5334 { 5335 const double * rowLower = solver_->getRowLower(); 5336 const double * rowUpper = solver_->getRowUpper(); 5337 5338 int numberRows = solver_->getNumRows(); 5339 5340 // Row copy 5341 const double * elementByRow = solver_->getMatrixByRow()->getElements(); 5342 const int * column = solver_->getMatrixByRow()->getIndices(); 5343 const CoinBigIndex * rowStart = solver_->getMatrixByRow()->getVectorStarts(); 5344 const int * rowLength = solver_->getMatrixByRow()->getVectorLengths(); 5345 5346 // Not all rows may be good so we need new array 5347 int * whichDelete = new int[numberRows]; 5348 int nDelete=0; 5349 for (int i=0;i<number;i++) { 5350 int iRow = which[i]; 5351 if (iRow>=0&&iRow<numberRows) { 5352 if (rowLower[iRow]<-1.0e20||rowUpper[iRow]>1.0e20) { 5353 whichDelete[nDelete++]=iRow; 5354 OsiRowCut thisCut; 5355 thisCut.setLb(rowLower[iRow]); 5356 thisCut.setUb(rowUpper[iRow]); 5357 int start = rowStart[iRow]; 5358 thisCut.setRow(rowLength[iRow],column+start,elementByRow+start); 5359 globalCuts_.insert(thisCut) ; 5360 } 5361 } 5362 } 5363 if (nDelete) 5364 solver_->deleteRows(nDelete,whichDelete); 5365 delete [] whichDelete; 5366 } 5367 void 5368 CbcModel::setNodeComparison(CbcCompareBase * compare) 5369 { 5370 delete nodeCompare_; 5371 nodeCompare_ = compare->clone(); 5372 } 5373 void 5374 CbcModel::setNodeComparison(CbcCompareBase & compare) 5375 { 5376 delete nodeCompare_; 5377 nodeCompare_ = compare.clone(); 5378 } 5379 // Set the strategy. Clones 5380 void 5381 CbcModel::setStrategy(CbcStrategy & strategy) 5382 { 5383 delete strategy_; 5384 strategy_ = strategy.clone(); 5385 } -
trunk/include/CbcCompareActual.hpp
r27 r97 88 88 virtual bool every1000Nodes(CbcModel * model,int numberNodes); 89 89 90 /* if weight == -1.0 then depth first (before solution) 91 if -2.0 then do breadth first just for first 1000 nodes 92 */ 90 93 inline double getWeight() const 91 94 { return weight_;}; … … 95 98 // Weight for each infeasibility 96 99 double weight_; 100 // Weight for each infeasibility - computed from solution 101 double saveWeight_; 97 102 // Number of solutions 98 103 int numberSolutions_; -
trunk/include/CbcModel.hpp
r94 r97 24 24 class CbcObject; 25 25 class CbcTree; 26 class CbcStrategy; 26 27 27 28 //############################################################################# … … 221 222 */ 222 223 bool resolve(); 224 /// Make given rows (L or G) into global cuts and remove from lp 225 void makeGlobalCuts(int numberRows,const int * which); 223 226 //@} 224 227 … … 850 853 inline CbcCompareBase * nodeComparison() const 851 854 { return nodeCompare_;}; 852 inline void setNodeComparison(CbcCompareBase * compare) 853 { nodeCompare_ = compare;}; 854 inline void setNodeComparison(CbcCompareBase & compare) 855 { nodeCompare_ = &compare;}; 855 void setNodeComparison(CbcCompareBase * compare); 856 void setNodeComparison(CbcCompareBase & compare); 856 857 //@} 857 858 … … 1009 1010 int whatDepth=-1, int whatDepthInSub=-1); 1010 1011 //@} 1012 /** \name Strategy and sub models 1013 1014 See the CbcStrategy class for additional information. 1015 */ 1016 //@{ 1017 1018 /// Get the current strategy 1019 inline CbcStrategy * strategy() const 1020 { return strategy_;}; 1021 /// Set the strategy. Clones 1022 void setStrategy(CbcStrategy & strategy); 1023 /// Get the current parent model 1024 inline CbcModel * parentModel() const 1025 { return parentModel_;}; 1026 /// Set the parent model 1027 inline void setParentModel(CbcModel & parentModel) 1028 { parentModel_ = &parentModel;}; 1029 //@} 1030 1011 1031 1012 1032 /** \name Heuristics and priorities */ … … 1277 1297 /// Variable selection function 1278 1298 CbcBranchDecision * branchingMethod_; 1299 /// Strategy 1300 CbcStrategy * strategy_; 1301 /// Parent model 1302 CbcModel * parentModel_; 1279 1303 /** Whether to automatically do presolve before branch and bound. 1280 1304 0 - no
Note: See TracChangeset
for help on using the changeset viewer.