Changeset 885 for branches/heur
 Timestamp:
 Feb 29, 2008 11:06:25 PM (12 years ago)
 Location:
 branches/heur/Cbc/src
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

branches/heur/Cbc/src/CbcHeuristic.cpp
r884 r885 33 33 heuristicName_("Unknown"), 34 34 howOften_(100), 35 decayFactor_(0.5) 35 decayFactor_(0.5), 36 lastRun_(0), 37 runNodes_(NULL) 36 38 { 37 39 // As CbcHeuristic virtual need to modify .cpp if above change … … 48 50 heuristicName_("Unknown"), 49 51 howOften_(100), 50 decayFactor_(0.5) 52 decayFactor_(0.5), 53 lastRun_(0), 54 runNodes_(NULL) 51 55 {} 52 56 … … 63 67 howOften_(rhs.howOften_), 64 68 decayFactor_(rhs.howOften_), 69 lastRun_(rhs.lastRun_), 65 70 runNodes_(rhs.runNodes_) 66 71 {} … … 80 85 howOften_ = rhs.howOften_; 81 86 decayFactor_ = rhs.howOften_; 87 lastRun_ = rhs.lastRun_; 82 88 runNodes_ = rhs.runNodes_; 83 89 } … … 497 503 CbcHeuristicNode::CbcHeuristicNode(CbcModel& model) 498 504 { 499 CbcNode* node = model >currentNode();505 CbcNode* node = model.currentNode(); 500 506 int depth = node>depth(); 501 507 numObjects_ = depth; //?? 502 brObj_ = new int[numObjects_];508 brObj_ = new OsiBranchingObject*[numObjects_]; 503 509 CbcNodeInfo* nodeInfo = node>nodeInfo(); 504 intdepth = 0;510 depth = 0; 505 511 while (nodeInfo) { 506 brObj_[depth++] = node Info>branchingObject()>clone();512 brObj_[depth++] = node>branchingObject()>clone(); 507 513 nodeInfo = nodeInfo>parent(); 508 514 } 509 515 std::sort(brObj_, brObj_+depth, compareBranchingObjects); 510 cnt = 0;516 int cnt = 0; 511 517 OsiBranchingObject* br; 512 518 for (int i = 1; i < depth; ++i) { … … 548 554 int i = 0; 549 555 int j = 0; 550 double dist = 0.0;551 while( i < numObjects_ && j < node .numObjects_) {556 double distance = 0.0; 557 while( i < numObjects_ && j < node>numObjects_) { 552 558 const OsiBranchingObject* br0 = brObj_[i]; 553 const OsiBranchingObject* br1 = node .brObj_[j];559 const OsiBranchingObject* br1 = node>brObj_[j]; 554 560 const int brComp = compare3BranchingObjects(br0, br1); 555 switch (br comp) {561 switch (brComp) { 556 562 case 1: 557 563 distance += subsetWeight; … … 581 587 } 582 588 } 583 distance += subsetWeight * (numObjects_  i + node .numObjects_  j);589 distance += subsetWeight * (numObjects_  i + node>numObjects_  j); 584 590 return distance; 585 591 } … … 592 598 delete brObj_[i]; 593 599 } 600 delete [] brObj_; 601 } 602 603 //======================================================================================= 604 605 CbcHeuristicNodeList::CbcHeuristicNodeList(const CbcHeuristicNodeList& rhs) 606 { 607 nodes_ = rhs.nodes_; 608 } 609 610 //======================================================================================= 611 612 CbcHeuristicNodeList& 613 CbcHeuristicNodeList::operator=(const CbcHeuristicNodeList& rhs) 614 { 615 if (this != &rhs) 616 nodes_ = rhs.nodes_; 617 618 return *this; 594 619 } 595 620 … … 599 624 CbcHeuristicNodeList::farFrom(const CbcHeuristicNode* node) 600 625 { 626 const double minDistance = 10.0; 627 628 double distance = 0.0; 629 for (int i = 0; i < (int) nodes_.size(); i++) { 630 if(nodes_[i] != NULL) 631 distance += nodes_[i]>distance(node); 632 } 601 633 602 603 // Get Hamming distance to last node where a solution was found 604 double 605 CbcHeuristic::getHammingDistance(const OsiSolverInterface* solver) const 606 { 607 double hammingDistance = 0.0; 608 int numberIntegers = model_>numberIntegers(); 609 const double * lower = solver>getColLower(); 610 const double * upper = solver>getColUpper(); 611 const int * integerVariable = model_>integerVariable(); 612 for (int i=0; i<numberIntegers; i++) { 613 int iColumn = integerVariable[i]; 614 if(lowerBoundLastNode_[i] != lower[iColumn]  615 upperBoundLastNode_[i] != upper[iColumn]) 616 hammingDistance += 1.0; 617 } 618 return hammingDistance; 619 } 634 if(distance > minDistance) 635 return true; 636 637 return false; 620 638 } 621 639 
branches/heur/Cbc/src/CbcHeuristic.hpp
r884 r885 9 9 #include "OsiCuts.hpp" 10 10 #include "CoinHelperFunctions.hpp" 11 #include "OsiBranchingObject.hpp" 11 12 12 13 class OsiSolverInterface; … … 20 21 21 22 class CbcHeuristicNode { 22 private: :23 private: 23 24 /// The number of branching decisions made 24 25 int numObjects_; … … 28 29 OsiBranchingObject** brObj_; 29 30 public: 31 CbcHeuristicNode() {} 32 CbcHeuristicNode(CbcModel& model); 33 ~CbcHeuristicNode(); 34 35 double distance(const CbcHeuristicNode* node) const; 36 #if 0 30 37 inline swap(CbcHeuristicNode& node) { 31 38 ::swap(numObjects_, node.numObjects_); 32 39 ::swap(objects_, node.objects_); 33 ::swap(bounds_, node.bounds_);34 40 } 41 #endif 35 42 }; 36 43 … … 48 55 } 49 56 50 bool farFrom(const CbcHeuristicNode &node);57 bool farFrom(const CbcHeuristicNode* node); 51 58 void append(CbcHeuristicNode*& node) { 52 59 nodes_.push_back(node); … … 54 61 } 55 62 void append(CbcHeuristicNodeList& nodes) { 56 nodes_.insert(nodes_.end(), nodes. begin(), nodes.end());57 nodes. clear();63 nodes_.insert(nodes_.end(), nodes.nodes_.begin(), nodes.nodes_.end()); 64 nodes.nodes_.clear(); 58 65 } 59 66 }; … … 93 100 */ 94 101 virtual int solution(double & objectiveValue, 95 double * newSolution, 96 CbcHeuristicInfo* info = NULL)=0; 102 double * newSolution)=0; 97 103 98 104 /** returns 0 if no solution, 1 if valid solution, 1 if just … … 105 111 virtual int solution(double & objectiveValue, 106 112 double * newSolution, 107 OsiCuts & cs, 108 CbcHeuristicInfo* info = NULL) {return 0;} 113 OsiCuts & cs) {return 0;} 109 114 110 115 /// Validate model i.e. sets when_ to 0 if necessary (may be NULL) … … 191 196 /// How much to increase how often 192 197 double decayFactor_; 198 /// Last node count where the heuristic was applied 199 int lastRun_; 193 200 /// The description of the nodes where this heuristic has been applied 194 CbcHeuristicNode * runNodes_;201 CbcHeuristicNodeList* runNodes_; 195 202 #if 0 196 203 /// Lower bounds of last node where the heuristic found a solution 
branches/heur/Cbc/src/CbcHeuristicDiveCoefficient.cpp
r884 r885 156 156 157 157 // Get where we are and create the appropriate CbcHeuristicNode object 158 nodeDesc = new CbcHeuristicNode( model_);159 if (! nodes_.farFrom(nodeDesc)) {158 nodeDesc = new CbcHeuristicNode(*model_); 159 if (!runNodes_>farFrom(nodeDesc)) { 160 160 delete nodeDesc; 161 161 return NULL; 162 162 } 163 163 } 164 165 if(nodeDesc != NULL) 166 runNodes_>append(nodeDesc); 167 168 lastRun_ = nodeCount; 164 169 165 170 #if 0 … … 444 449 returnCode=1; 445 450 446 setCurrentNode(model_>solver());451 // setCurrentNode(model_>solver()); 447 452 } 448 453 }
Note: See TracChangeset
for help on using the changeset viewer.