Changeset 896 for branches/heur


Ignore:
Timestamp:
Mar 11, 2008 5:52:27 PM (11 years ago)
Author:
ladanyi
Message:

added debug info

Location:
branches/heur/Cbc/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/heur/Cbc/src/CbcHeuristic.cpp

    r893 r896  
    9696  fractionSmall_(1.0),
    9797  heuristicName_("Unknown"),
    98   howOften_(2),
     98  howOften_(1),
    9999  decayFactor_(0.5),
    100100  shallowDepth_(0),
    101   howOftenShallow_(100),
     101  howOftenShallow_(1),
    102102  numInvocationsInShallow_(0),
    103103  numInvocationsInDeep_(0),
     
    118118  fractionSmall_(1.0),
    119119  heuristicName_("Unknown"),
    120   howOften_(2),
     120  howOften_(1),
    121121  decayFactor_(0.5),
    122122  shallowDepth_(0),
    123   howOftenShallow_(100),
     123  howOftenShallow_(1),
    124124  numInvocationsInShallow_(0),
    125125  numInvocationsInDeep_(0),
     
    173173  CbcNode* node = model_->currentNode();
    174174  CbcNodeInfo* nodeInfo = node->nodeInfo();
    175   while (nodeInfo->owner() != NULL) {
     175  std::cout << "===============================================================\n";
     176  while (nodeInfo) {
    176177    const CbcNode* node = nodeInfo->owner();
    177     int depth = node->depth();
    178     int nodeNumber = node->nodeNumber();
    179     bool onTree = node->onTree();
    180     bool active = node->active();
    181     std::cout<<"nodeNumber= "<<nodeNumber
    182              <<", depth= "<<depth
    183              <<", onTree= "<<onTree
    184              <<", active= "<<active<<std::endl;
    185     const OsiBranchingObject* osibr =
    186       nodeInfo->owner()->branchingObject();
    187     const CbcBranchingObject* cbcbr =
    188       dynamic_cast<const CbcBranchingObject*>(osibr);
    189     assert(cbcbr);
    190     const CbcIntegerBranchingObject* brPrint =
    191       dynamic_cast<const CbcIntegerBranchingObject*>(cbcbr);
    192     const double* downBounds = brPrint->downBounds();
    193     const double* upBounds = brPrint->upBounds();
    194     int variable = brPrint->variable();
    195     int way = brPrint->way();
    196     std::cout<<"downBounds= ["<<downBounds[0]<<","<<downBounds[1]<<"]"
    197              <<", upBounds= ["<<upBounds[0]<<","<<upBounds[1]<<"]"
    198              <<", variable= "<<variable
    199              <<", way= "<<way<<std::endl;
     178    printf("nodeinfo: node %i\n", nodeInfo->nodeNumber());
     179    {
     180      const CbcIntegerBranchingObject* brPrint =
     181        dynamic_cast<const CbcIntegerBranchingObject*>(nodeInfo->parentBranch());
     182      if (!brPrint) {
     183        printf("    parentBranch: NULL\n");
     184      } else {
     185        const double* downBounds = brPrint->downBounds();
     186        const double* upBounds = brPrint->upBounds();
     187        int variable = brPrint->variable();
     188        int way = brPrint->way();
     189        printf("   parentBranch: var %i downBd [%i,%i] upBd [%i,%i] way %i\n",
     190               variable, (int)downBounds[0], (int)downBounds[1],
     191               (int)upBounds[0], (int)upBounds[1], way);
     192      }
     193    }
     194    if (! node) {
     195      printf("    owner: NULL\n");
     196    } else {
     197      printf("    owner: node %i depth %i onTree %i active %i",
     198             node->nodeNumber(), node->depth(), node->onTree(), node->active());
     199      const OsiBranchingObject* osibr =
     200        nodeInfo->owner()->branchingObject();
     201      const CbcBranchingObject* cbcbr =
     202        dynamic_cast<const CbcBranchingObject*>(osibr);
     203      const CbcIntegerBranchingObject* brPrint =
     204        dynamic_cast<const CbcIntegerBranchingObject*>(cbcbr);
     205      if (!brPrint) {
     206        printf("        ownerBranch: NULL\n");
     207      } else {
     208        const double* downBounds = brPrint->downBounds();
     209        const double* upBounds = brPrint->upBounds();
     210        int variable = brPrint->variable();
     211        int way = brPrint->way();
     212        printf("        ownerbranch: var %i downBd [%i,%i] upBd [%i,%i] way %i\n",
     213               variable, (int)downBounds[0], (int)downBounds[1],
     214               (int)upBounds[0], (int)upBounds[1], way);
     215      }
     216    }
    200217    nodeInfo = nodeInfo->parent();
    201218  }
     
    212229
    213230  debugNodes();
     231  return false;
    214232
    215233  const int depth = currentNode->depth();
     
    676694{
    677695  CbcNode* node = model.currentNode();
    678   int depth = node->depth();
    679   numObjects_ = depth; //??
    680   brObj_ = new CbcBranchingObject*[numObjects_];
     696  brObj_ = new CbcBranchingObject*[node->depth()-1];
    681697  CbcNodeInfo* nodeInfo = node->nodeInfo();
    682   depth = 0;
    683   while (nodeInfo->owner() != NULL) {
    684 #if 0
    685     const OsiBranchingObject* osibr = nodeInfo->parentBranchingObject();
    686 #else
    687     const OsiBranchingObject* osibr =
    688       nodeInfo->owner()->branchingObject();
    689 #endif
    690     const CbcBranchingObject* cbcbr =
    691       dynamic_cast<const CbcBranchingObject*>(osibr);
    692     assert(cbcbr);
    693     const CbcIntegerBranchingObject* brPrint =
    694       dynamic_cast<const CbcIntegerBranchingObject*>(cbcbr);
    695     brObj_[depth++] = cbcbr->clone();
     698  int cnt = 0;
     699  while (nodeInfo->parentBranch() != NULL) {
     700    brObj_[cnt++] = nodeInfo->parentBranch()->clone();
    696701    nodeInfo = nodeInfo->parent();
    697702  }
    698   std::sort(brObj_, brObj_+depth, compareBranchingObjects);
    699   int cnt = 0;
    700   CbcBranchingObject* br;
    701   for (int i = 1; i < depth; ++i) {
    702     if (compare3BranchingObjects(brObj_[cnt], brObj_[i]) == 0) {
    703       int comp = brObj_[cnt]->compareBranchingObject(brObj_[i], &br);
    704       switch (comp) {
    705       case CbcRangeSame: // the same range
    706       case CbcRangeDisjoint: // disjoint decisions
    707         // should not happen! we are on a chain!
    708         abort();
    709       case CbcRangeSubset: // brObj_[cnt] is a subset of brObj_[i]
    710         delete brObj_[i];
    711         break;
    712       case CbcRangeSuperset: // brObj_[i] is a subset of brObj_[cnt]
    713         delete brObj_[cnt];
    714         brObj_[cnt] = brObj_[i];
    715         break;
    716       case CbcRangeOverlap: // overlap
    717         delete brObj_[i];
    718         delete brObj_[cnt];
    719         brObj_[cnt] = br;
    720         break;
    721       }
    722       continue;
    723     } else {
    724       brObj_[++cnt] = brObj_[i];
    725     }
    726   }
    727   numObjects_ = cnt + 1;
     703  std::sort(brObj_, brObj_+cnt, compareBranchingObjects);
     704  if (cnt <= 1) {
     705    numObjects_ = cnt;
     706  } else {
     707    numObjects_ = 0;
     708    CbcBranchingObject* br;
     709    for (int i = 1; i < cnt; ++i) {
     710      if (compare3BranchingObjects(brObj_[numObjects_], brObj_[i]) == 0) {
     711        int comp = brObj_[numObjects_]->compareBranchingObject(brObj_[i], &br);
     712        switch (comp) {
     713        case CbcRangeSame: // the same range
     714        case CbcRangeDisjoint: // disjoint decisions
     715          // should not happen! we are on a chain!
     716          abort();
     717        case CbcRangeSubset: // brObj_[numObjects_] is a subset of brObj_[i]
     718          delete brObj_[i];
     719          break;
     720        case CbcRangeSuperset: // brObj_[i] is a subset of brObj_[numObjects_]
     721          delete brObj_[numObjects_];
     722          brObj_[numObjects_] = brObj_[i];
     723          break;
     724        case CbcRangeOverlap: // overlap
     725          delete brObj_[i];
     726          delete brObj_[numObjects_];
     727          brObj_[numObjects_] = br;
     728          break;
     729      }
     730        continue;
     731      } else {
     732        brObj_[++numObjects_] = brObj_[i];
     733      }
     734    }
     735    ++numObjects_;
     736  }
    728737}
    729738
  • branches/heur/Cbc/src/CbcHeuristic.hpp

    r894 r896  
    3737public:
    3838  CbcHeuristicNode(CbcModel& model);
     39
    3940  CbcHeuristicNode(const CbcHeuristicNode& rhs);
    4041  ~CbcHeuristicNode();
  • branches/heur/Cbc/src/CbcNode.cpp

    r895 r896  
    4646  numberPointingToThis_(0),
    4747  parent_(NULL),
     48  parentBranch_(NULL),
    4849  owner_(NULL),
    4950  numberCuts_(0),
     
    5253  numberRows_(0),
    5354  numberBranchesLeft_(0),
    54   active_(7),
    55   branch_(NULL)
     55  active_(7)
    5656{
    5757#ifdef CHECK_NODE
     
    5959#endif
    6060}
     61
     62void
     63CbcNodeInfo::setParentBasedData()
     64{
     65  if (parent_) {
     66    numberRows_ = parent_->numberRows_+parent_->numberCuts_;
     67    //parent_->increment();
     68    if (parent_->owner()) {
     69      const OsiBranchingObject* br = parent_->owner()->branchingObject();
     70      const CbcBranchingObject* cbcbr = dynamic_cast<const CbcBranchingObject*>(br);
     71      assert(cbcbr);
     72      parentBranch_ = cbcbr->clone();
     73    }
     74  }
     75}
     76
    6177// Constructor given parent
    6278CbcNodeInfo::CbcNodeInfo (CbcNodeInfo * parent)
     
    6480  numberPointingToThis_(2),
    6581  parent_(parent),
     82  parentBranch_(NULL),
    6683  owner_(NULL),
    6784  numberCuts_(0),
     
    7592  printf("CbcNodeInfo %x Constructor from parent %x\n",this,parent_);
    7693#endif
    77   if (parent_) {
    78     numberRows_ = parent_->numberRows_+parent_->numberCuts_;
    79     //parent_->increment();
    80 #if 0
    81     branch_ = parent_->owner()->branchingObject()->clone();
    82 #endif
    83   }
     94  setParentBasedData();
    8495}
    8596// Copy Constructor
     
    8899  numberPointingToThis_(rhs.numberPointingToThis_),
    89100  parent_(rhs.parent_),
     101  parentBranch_(NULL),
    90102  owner_(rhs.owner_),
    91103  numberCuts_(rhs.numberCuts_),
     
    94106  numberRows_(rhs.numberRows_),
    95107  numberBranchesLeft_(rhs.numberBranchesLeft_),
    96   active_(rhs.active_),
    97   branch_(rhs.branch_)
     108  active_(rhs.active_)
    98109{
    99110#ifdef CHECK_NODE
     
    114125    numberCuts_=n;
    115126  }
     127  if (rhs.parentBranch_) {
     128    parentBranch_ = rhs.parentBranch_->clone();
     129  }
    116130}
    117131// Constructor given parent and owner
     
    120134  numberPointingToThis_(2),
    121135  parent_(parent),
     136  parentBranch_(NULL),
    122137  owner_(owner),
    123138  numberCuts_(0),
     
    131146  printf("CbcNodeInfo %x Constructor from parent %x\n",this,parent_);
    132147#endif
    133   if (parent_) {
    134     numberRows_ = parent_->numberRows_+parent_->numberCuts_;
    135 #if 0
    136     branch_ = parent_->owner()->branchingObject()->clone();
    137 #endif
    138   }
     148  setParentBasedData();
    139149}
    140150
  • branches/heur/Cbc/src/CbcNode.hpp

    r895 r896  
    231231
    232232  /// Branching object for the parent
    233   inline const OsiBranchingObject * parentBranchingObject() const
    234   { return branch_;}
     233  inline const CbcBranchingObject * parentBranch() const
     234  { return parentBranch_;}
    235235protected:
    236236
     
    247247  CbcNodeInfo * parent_;
    248248
     249  /// Copy of the branching object of the parent when the node is created
     250  CbcBranchingObject * parentBranch_;
     251     
    249252  /// Owner
    250253  CbcNode * owner_;
     
    277280  int active_;
    278281
    279   /// Copy of the branching object of the parent when the node is created
    280   OsiBranchingObject * branch_;
    281      
    282282private:
    283283 
    284284  /// Illegal Assignment operator
    285285  CbcNodeInfo & operator=(const CbcNodeInfo& rhs);
    286  
     286
     287  /// routine common to constructors
     288  void setParentBasedData();
    287289};
    288290
Note: See TracChangeset for help on using the changeset viewer.