/home/coin/SVN-release/Cbc-2.0.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 #include "CbcConfig.h"
00021 
00022 class CbcModel;
00023 class CbcTree;
00024 class CbcCompareBase {
00025 public:
00026   // Default Constructor 
00027   CbcCompareBase () {test_=NULL;}
00028 
00029   // This allows any method to change behavior as it is called
00030   // after each solution
00031   virtual void newSolution(CbcModel * model) {}
00032 
00033   // This Also allows any method to change behavior as it is called
00034   // after each solution
00035   virtual void newSolution(CbcModel * model,
00036                            double objectiveAtContinuous,
00037                            int numberInfeasibilitiesAtContinuous) {}
00038 
00039   // This allows any method to change behavior as it is called
00040   // after every 1000 nodes.
00041   // Return true if want tree re-sorted
00042   virtual bool every1000Nodes(CbcModel * model,int numberNodes) {return false;}
00043 
00047   virtual bool fullScan() const { return false;}
00048 
00049   virtual ~CbcCompareBase() {}
00051   virtual void generateCpp( FILE * fp) {}
00052 
00053   // Copy constructor 
00054   CbcCompareBase ( const CbcCompareBase & rhs)
00055   {test_=rhs.test_;}
00056    
00057   // Assignment operator 
00058   CbcCompareBase & operator=( const CbcCompareBase& rhs)
00059   {  if (this!=&rhs) {test_=rhs.test_;}
00060   return *this;
00061   }
00062 
00064   virtual CbcCompareBase * clone() const
00065   { abort(); return NULL;}
00066 
00068   virtual bool test (CbcNode * x, CbcNode * y) {return true;}
00069 
00071   virtual bool alternateTest (CbcNode * x, CbcNode * y) {return test(x,y);}
00072 
00073   bool operator() (CbcNode * x, CbcNode * y) {
00074     return test(x,y);
00075   }
00077   inline bool equalityTest (CbcNode * x, CbcNode * y) const
00078   {
00079     assert (x);
00080     assert (y);
00081 #ifndef CBC_THREAD
00082     CbcNodeInfo * infoX = x->nodeInfo();
00083     assert (infoX);
00084     int nodeNumberX = infoX->nodeNumber();
00085     CbcNodeInfo * infoY = y->nodeInfo();
00086     assert (infoY);
00087     int nodeNumberY = infoY->nodeNumber();
00088     assert (nodeNumberX!=nodeNumberY);
00089     return (nodeNumberX>nodeNumberY);
00090 #else
00091     // doesn't work if threaded
00092     assert (x!=y);
00093     return (x>y);
00094 #endif
00095   }
00096 protected:
00097   CbcCompareBase * test_;
00098 };
00099 class CbcCompare {
00100 public:
00101   CbcCompareBase * test_;
00102   // Default Constructor 
00103   CbcCompare () {test_=NULL;}
00104 
00105   virtual ~CbcCompare() {}
00106 
00107   bool operator() (CbcNode * x, CbcNode * y) {
00108     return test_->test(x,y);
00109   }
00110   bool compareNodes (CbcNode * x, CbcNode * y) {
00111     return test_->test(x,y);
00112   }
00114   inline bool alternateTest (CbcNode * x, CbcNode * y) {return test_->alternateTest(x,y);}
00115 
00117   inline CbcCompareBase * comparisonObject() const
00118   { return test_;}
00119 };
00120 //#############################################################################
00121 /*  These can be alternative strategies for choosing variables
00122     Any descendant can be passed in by setVariableChoice
00123 */
00124 
00125 class CbcChooseVariable {
00126 public:
00127   // Default Constructor 
00128   CbcChooseVariable () {}
00129 
00130   virtual ~CbcChooseVariable() {}
00136   virtual int chosen (const CbcModel * model,int numberToLookAt,
00137                       const int * which, const double * downMovement,
00138                       const double * upMovement, const double * solution,
00139                       int & way, double & value)=0;
00140 
00141 };
00142 #endif

Generated on Thu May 15 22:07:39 2008 by  doxygen 1.4.7