Ignore:
Timestamp:
Nov 28, 2009 6:09:56 AM (10 years ago)
Author:
forrest
Message:

final changes before cleaning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/sandbox/Cbc/src/CbcCompareDefault.cpp

    r1314 r1315  
    2727        numberSolutions_(0),
    2828        treeSize_(0),
    29         breadthDepth_(5)
     29        breadthDepth_(5),
     30        startNodeNumber_(-1),
     31        afterNodeNumber_(-1)
    3032{
    3133    test_ = this;
     
    4143        numberSolutions_(0),
    4244        treeSize_(0),
    43         breadthDepth_(5)
     45        breadthDepth_(5),
     46        startNodeNumber_(-1),
     47        afterNodeNumber_(-1)
    4448{
    4549    test_ = this;
     
    5963    treeSize_ = rhs.treeSize_;
    6064    breadthDepth_ = rhs.breadthDepth_;
     65    startNodeNumber_ = rhs.startNodeNumber_;
     66    afterNodeNumber_ = rhs.afterNodeNumber_;
    6167}
    6268
     
    8187        treeSize_ = rhs.treeSize_;
    8288        breadthDepth_ = rhs.breadthDepth_;
     89        startNodeNumber_ = rhs.startNodeNumber_;
     90        afterNodeNumber_ = rhs.afterNodeNumber_;
    8391    }
    8492    return *this;
     
    94102CbcCompareDefault::test (CbcNode * x, CbcNode * y)
    95103{
    96 #if 0
    97     // always choose *smallest* depth if one or both <= breadthDepth_
    98     int depthX = x->depth();
    99     int depthY = y->depth();
    100     if (depthX <= breadthDepth_ || depthY <= breadthDepth_) {
    101         if (depthX != depthY)
    102             return depthX > depthY;
    103         else
    104             return equalityTest(x, y); // so ties will be broken in consistent manner
    105     }
    106     if (weight_ == -1.0 || weight_ == -3.0) {
    107         int adjust =  (weight_ == -3.0) ? 10000 : 0;
    108         // before solution
    109         /*printf("x %d %d %g, y %d %d %g\n",
    110            x->numberUnsatisfied(),x->depth(),x->objectiveValue(),
    111            y->numberUnsatisfied(),y->depth(),y->objectiveValue()); */
    112         if (x->numberUnsatisfied() > y->numberUnsatisfied() + adjust) {
     104    if (startNodeNumber_ >= 0) {
     105        // Diving
     106        int nX = x->nodeNumber();
     107        int nY = y->nodeNumber();
     108        if (nY == startNodeNumber_)
    113109            return true;
    114         } else if (x->numberUnsatisfied() < y->numberUnsatisfied() - adjust) {
     110        else if (nX == startNodeNumber_)
    115111            return false;
     112        if (nX >= afterNodeNumber_ && nY < afterNodeNumber_)
     113            return false;
     114        else if (nY >= afterNodeNumber_ && nX < afterNodeNumber_)
     115            return true;
     116        // treat as depth first
     117        int depthX = x->depth();
     118        int depthY = y->depth();
     119        if (depthX != depthY) {
     120            return depthX < depthY;
    116121        } else {
    117             int depthX = x->depth();
    118             int depthY = y->depth();
    119             if (depthX != depthY)
    120                 return depthX < depthY;
     122            double weight = CoinMax(weight_, 1.0e-9);
     123            double testX =  x->objectiveValue() + weight * x->numberUnsatisfied();
     124            double testY = y->objectiveValue() + weight * y->numberUnsatisfied();
     125            if (testX != testY)
     126                return testX > testY;
    121127            else
    122128                return equalityTest(x, y); // so ties will be broken in consistent manner
    123129        }
    124     } else {
    125         // after solution
    126         double weight = CoinMax(weight_, 0.0);
    127         double testX =  x->objectiveValue() + weight * x->numberUnsatisfied();
    128         double testY = y->objectiveValue() + weight * y->numberUnsatisfied();
    129         if (testX != testY)
    130             return testX > testY;
    131         else
    132             return equalityTest(x, y); // so ties will be broken in consistent manner
    133     }
    134 #else
     130    }
    135131    //weight_=0.0;
    136132    if ((weight_ == -1.0 && (y->depth() > breadthDepth_ && x->depth() > breadthDepth_)) || weight_ == -3.0 || weight_ == -2.0) {
     
    177173        double testY = y->objectiveValue() + weight * y->numberUnsatisfied();
    178174#elif TRY_THIS==1
    179     /* compute what weight would have to be to hit target
    180        then reverse sign as large weight good */
    181     double target = (1.0 - THRESH2) * bestPossible_ + THRESH2 * cutoff_;
    182     double weight;
    183     weight = (target - x->objectiveValue()) /
    184              static_cast<double>(x->numberUnsatisfied());
    185     double testX = - weight;
    186     weight = (target - y->objectiveValue()) /
    187              static_cast<double>(y->numberUnsatisfied());
    188     double testY = - weight;
     175        /* compute what weight would have to be to hit target
     176           then reverse sign as large weight good */
     177        double target = (1.0 - THRESH2) * bestPossible_ + THRESH2 * cutoff_;
     178        double weight;
     179        weight = (target - x->objectiveValue()) /
     180                 static_cast<double>(x->numberUnsatisfied());
     181        double testX = - weight;
     182        weight = (target - y->objectiveValue()) /
     183                 static_cast<double>(y->numberUnsatisfied());
     184        double testY = - weight;
    189185#elif TRY_THIS==2
    190     // Use estimates
    191     double testX = x->guessedObjectiveValue();
    192     double testY = y->guessedObjectiveValue();
     186        // Use estimates
     187        double testX = x->guessedObjectiveValue();
     188        double testY = y->guessedObjectiveValue();
    193189#elif TRY_THIS==3
    194190#define THRESH 0.95
    195     // Use estimates
    196     double testX = x->guessedObjectiveValue();
    197     double testY = y->guessedObjectiveValue();
    198     if (x->objectiveValue() - bestPossible_ > THRESH*(cutoff_ - bestPossible_))
    199         testX *= 2.0; // make worse
    200     if (y->objectiveValue() - bestPossible_ > THRESH*(cutoff_ - bestPossible_))
    201         testY *= 2.0; // make worse
     191        // Use estimates
     192        double testX = x->guessedObjectiveValue();
     193        double testY = y->guessedObjectiveValue();
     194        if (x->objectiveValue() - bestPossible_ > THRESH*(cutoff_ - bestPossible_))
     195            testX *= 2.0; // make worse
     196        if (y->objectiveValue() - bestPossible_ > THRESH*(cutoff_ - bestPossible_))
     197            testY *= 2.0; // make worse
    202198#endif
    203199        if (testX != testY)
     
    206202            return equalityTest(x, y); // so ties will be broken in consistent manner
    207203    }
    208 #endif
    209204}
    210205// This allows method to change behavior as it is called
     
    270265    return (weight_ != saveWeight);
    271266}
     267// Start dive
     268void
     269CbcCompareDefault::startDive(CbcModel * model)
     270{
     271    // Get best - using ? criterion
     272    double saveWeight = weight_;
     273    weight_ = 0.5 * saveWeight_; //0.0;
     274    // Switch off to get best
     275    startNodeNumber_ = -1;
     276    afterNodeNumber_ = -1;
     277    CbcNode * best = model->tree()->bestAlternate();
     278    startNodeNumber_ = best->nodeNumber();
     279    // send signal to setComparison
     280    afterNodeNumber_ = -2;
     281    // redo tree
     282    model->tree()->setComparison(*this);
     283    afterNodeNumber_ = model->tree()->maximumNodeNumber();
     284    weight_ = saveWeight;
     285}
     286// Clean up dive
     287void
     288CbcCompareDefault::cleanDive()
     289{
     290    if (afterNodeNumber_ != -2) {
     291        // switch off
     292        startNodeNumber_ = -1;
     293        afterNodeNumber_ = -1;
     294    }
     295}
    272296
    273297// Create C++ lines to get to current state
Note: See TracChangeset for help on using the changeset viewer.