00001
00002
00003 #ifndef SbbCompareUser_H
00004 #define SbbCompareUser_H
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "SbbNode.hpp"
00016 #include "SbbCompareBase.hpp"
00017
00018
00019
00020
00021 class SbbCompareUser : public SbbCompareBase {
00022 public:
00023
00024 double weight_;
00025
00026 int numberSolutions_;
00027
00028 SbbCompareUser () : weight_(-1.0), numberSolutions_(0) {test_=this;};
00029
00030 ~SbbCompareUser() {};
00031
00032
00033
00034
00035
00036
00037 virtual bool test (SbbNode * x, SbbNode * y) {
00038 if (weight_<0.0) {
00039
00040
00041
00042
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
00051 return x->objectiveValue()+ weight_*x->numberUnsatisfied() >
00052 y->objectiveValue() + weight_*y->numberUnsatisfied();
00053 }
00054 }
00055
00056
00057 virtual void newSolution(SbbModel * model,
00058 double objectiveAtContinuous,
00059 int numberInfeasibilitiesAtContinuous)
00060 {
00061 if (model->getSolutionCount()==model->getNumberHeuristicSolutions())
00062 return;
00063
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;
00071 }
00072
00073 virtual void every1000Nodes(SbbModel * model, int numberNodes)
00074 {
00075 if (numberNodes>10000)
00076 weight_ =0.0;
00077 }
00078 };
00079
00080 #endif