/home/coin/SVN-release/Cbc-1.2.0/Cbc/src/CbcCompareBase.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2002, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #ifndef CbcCompareBase_H
00004 #define CbcCompareBase_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     This is rather inflexible so if the comparison functions wants
00015     it can signal to use alternative criterion on a complete pass
00016     throgh tree.
00017 
00018 */
00019 #include "CbcNode.hpp"
00020 
00021 class CbcModel;
00022 class CbcTree;
00023 class CbcCompareBase {
00024 public:
00025   // Default Constructor 
00026   CbcCompareBase () {test_=NULL;};
00027 
00028   // This allows any method to change behavior as it is called
00029   // after each solution
00030   virtual void newSolution(CbcModel * model) {};
00031 
00032   // This Also allows any method to change behavior as it is called
00033   // after each solution
00034   virtual void newSolution(CbcModel * model,
00035                            double objectiveAtContinuous,
00036                            int numberInfeasibilitiesAtContinuous) {};
00037 
00038   // This allows any method to change behavior as it is called
00039   // after every 1000 nodes.
00040   // Return true if want tree re-sorted
00041   virtual bool every1000Nodes(CbcModel * model,int numberNodes) {return false;};
00042 
00046   virtual bool fullScan() const { return false;};
00047 
00048   virtual ~CbcCompareBase() {};
00050   virtual void generateCpp( FILE * fp) {};
00051 
00052   // Copy constructor 
00053   CbcCompareBase ( const CbcCompareBase & rhs)
00054   {test_=rhs.test_;};
00055    
00056   // Assignment operator 
00057   CbcCompareBase & operator=( const CbcCompareBase& rhs)
00058   {  if (this!=&rhs) {test_=rhs.test_;}
00059   return *this;
00060   };
00061 
00063   virtual CbcCompareBase * clone() const=0;
00064 
00066   virtual bool test (CbcNode * x, CbcNode * y) {return true;};
00067 
00069   virtual bool alternateTest (CbcNode * x, CbcNode * y) {return test(x,y);};
00070 
00071   bool operator() (CbcNode * x, CbcNode * y) {
00072     return test(x,y);
00073   }
00075   inline bool equalityTest (CbcNode * x, CbcNode * y) const
00076   {
00077     assert (x);
00078     CbcNodeInfo * infoX = x->nodeInfo();
00079     assert (infoX);
00080     int nodeNumberX = infoX->nodeNumber();
00081     assert (y);
00082     CbcNodeInfo * infoY = y->nodeInfo();
00083     assert (infoY);
00084     int nodeNumberY = infoY->nodeNumber();
00085     assert (nodeNumberX!=nodeNumberY);
00086     return (nodeNumberX>nodeNumberY);
00087   };
00088 protected:
00089   CbcCompareBase * test_;
00090 };
00091 class CbcCompare {
00092 public:
00093   CbcCompareBase * test_;
00094   // Default Constructor 
00095   CbcCompare () {test_=NULL;};
00096 
00097   virtual ~CbcCompare() {};
00098 
00099   bool operator() (CbcNode * x, CbcNode * y) {
00100     return test_->test(x,y);
00101   }
00103   inline bool alternateTest (CbcNode * x, CbcNode * y) {return test_->alternateTest(x,y);};
00104 
00106   inline CbcCompareBase * comparisonObject() const
00107   { return test_;};
00108 };
00109 //#############################################################################
00110 /*  These can be alternative strategies for choosing variables
00111     Any descendant can be passed in by setVariableChoice
00112 */
00113 
00114 class CbcChooseVariable {
00115 public:
00116   // Default Constructor 
00117   CbcChooseVariable () {};
00118 
00119   virtual ~CbcChooseVariable() {};
00125   virtual int chosen (const CbcModel * model,int numberToLookAt,
00126                       const int * which, const double * downMovement,
00127                       const double * upMovement, const double * solution,
00128                       int & way, double & value)=0;
00129 
00130 };
00131 #endif

Generated on Thu May 15 22:04:41 2008 by  doxygen 1.4.7