Changeset 485


Ignore:
Timestamp:
Nov 8, 2006 2:10:36 PM (14 years ago)
Author:
forrest
Message:

fix compare

Location:
trunk/Cbc/src
Files:
3 edited

Legend:

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

    r356 r485  
    5959CbcCompareDepth::test (CbcNode * x, CbcNode * y)
    6060{
    61   return x->depth() < y->depth();
     61  int testX = x->depth();
     62  int testY = y->depth();
     63  if (testX!=testY)
     64    return testX < testY;
     65  else
     66    return equalityTest(x,y); // so ties will be broken in consistent manner
    6267}
    6368// Create C++ lines to get to current state
     
    112117CbcCompareObjective::test (CbcNode * x, CbcNode * y)
    113118{
    114   return x->objectiveValue() > y->objectiveValue();
     119  double testX = x->objectiveValue();
     120  double testY = y->objectiveValue();
     121  if (testX!=testY)
     122    return testX > testY;
     123  else
     124    return equalityTest(x,y); // so ties will be broken in consistent manner
    115125}
    116126// Create C++ lines to get to current state
     
    209219  }
    210220#else
    211   if (weight_==-1.0&&(y->depth()>7||x->depth()>7)) {
     221  if ((weight_==-1.0&&(y->depth()>7||x->depth()>7))||weight_==-3.0) {
     222    int adjust =  (weight_==-3.0) ? 10000 : 0;
    212223    // before solution
    213     /* printf("x %d %d %g, y %d %d %g\n",
     224    /*printf("x %d %d %g, y %d %d %g\n",
    214225       x->numberUnsatisfied(),x->depth(),x->objectiveValue(),
    215226       y->numberUnsatisfied(),y->depth(),y->objectiveValue()); */
    216     if (x->numberUnsatisfied() > y->numberUnsatisfied())
     227    if (x->numberUnsatisfied() > y->numberUnsatisfied()+adjust) {
    217228      return true;
    218     else if (x->numberUnsatisfied() < y->numberUnsatisfied())
     229    } else if (x->numberUnsatisfied() < y->numberUnsatisfied()-adjust) {
    219230      return false;
    220     else
    221       return x->depth() < y->depth();
     231    } else {
     232      int depthX = x->depth();
     233      int depthY = y->depth();
     234      if (depthX!=depthY)
     235        return depthX < depthY;
     236      else
     237        return equalityTest(x,y); // so ties will be broken in consistent manner
     238    }
    222239  } else {
     240    // always choose *smallest* depth if <= 7
     241    int depthX = x->depth();
     242    int depthY = y->depth();
     243    if (depthX<=7||depthY<=7) {
     244      if (depthX!=depthY) {
     245        return depthX < depthY;
     246      }
     247    }
    223248    // after solution
    224249    double weight = CoinMax(weight_,0.0);
    225     return x->objectiveValue()+ weight*x->numberUnsatisfied() >
    226       y->objectiveValue() + weight*y->numberUnsatisfied();
     250    double testX =  x->objectiveValue()+ weight*x->numberUnsatisfied();
     251    double testY = y->objectiveValue() + weight*y->numberUnsatisfied();
     252    if (testX!=testY)
     253      return testX > testY;
     254    else
     255      return equalityTest(x,y); // so ties will be broken in consistent manner
    227256  }
    228257#endif
     
    344373CbcCompareEstimate::test (CbcNode * x, CbcNode * y)
    345374{
    346   return x->guessedObjectiveValue() >  y->guessedObjectiveValue() ;
     375  double testX = x->guessedObjectiveValue();
     376  double testY = y->guessedObjectiveValue();
     377  if (testX!=testY)
     378    return testX > testY;
     379  else
     380    return equalityTest(x,y); // so ties will be broken in consistent manner
    347381}
    348382
     
    355389  fprintf(fp,"3  cbcModel->setNodeComparison(compare);\n");
    356390}
    357 
  • trunk/Cbc/src/CbcCompareActual.hpp

    r356 r485  
    9494  virtual bool every1000Nodes(CbcModel * model,int numberNodes);
    9595
    96   /* if weight == -1.0 then depth first (before solution)
     96  /* if weight == -1.0 then fewest infeasibilities (before solution)
    9797     if -2.0 then do breadth first just for first 1000 nodes
     98     if -3.0 then depth first before solution
    9899  */
    99100  inline double getWeight() const
  • trunk/Cbc/src/CbcCompareBase.hpp

    r356 r485  
    4141  virtual bool every1000Nodes(CbcModel * model,int numberNodes) {return false;};
    4242
    43   /// Returns true if wants code to do scan with alternate criterion
     43  /** Returns true if wants code to do scan with alternate criterion
     44      NOTE - this is temporarily disabled
     45  */
    4446  virtual bool fullScan() const { return false;};
    4547
     
    7072    return test(x,y);
    7173  }
     74  /// Further test if everything else equal
     75  inline bool equalityTest (CbcNode * x, CbcNode * y) const
     76  {
     77    assert (x);
     78    CbcNodeInfo * infoX = x->nodeInfo();
     79    assert (infoX);
     80    int nodeNumberX = infoX->nodeNumber();
     81    assert (y);
     82    CbcNodeInfo * infoY = y->nodeInfo();
     83    assert (infoY);
     84    int nodeNumberY = infoY->nodeNumber();
     85    assert (nodeNumberX!=nodeNumberY);
     86    return (nodeNumberX>nodeNumberY);
     87  };
    7288protected:
    7389  CbcCompareBase * test_;
Note: See TracChangeset for help on using the changeset viewer.