# CbcCompareBase.hpp

Go to the documentation of this file.

    00001 /* $Id: CbcCompareBase.hpp 1573 2011-01-05 01:12:36Z lou $ */
    00002 // Copyright (C) 2002, International Business Machines
    00003 // Corporation and others.  All Rights Reserved.
    00004 // This code is licensed under the terms of the Eclipse Public License (EPL).
    00005
    00006 #ifndef CbcCompareBase_H
    00007 #define CbcCompareBase_H
    00008
    00009
    00010 //#############################################################################
    00011 /*  These are alternative strategies for node traversal.
    00012     They can take data etc for fine tuning
    00013
    00014     At present the node list is stored as a heap and the "test"
    00015     comparison function returns true if node y is better than node x.
    00016
    00017     This is rather inflexible so if the comparison functions wants
    00018     it can signal to use alternative criterion on a complete pass
    00019     throgh tree.
    00020
    00021 */
    00022 #include "CbcNode.hpp"
    00023 #include "CbcConfig.h"
    00024
    00025 class CbcModel;
    00026 class CbcTree;
    00027 class CbcCompareBase {
    00028 public:
    00029     // Default Constructor
    00030     CbcCompareBase () {
    00031         test_ = NULL;
    00032         threaded_ = false;
    00033     }
    00034
    00045     virtual bool newSolution(CbcModel * ) { return (false) ; }
    00046
    00057     virtual bool newSolution(CbcModel * ,
    00058                              double ,
    00059                              int ) { return (false) ; }
    00060
    00061     // This allows any method to change behavior as it is called
    00062     // after every 1000 nodes.
    00063     // Return true if want tree re-sorted
    00064     virtual bool every1000Nodes(CbcModel * , int ) {
    00065         return false;
    00066     }
    00067
    00071     virtual bool fullScan() const {
    00072         return false;
    00073     }
    00074
    00075     virtual ~CbcCompareBase() {}
    00077     virtual void generateCpp( FILE * ) {}
    00078
    00079     // Copy constructor
    00080     CbcCompareBase ( const CbcCompareBase & rhs) {
    00081         test_ = rhs.test_;
    00082         threaded_ = rhs.threaded_;
    00083     }
    00084
    00085     // Assignment operator
    00086     CbcCompareBase & operator=( const CbcCompareBase& rhs) {
    00087         if (this != &rhs) {
    00088             test_ = rhs.test_;
    00089             threaded_ = rhs.threaded_;
    00090         }
    00091         return *this;
    00092     }
    00093
    00095     virtual CbcCompareBase * clone() const {
    00096         abort();
    00097         return NULL;
    00098     }
    00099
    00101     virtual bool test (CbcNode * , CbcNode * ) {
    00102         return true;
    00103     }
    00104
    00106     virtual bool alternateTest (CbcNode * x, CbcNode * y) {
    00107         return test(x, y);
    00108     }
    00109
    00110     bool operator() (CbcNode * x, CbcNode * y) {
    00111         return test(x, y);
    00112     }
    00114     inline bool equalityTest (CbcNode * x, CbcNode * y) const {
    00115         assert (x);
    00116         assert (y);
    00117         if (!threaded_) {
    00118             CbcNodeInfo * infoX = x->nodeInfo();
    00119             assert (infoX);
    00120             int nodeNumberX = infoX->nodeNumber();
    00121             CbcNodeInfo * infoY = y->nodeInfo();
    00122             assert (infoY);
    00123             int nodeNumberY = infoY->nodeNumber();
    00124             assert (nodeNumberX != nodeNumberY);
    00125             return (nodeNumberX > nodeNumberY);
    00126         } else {
    00127             assert (x->nodeNumber() != y->nodeNumber());
    00128             return (x->nodeNumber() > y->nodeNumber());
    00129         }
    00130     }
    00132     inline void sayThreaded() {
    00133         threaded_ = true;
    00134     }
    00135 protected:
    00136     CbcCompareBase * test_;
    00137     // If not threaded we can use better way to break ties
    00138     bool threaded_;
    00139 };
    00140
    00141 #endif
    00142

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines