Changeset 180


Ignore:
Timestamp:
Oct 5, 2005 1:36:32 PM (14 years ago)
Author:
forrest
Message:

mods

Location:
trunk/Samples
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Samples/CbcCompareUser.cpp

    r86 r180  
    2525    saveWeight_(0.0),
    2626    numberSolutions_(0),
     27    count_(0),
    2728    treeSize_(0)
    2829{
     
    3637    saveWeight_(0.0),
    3738    numberSolutions_(0),
     39    count_(0),
    3840    treeSize_(0)
    3941{
     
    5052  saveWeight_ = rhs.saveWeight_;
    5153  numberSolutions_=rhs.numberSolutions_;
     54  count_ = rhs.count_;
    5255  treeSize_ = rhs.treeSize_;
    5356}
     
    6972    saveWeight_ = rhs.saveWeight_;
    7073    numberSolutions_=rhs.numberSolutions_;
     74    count_ = rhs.count_;
    7175    treeSize_ = rhs.treeSize_;
    7276  }
     
    8387CbcCompareUser::test (CbcNode * x, CbcNode * y)
    8488{
    85   if (weight_==-1.0) {
    86     // before solution
    87     /* printf("x %d %d %g, y %d %d %g\n",
    88        x->numberUnsatisfied(),x->depth(),x->objectiveValue(),
    89        y->numberUnsatisfied(),y->depth(),y->objectiveValue()); */
    90     if (x->numberUnsatisfied() > y->numberUnsatisfied())
    91       return true;
    92     else if (x->numberUnsatisfied() < y->numberUnsatisfied())
     89  if (x) {
     90    if (y) {
     91      if (weight_==-1.0) {
     92        // before solution
     93        /* printf("x %d %d %g, y %d %d %g\n",
     94           x->numberUnsatisfied(),x->depth(),x->objectiveValue(),
     95           y->numberUnsatisfied(),y->depth(),y->objectiveValue()); */
     96        if (x->numberUnsatisfied() > y->numberUnsatisfied())
     97          return true;
     98        else if (x->numberUnsatisfied() < y->numberUnsatisfied())
     99          return false;
     100        else
     101          return x->depth() < y->depth();
     102      } else {
     103        // after solution
     104        double weight = CoinMax(weight_,0.0);
     105        return x->objectiveValue()+ weight*x->numberUnsatisfied() >
     106          y->objectiveValue() + weight*y->numberUnsatisfied();
     107        //return x->guessedObjectiveValue()>y->guessedObjectiveValue();
     108      }
     109    } else {
    93110      return false;
    94     else
    95       return x->depth() < y->depth();
     111    }
    96112  } else {
    97     // after solution
    98     double weight = CoinMax(weight_,0.0);
    99     return x->objectiveValue()+ weight*x->numberUnsatisfied() >
    100       y->objectiveValue() + weight*y->numberUnsatisfied();
     113    return true;
    101114  }
    102115}
     
    108121                               int numberInfeasibilitiesAtContinuous)
    109122{
    110   if (model->getSolutionCount()==model->getNumberHeuristicSolutions())
    111     return; // solution was got by rounding
    112123  // set to get close to this solution
    113124  double costPerInteger =
    114125    (model->getObjValue()-objectiveAtContinuous)/
    115126    ((double) numberInfeasibilitiesAtContinuous);
    116   weight_ = 0.98*costPerInteger;
     127  weight_ = 0.95*costPerInteger;
    117128  saveWeight_=weight_;
     129  if (model->getSolutionCount()==model->getNumberHeuristicSolutions())
     130    return; // solution was got by rounding
    118131  numberSolutions_++;
    119132  if (numberSolutions_>5)
     
    141154  return numberNodes==11000; // resort if first time
    142155}
     156// Returns true if wants code to do scan with alternate criterion
     157bool
     158CbcCompareUser::fullScan() const
     159{
     160  count_++;
     161  if (weight_)
     162    return (count_%10)==0;
     163  else
     164    return false;
     165}
     166// This is alternate test function
     167bool
     168CbcCompareUser::alternateTest (CbcNode * x, CbcNode * y)
     169{
     170  if (x) {
     171    if (y) {
     172      return x->objectiveValue() >
     173        y->objectiveValue() ;
     174    } else {
     175      return false;
     176    }
     177  } else {
     178    return true;
     179  }
     180}
  • trunk/Samples/CbcCompareUser.hpp

    r31 r180  
    3232     weighted value of node x */
    3333  virtual bool test (CbcNode * x, CbcNode * y) ;
     34  /// This is alternate test function
     35  virtual bool alternateTest (CbcNode * x, CbcNode * y);
    3436  // This allows method to change behavior as it is called
    3537  // after each solution
     
    3739                           double objectiveAtContinuous,
    3840                           int numberInfeasibilitiesAtContinuous) ;
     41  /// Returns true if wants code to do scan with alternate criterion
     42  virtual bool fullScan() const;
    3943  // This allows method to change behavior
    4044  // Return true if want tree re-sorted
     
    5559  // Number of solutions
    5660  int numberSolutions_;
     61  // count
     62  mutable int count_;
    5763  // Tree size (at last check)
    5864  int treeSize_;
Note: See TracChangeset for help on using the changeset viewer.