Changeset 915 for trunk


Ignore:
Timestamp:
Apr 13, 2008 12:00:26 AM (12 years ago)
Author:
ladanyi
Message:

Fix the branch chain distance calculation so that other codes (bonmin, couenne) do not break.

Location:
trunk/Cbc/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/src/CbcHeuristic.cpp

    r912 r915  
    311311    //#ifdef PRINT_DEBUG
    312312#if 1
     313    const double minDistanceToRun = 1.5 * log((double)depth) / log((double)2);
     314#else
     315    const double minDistanceToRun = minDistanceToRun_;
     316#endif
     317#ifdef PRINT_DEBUG
    313318    double minDistance = nodeDesc->minDistance(runNodes_);
    314     double minDistanceToRun = 1.5 * log((double)depth) / log((double)2);
    315319    std::cout<<"minDistance = "<<minDistance
    316320             <<", minDistanceToRun = "<<minDistanceToRun<<std::endl;
    317     if (minDistance < minDistanceToRun) {
    318 #else
    319     if (nodeDesc->minDistance(runNodes_) < minDistanceToRun_) {
    320321#endif
     322    if (nodeDesc->minDistanceIsSmall(runNodes_, minDistanceToRun)) {
    321323      delete nodeDesc;
    322324      return false;
     
    773775  int cnt = 0;
    774776  while (nodeInfo->parentBranch() != NULL) {
    775     brObj_[cnt++] = nodeInfo->parentBranch()->clone();
     777    const OsiBranchingObject* br = nodeInfo->parentBranch();
     778    const CbcBranchingObject* cbcbr = dynamic_cast<const CbcBranchingObject*>(br);
     779    if (! cbcbr) {
     780      throw CoinError("CbcHeuristicNode can be used only with CbcBranchingObjects.\n",
     781                      "gutsOfConstructor",
     782                      "CbcHeuristicNode",
     783                      __FILE__, __LINE__);
     784    }
     785    brObj_[cnt] = cbcbr->clone();
     786    brObj_[cnt]->previousBranch();
     787    ++cnt;
    776788    nodeInfo = nodeInfo->parent();
    777789  }
     
    916928
    917929double
    918 CbcHeuristicNode::minDistance(const CbcHeuristicNodeList& nodeList)
     930CbcHeuristicNode::minDistance(const CbcHeuristicNodeList& nodeList) const
    919931{
    920932  double minDist = COIN_DBL_MAX;
     
    927939//==============================================================================
    928940
     941bool
     942CbcHeuristicNode::minDistanceIsSmall(const CbcHeuristicNodeList& nodeList,
     943                                     const double threshold) const
     944{
     945  for (int i = nodeList.size() - 1; i >= 0; --i) {
     946    if (distance(nodeList.node(i)) >= threshold) {
     947      continue;
     948    } else {
     949      return true;
     950    }
     951  }
     952  return false;
     953}
     954
     955//==============================================================================
     956
    929957double
    930 CbcHeuristicNode::avgDistance(const CbcHeuristicNodeList& nodeList)
     958CbcHeuristicNode::avgDistance(const CbcHeuristicNodeList& nodeList) const
    931959{
    932960  if (nodeList.size() == 0) {
  • trunk/Cbc/src/CbcHeuristic.hpp

    r912 r915  
    4141  ~CbcHeuristicNode();
    4242  double distance(const CbcHeuristicNode* node) const;
    43   double minDistance(const CbcHeuristicNodeList& nodeList);
    44   double avgDistance(const CbcHeuristicNodeList& nodeList);
     43  double minDistance(const CbcHeuristicNodeList& nodeList) const;
     44  bool minDistanceIsSmall(const CbcHeuristicNodeList& nodeList,
     45                          const double threshold) const;
     46  double avgDistance(const CbcHeuristicNodeList& nodeList) const;
    4547};
    4648
  • trunk/Cbc/src/CbcNode.cpp

    r912 r915  
    6868    if (parent_->owner()) {
    6969      const OsiBranchingObject* br = parent_->owner()->branchingObject();
    70       const CbcBranchingObject* cbcbr = dynamic_cast<const CbcBranchingObject*>(br);
    71       assert(cbcbr);
    72       parentBranch_ = cbcbr->clone();
    73       parentBranch_->previousBranch();
     70      assert(br);
     71      parentBranch_ = br->clone();
    7472    }
    7573  }
  • trunk/Cbc/src/CbcNode.hpp

    r912 r915  
    232232
    233233  /// Branching object for the parent
    234   inline const CbcBranchingObject * parentBranch() const
     234  inline const OsiBranchingObject * parentBranch() const
    235235  { return parentBranch_;}
    236236protected:
     
    249249
    250250  /// Copy of the branching object of the parent when the node is created
    251   CbcBranchingObject * parentBranch_;
     251  OsiBranchingObject * parentBranch_;
    252252     
    253253  /// Owner
Note: See TracChangeset for help on using the changeset viewer.