Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

SbbCompareUser.hpp

00001 // Copyright (C) 2002, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #ifndef SbbCompareUser_H
00004 #define SbbCompareUser_H
00005 
00006 
00007 //#############################################################################
00008 /*  These are alternative strategies for node traversal.  
00009     They can take data etc for fine tuning 
00010 
00011     At present the node list is stored as a heap and the "test"
00012     comparison function returns true if node y is better than node x.
00013 
00014 */
00015 #include "SbbNode.hpp"
00016 #include "SbbCompareBase.hpp"
00017 
00018 /* Before first solution do depth first,
00019    then it is computed to hit first solution less 2%
00020 */
00021 class SbbCompareUser  : public SbbCompareBase {
00022 public:
00023   // Weight for each infeasibility
00024   double weight_;
00025   // Number of solutions
00026   int numberSolutions_;
00027   // Default Constructor 
00028   SbbCompareUser () : weight_(-1.0), numberSolutions_(0) {test_=this;};
00029 
00030   ~SbbCompareUser() {};
00031 
00032   /* 
00033      Return true if y better than x
00034      Node y is better than node x if y has fewer unsatisfied (greater depth on tie) or
00035      after solution weighted value of y is less than weighted value of x
00036   */
00037   virtual bool test (SbbNode * x, SbbNode * y) {
00038     if (weight_<0.0) {
00039       // before solution
00040       /* printf("x %d %d %g, y %d %d %g\n",
00041              x->numberUnsatisfied(),x->depth(),x->objectiveValue(),
00042              y->numberUnsatisfied(),y->depth(),y->objectiveValue()); */
00043       if (x->numberUnsatisfied() > y->numberUnsatisfied())
00044         return true;
00045       else if (x->numberUnsatisfied() < y->numberUnsatisfied())
00046         return false;
00047       else
00048         return x->depth() < y->depth();
00049     } else {
00050       // after solution
00051       return x->objectiveValue()+ weight_*x->numberUnsatisfied() > 
00052         y->objectiveValue() + weight_*y->numberUnsatisfied();
00053     }
00054   }
00055   // This allows method to change behavior as it is called
00056   // after each solution
00057   virtual void newSolution(SbbModel * model,
00058                            double objectiveAtContinuous,
00059                            int numberInfeasibilitiesAtContinuous) 
00060   {
00061     if (model->getSolutionCount()==model->getNumberHeuristicSolutions())
00062       return; // solution was got by rounding
00063     // set to get close to this solution
00064     double costPerInteger = 
00065       (model->getObjValue()-objectiveAtContinuous)/
00066       ((double) numberInfeasibilitiesAtContinuous);
00067     weight_ = 0.98*costPerInteger;
00068     numberSolutions_++;
00069     if (numberSolutions_>5)
00070       weight_ =0.0; // this searches on objective
00071   }
00072   // This allows method to change behavior 
00073   virtual void every1000Nodes(SbbModel * model, int numberNodes)
00074   {
00075     if (numberNodes>10000)
00076       weight_ =0.0; // this searches on objective
00077   }
00078 };
00079 
00080 #endif

Generated on Wed Dec 3 14:36:19 2003 for Sbb by doxygen 1.3.5