source: stable/2.9/Cbc/src/CbcCompareBase.hpp @ 2112

Last change on this file since 2112 was 1573, checked in by lou, 9 years ago

Change to EPL license notice.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1/* $Id: CbcCompareBase.hpp 1573 2011-01-05 01:12:36Z tkr $ */
2// Copyright (C) 2002, International Business Machines
3// Corporation and others.  All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
6#ifndef CbcCompareBase_H
7#define CbcCompareBase_H
8
9
10//#############################################################################
11/*  These are alternative strategies for node traversal.
12    They can take data etc for fine tuning
13
14    At present the node list is stored as a heap and the "test"
15    comparison function returns true if node y is better than node x.
16
17    This is rather inflexible so if the comparison functions wants
18    it can signal to use alternative criterion on a complete pass
19    throgh tree.
20
21*/
22#include "CbcNode.hpp"
23#include "CbcConfig.h"
24
25class CbcModel;
26class CbcTree;
27class CbcCompareBase {
28public:
29    // Default Constructor
30    CbcCompareBase () {
31        test_ = NULL;
32        threaded_ = false;
33    }
34
35    /*! \brief Reconsider behaviour after discovering a new solution.
36   
37      This allows any method to change its behaviour. It is called
38      after each solution.
39
40      The method should return true if changes are made which will
41      alter the evaluation criteria applied to a node. (So that in
42      cases where the search tree is sorted, it can be properly
43      rebuilt.)
44    */
45    virtual bool newSolution(CbcModel * ) { return (false) ; }
46
47    /*! \brief Reconsider behaviour after discovering a new solution.
48   
49      This allows any method to change its behaviour. It is called
50      after each solution.
51
52      The method should return true if changes are made which will
53      alter the evaluation criteria applied to a node. (So that in
54      cases where the search tree is sorted, it can be properly
55      rebuilt.)
56    */
57    virtual bool newSolution(CbcModel * ,
58                             double ,
59                             int ) { return (false) ; }
60
61    // This allows any method to change behavior as it is called
62    // after every 1000 nodes.
63    // Return true if want tree re-sorted
64    virtual bool every1000Nodes(CbcModel * , int ) {
65        return false;
66    }
67
68    /** Returns true if wants code to do scan with alternate criterion
69        NOTE - this is temporarily disabled
70    */
71    virtual bool fullScan() const {
72        return false;
73    }
74
75    virtual ~CbcCompareBase() {}
76    /// Create C++ lines to get to current state
77    virtual void generateCpp( FILE * ) {}
78
79    // Copy constructor
80    CbcCompareBase ( const CbcCompareBase & rhs) {
81        test_ = rhs.test_;
82        threaded_ = rhs.threaded_;
83    }
84
85    // Assignment operator
86    CbcCompareBase & operator=( const CbcCompareBase& rhs) {
87        if (this != &rhs) {
88            test_ = rhs.test_;
89            threaded_ = rhs.threaded_;
90        }
91        return *this;
92    }
93
94    /// Clone
95    virtual CbcCompareBase * clone() const {
96        abort();
97        return NULL;
98    }
99
100    /// This is test function
101    virtual bool test (CbcNode * , CbcNode * ) {
102        return true;
103    }
104
105    /// This is alternate test function
106    virtual bool alternateTest (CbcNode * x, CbcNode * y) {
107        return test(x, y);
108    }
109
110    bool operator() (CbcNode * x, CbcNode * y) {
111        return test(x, y);
112    }
113    /// Further test if everything else equal
114    inline bool equalityTest (CbcNode * x, CbcNode * y) const {
115        assert (x);
116        assert (y);
117        if (!threaded_) {
118            CbcNodeInfo * infoX = x->nodeInfo();
119            assert (infoX);
120            int nodeNumberX = infoX->nodeNumber();
121            CbcNodeInfo * infoY = y->nodeInfo();
122            assert (infoY);
123            int nodeNumberY = infoY->nodeNumber();
124            assert (nodeNumberX != nodeNumberY);
125            return (nodeNumberX > nodeNumberY);
126        } else {
127            assert (x->nodeNumber() != y->nodeNumber());
128            return (x->nodeNumber() > y->nodeNumber());
129        }
130    }
131    /// Say threaded
132    inline void sayThreaded() {
133        threaded_ = true;
134    }
135protected:
136    CbcCompareBase * test_;
137    // If not threaded we can use better way to break ties
138    bool threaded_;
139};
140
141#endif
142
Note: See TracBrowser for help on using the repository browser.