Changeset 885 for branches/heur/Cbc/src/CbcHeuristic.cpp
 Timestamp:
 Feb 29, 2008 11:06:25 PM (11 years ago)
 File:

 1 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
Note: See TracChangeset
for help on using the changeset viewer.