/home/coin/SVN-release/CoinAll-1.1.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;threaded_=false;}
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_;threaded_=rhs.threaded_;}
00056    
00057   // Assignment operator 
00058   CbcCompareBase & operator=( const CbcCompareBase& rhs)
00059   {  if (this!=&rhs) {test_=rhs.test_;threaded_=rhs.threaded_;}
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     if (!threaded_) {
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       assert (x->nodeNumber()!=y->nodeNumber());
00092       return (x->nodeNumber()>y->nodeNumber());
00093     }
00094   }
00096   inline void sayThreaded()
00097   { threaded_ = true;}
00098 protected:
00099   CbcCompareBase * test_;
00100   // If not threaded we can use better way to break ties
00101   bool threaded_;
00102 };
00103 class CbcCompare {
00104 public:
00105   CbcCompareBase * test_;
00106   // Default Constructor 
00107   CbcCompare () {test_=NULL;}
00108 
00109   virtual ~CbcCompare() {}
00110 
00111   bool operator() (CbcNode * x, CbcNode * y) {
00112     return test_->test(x,y);
00113   }
00114   bool compareNodes (CbcNode * x, CbcNode * y) {
00115     return test_->test(x,y);
00116   }
00118   inline bool alternateTest (CbcNode * x, CbcNode * y) {return test_->alternateTest(x,y);}
00119 
00121   inline CbcCompareBase * comparisonObject() const
00122   { return test_;}
00123 };
00124 //#############################################################################
00125 /*  These can be alternative strategies for choosing variables
00126     Any descendant can be passed in by setVariableChoice
00127 */
00128 
00129 class CbcChooseVariable {
00130 public:
00131   // Default Constructor 
00132   CbcChooseVariable () {}
00133 
00134   virtual ~CbcChooseVariable() {}
00140   virtual int chosen (const CbcModel * model,int numberToLookAt,
00141                       const int * which, const double * downMovement,
00142                       const double * upMovement, const double * solution,
00143                       int & way, double & value)=0;
00144 
00145 };
00146 #endif

Generated on Sun Nov 14 14:06:30 2010 for Coin-All by  doxygen 1.4.7