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

Go to the documentation of this file.
00001 /* $Id: CbcCompareBase.hpp 1271 2009-11-05 15:57:25Z forrest $ */
00002 // Copyright (C) 2002, International Business Machines
00003 // Corporation and others.  All Rights Reserved.
00004 #ifndef CbcCompareBase_H
00005 #define CbcCompareBase_H
00006 
00007 
00008 //#############################################################################
00009 /*  These are alternative strategies for node traversal.  
00010     They can take data etc for fine tuning 
00011 
00012     At present the node list is stored as a heap and the "test"
00013     comparison function returns true if node y is better than node x.
00014 
00015     This is rather inflexible so if the comparison functions wants
00016     it can signal to use alternative criterion on a complete pass
00017     throgh tree.
00018 
00019 */
00020 #include "CbcNode.hpp"
00021 #include "CbcConfig.h"
00022 
00023 class CbcModel;
00024 class CbcTree;
00025 class CbcCompareBase {
00026 public:
00027   // Default Constructor 
00028   CbcCompareBase () {test_=NULL;threaded_=false;}
00029 
00030   // This allows any method to change behavior as it is called
00031   // after each solution
00032   virtual void newSolution(CbcModel * ) {}
00033 
00034   // This Also allows any method to change behavior as it is called
00035   // after each solution
00036   virtual void newSolution(CbcModel * ,
00037                            double ,
00038                            int ) {}
00039 
00040   // This allows any method to change behavior as it is called
00041   // after every 1000 nodes.
00042   // Return true if want tree re-sorted
00043   virtual bool every1000Nodes(CbcModel * ,int ) {return false;}
00044 
00048   virtual bool fullScan() const { return false;}
00049 
00050   virtual ~CbcCompareBase() {}
00052   virtual void generateCpp( FILE * ) {}
00053 
00054   // Copy constructor 
00055   CbcCompareBase ( const CbcCompareBase & rhs)
00056   {test_=rhs.test_;threaded_=rhs.threaded_;}
00057    
00058   // Assignment operator 
00059   CbcCompareBase & operator=( const CbcCompareBase& rhs)
00060   {  if (this!=&rhs) {test_=rhs.test_;threaded_=rhs.threaded_;}
00061   return *this;
00062   }
00063 
00065   virtual CbcCompareBase * clone() const
00066   { abort(); return NULL;}
00067 
00069   virtual bool test (CbcNode * , CbcNode * ) {return true;}
00070 
00072   virtual bool alternateTest (CbcNode * x, CbcNode * y) {return test(x,y);}
00073 
00074   bool operator() (CbcNode * x, CbcNode * y) {
00075     return test(x,y);
00076   }
00078   inline bool equalityTest (CbcNode * x, CbcNode * y) const
00079   {
00080     assert (x);
00081     assert (y);
00082     if (!threaded_) {
00083       CbcNodeInfo * infoX = x->nodeInfo();
00084       assert (infoX);
00085       int nodeNumberX = infoX->nodeNumber();
00086       CbcNodeInfo * infoY = y->nodeInfo();
00087       assert (infoY);
00088       int nodeNumberY = infoY->nodeNumber();
00089       assert (nodeNumberX!=nodeNumberY);
00090       return (nodeNumberX>nodeNumberY);
00091     } else {
00092       assert (x->nodeNumber()!=y->nodeNumber());
00093       return (x->nodeNumber()>y->nodeNumber());
00094     }
00095   }
00097   inline void sayThreaded()
00098   { threaded_ = true;}
00099 protected:
00100   CbcCompareBase * test_;
00101   // If not threaded we can use better way to break ties
00102   bool threaded_;
00103 };
00104 class CbcCompare {
00105 public:
00106   CbcCompareBase * test_;
00107   // Default Constructor 
00108   CbcCompare () {test_=NULL;}
00109 
00110   virtual ~CbcCompare() {}
00111 
00112   bool operator() (CbcNode * x, CbcNode * y) {
00113     return test_->test(x,y);
00114   }
00115   bool compareNodes (CbcNode * x, CbcNode * y) {
00116     return test_->test(x,y);
00117   }
00119   inline bool alternateTest (CbcNode * x, CbcNode * y) {return test_->alternateTest(x,y);}
00120 
00122   inline CbcCompareBase * comparisonObject() const
00123   { return test_;}
00124 };
00125 //#############################################################################
00126 /*  These can be alternative strategies for choosing variables
00127     Any descendant can be passed in by setVariableChoice
00128 */
00129 
00130 class CbcChooseVariable {
00131 public:
00132   // Default Constructor 
00133   CbcChooseVariable () {}
00134 
00135   virtual ~CbcChooseVariable() {}
00141   virtual int chosen (const CbcModel * model,int numberToLookAt,
00142                       const int * which, const double * downMovement,
00143                       const double * upMovement, const double * solution,
00144                       int & way, double & value)=0;
00145 
00146 };
00147 #endif

Generated on Tue Jan 19 03:02:15 2010 by  doxygen 1.4.7