/home/coin/SVN-release/Cbc-1.1.1/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 
00044   virtual bool fullScan() const { return false;};
00045 
00046   virtual ~CbcCompareBase() {};
00048   virtual void generateCpp( FILE * fp) {};
00049 
00050   // Copy constructor 
00051   CbcCompareBase ( const CbcCompareBase & rhs)
00052   {test_=rhs.test_;};
00053    
00054   // Assignment operator 
00055   CbcCompareBase & operator=( const CbcCompareBase& rhs)
00056   {  if (this!=&rhs) {test_=rhs.test_;}
00057   return *this;
00058   };
00059 
00061   virtual CbcCompareBase * clone() const=0;
00062 
00064   virtual bool test (CbcNode * x, CbcNode * y) {return true;};
00065 
00067   virtual bool alternateTest (CbcNode * x, CbcNode * y) {return test(x,y);};
00068 
00069   bool operator() (CbcNode * x, CbcNode * y) {
00070     return test(x,y);
00071   }
00072 protected:
00073   CbcCompareBase * test_;
00074 };
00075 class CbcCompare {
00076 public:
00077   CbcCompareBase * test_;
00078   // Default Constructor 
00079   CbcCompare () {test_=NULL;};
00080 
00081   virtual ~CbcCompare() {};
00082 
00083   bool operator() (CbcNode * x, CbcNode * y) {
00084     return test_->test(x,y);
00085   }
00087   inline bool alternateTest (CbcNode * x, CbcNode * y) {return test_->alternateTest(x,y);};
00088 
00090   inline CbcCompareBase * comparisonObject() const
00091   { return test_;};
00092 };
00093 //#############################################################################
00094 /*  These can be alternative strategies for choosing variables
00095     Any descendant can be passed in by setVariableChoice
00096 */
00097 
00098 class CbcChooseVariable {
00099 public:
00100   // Default Constructor 
00101   CbcChooseVariable () {};
00102 
00103   virtual ~CbcChooseVariable() {};
00109   virtual int chosen (const CbcModel * model,int numberToLookAt,
00110                       const int * which, const double * downMovement,
00111                       const double * upMovement, const double * solution,
00112                       int & way, double & value)=0;
00113 
00114 };
00115 #endif

Generated on Thu May 15 21:59:04 2008 by  doxygen 1.4.7