• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

/tmp/buildd/coinor-cbc-2.5.0/debian/tmp/usr/include/coin/CbcCompareBase.hpp

Go to the documentation of this file.
00001 /* $Id: CbcCompareBase.hpp 1400 2009-12-11 14:14:06Z lou $ */
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 () {
00029         test_ = NULL;
00030         threaded_ = false;
00031     }
00032 
00033     // This allows any method to change behavior as it is called
00034     // after each solution
00035     virtual void newSolution(CbcModel * ) {}
00036 
00037     // This Also allows any method to change behavior as it is called
00038     // after each solution
00039     virtual void newSolution(CbcModel * ,
00040                              double ,
00041                              int ) {}
00042 
00043     // This allows any method to change behavior as it is called
00044     // after every 1000 nodes.
00045     // Return true if want tree re-sorted
00046     virtual bool every1000Nodes(CbcModel * , int ) {
00047         return false;
00048     }
00049 
00053     virtual bool fullScan() const {
00054         return false;
00055     }
00056 
00057     virtual ~CbcCompareBase() {}
00059     virtual void generateCpp( FILE * ) {}
00060 
00061     // Copy constructor
00062     CbcCompareBase ( const CbcCompareBase & rhs) {
00063         test_ = rhs.test_;
00064         threaded_ = rhs.threaded_;
00065     }
00066 
00067     // Assignment operator
00068     CbcCompareBase & operator=( const CbcCompareBase& rhs) {
00069         if (this != &rhs) {
00070             test_ = rhs.test_;
00071             threaded_ = rhs.threaded_;
00072         }
00073         return *this;
00074     }
00075 
00077     virtual CbcCompareBase * clone() const {
00078         abort();
00079         return NULL;
00080     }
00081 
00083     virtual bool test (CbcNode * , CbcNode * ) {
00084         return true;
00085     }
00086 
00088     virtual bool alternateTest (CbcNode * x, CbcNode * y) {
00089         return test(x, y);
00090     }
00091 
00092     bool operator() (CbcNode * x, CbcNode * y) {
00093         return test(x, y);
00094     }
00096     inline bool equalityTest (CbcNode * x, CbcNode * y) const {
00097         assert (x);
00098         assert (y);
00099         if (!threaded_) {
00100             CbcNodeInfo * infoX = x->nodeInfo();
00101             assert (infoX);
00102             int nodeNumberX = infoX->nodeNumber();
00103             CbcNodeInfo * infoY = y->nodeInfo();
00104             assert (infoY);
00105             int nodeNumberY = infoY->nodeNumber();
00106             assert (nodeNumberX != nodeNumberY);
00107             return (nodeNumberX > nodeNumberY);
00108         } else {
00109             assert (x->nodeNumber() != y->nodeNumber());
00110             return (x->nodeNumber() > y->nodeNumber());
00111         }
00112     }
00114     inline void sayThreaded() {
00115         threaded_ = true;
00116     }
00117 protected:
00118     CbcCompareBase * test_;
00119     // If not threaded we can use better way to break ties
00120     bool threaded_;
00121 };
00122 
00123 #endif
00124 

Generated on Tue Sep 7 2010 20:23:52 by  doxygen 1.7.1