Ignore:
Timestamp:
Feb 29, 2008 11:06:25 PM (11 years ago)
Author:
jpgoncal
Message:

Cleaned up a little bit.

File:
1 edited

Legend:

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

    r884 r885  
    3333   heuristicName_("Unknown"),
    3434   howOften_(100),
    35    decayFactor_(0.5)
     35   decayFactor_(0.5),
     36   lastRun_(0),
     37   runNodes_(NULL)
    3638{
    3739  // As CbcHeuristic virtual need to modify .cpp if above change
     
    4850  heuristicName_("Unknown"),
    4951  howOften_(100),
    50   decayFactor_(0.5)
     52  decayFactor_(0.5),
     53  lastRun_(0),
     54  runNodes_(NULL)
    5155{}
    5256
     
    6367  howOften_(rhs.howOften_),
    6468  decayFactor_(rhs.howOften_),
     69  lastRun_(rhs.lastRun_),
    6570  runNodes_(rhs.runNodes_)
    6671{}
     
    8085    howOften_ = rhs.howOften_;
    8186    decayFactor_ = rhs.howOften_;
     87    lastRun_ = rhs.lastRun_;
    8288    runNodes_ = rhs.runNodes_;
    8389  }
     
    497503CbcHeuristicNode::CbcHeuristicNode(CbcModel& model)
    498504{
    499   CbcNode* node = model->currentNode();
     505  CbcNode* node = model.currentNode();
    500506  int depth = node->depth();
    501507  numObjects_ = depth; //??
    502   brObj_ = new int[numObjects_];
     508  brObj_ = new OsiBranchingObject*[numObjects_];
    503509  CbcNodeInfo* nodeInfo = node->nodeInfo();
    504   int depth = 0;
     510  depth = 0;
    505511  while (nodeInfo) {
    506     brObj_[depth++] = nodeInfo->branchingObject()->clone();
     512    brObj_[depth++] = node->branchingObject()->clone();
    507513    nodeInfo = nodeInfo->parent();
    508514  }
    509515  std::sort(brObj_, brObj_+depth, compareBranchingObjects);
    510   cnt = 0;
     516  int cnt = 0;
    511517  OsiBranchingObject* br;
    512518  for (int i = 1; i < depth; ++i) {
     
    548554  int i = 0;
    549555  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_) {
    552558    const OsiBranchingObject* br0 = brObj_[i];
    553     const OsiBranchingObject* br1 = node.brObj_[j];
     559    const OsiBranchingObject* br1 = node->brObj_[j];
    554560    const int brComp = compare3BranchingObjects(br0, br1);
    555     switch (brcomp) {
     561    switch (brComp) {
    556562    case -1:
    557563      distance += subsetWeight;
     
    581587    }
    582588  }
    583   distance += subsetWeight * (numObjects_ - i + node.numObjects_ - j);
     589  distance += subsetWeight * (numObjects_ - i + node->numObjects_ - j);
    584590  return distance;
    585591}
     
    592598    delete brObj_[i];
    593599  }
     600  delete [] brObj_;
     601}
     602
     603//=======================================================================================
     604
     605CbcHeuristicNodeList::CbcHeuristicNodeList(const CbcHeuristicNodeList& rhs)
     606{
     607  nodes_ = rhs.nodes_;
     608}
     609
     610//=======================================================================================
     611
     612CbcHeuristicNodeList&
     613CbcHeuristicNodeList::operator=(const CbcHeuristicNodeList& rhs)
     614{
     615  if (this != &rhs)
     616    nodes_ = rhs.nodes_;
     617
     618  return *this;
    594619}
    595620
     
    599624CbcHeuristicNodeList::farFrom(const CbcHeuristicNode* node)
    600625{
     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  }
    601633 
    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;
    620638}
    621639
Note: See TracChangeset for help on using the changeset viewer.