source: trunk/Cbc/src/CbcCompareBase.hpp @ 1514

Last change on this file since 1514 was 1506, checked in by lou, 9 years ago

Fix `Invalid heap' error in cl debug builds. Add validateHeap method to CbcTree? for future debugging.

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