1 | // Copyright (C) 2004, International Business Machines |
---|
2 | // Corporation and others. All Rights Reserved. |
---|
3 | #ifndef CbcTree_H |
---|
4 | #define CbcTree_H |
---|
5 | using namespace std; |
---|
6 | |
---|
7 | |
---|
8 | #include <vector> |
---|
9 | |
---|
10 | /*! \class tree |
---|
11 | \brief Implementation of live set as a heap. |
---|
12 | |
---|
13 | This class is used to hold the set of live nodes in the search tree. |
---|
14 | */ |
---|
15 | |
---|
16 | class CbcTree { |
---|
17 | |
---|
18 | public: |
---|
19 | |
---|
20 | // Default Constructor |
---|
21 | CbcTree (); |
---|
22 | |
---|
23 | // Copy constructor |
---|
24 | CbcTree ( const CbcTree & rhs); |
---|
25 | // = operator |
---|
26 | CbcTree & operator=(const CbcTree & rhs); |
---|
27 | |
---|
28 | virtual ~CbcTree(); |
---|
29 | |
---|
30 | /// Clone |
---|
31 | virtual CbcTree * clone() const; |
---|
32 | /// Create C++ lines to get to current state |
---|
33 | virtual void generateCpp( FILE * fp) {}; |
---|
34 | |
---|
35 | /*! \name Heap access and maintenance methods */ |
---|
36 | //@{ |
---|
37 | |
---|
38 | /// Set comparison function and resort heap |
---|
39 | void setComparison(CbcCompareBase &compare); |
---|
40 | |
---|
41 | /// Return the top node of the heap |
---|
42 | virtual CbcNode * top() const; |
---|
43 | |
---|
44 | /// Add a node to the heap |
---|
45 | virtual void push(CbcNode * x); |
---|
46 | |
---|
47 | /// Remove the top node from the heap |
---|
48 | virtual void pop() ; |
---|
49 | /// Gets best node and takes off heap |
---|
50 | virtual CbcNode * bestNode(double cutoff); |
---|
51 | |
---|
52 | //@} |
---|
53 | /*! \name vector methods */ |
---|
54 | //@{ |
---|
55 | |
---|
56 | /// Test if empty *** note may be overridden |
---|
57 | virtual bool empty() ; |
---|
58 | |
---|
59 | /// Return size |
---|
60 | inline int size() const |
---|
61 | { return nodes_.size();} |
---|
62 | |
---|
63 | /// [] operator |
---|
64 | inline CbcNode * operator [] (int i) const |
---|
65 | { return nodes_[i];} |
---|
66 | |
---|
67 | /// Return a node pointer |
---|
68 | inline CbcNode * nodePointer (int i) const |
---|
69 | { return nodes_[i];} |
---|
70 | |
---|
71 | //@} |
---|
72 | |
---|
73 | /*! \name Search tree maintenance */ |
---|
74 | //@{ |
---|
75 | |
---|
76 | /*! \brief Prune the tree using an objective function cutoff |
---|
77 | |
---|
78 | This routine removes all nodes with objective worst than the |
---|
79 | specified cutoff value. |
---|
80 | It also sets bestPossibleObjective to best |
---|
81 | of all on tree before deleting. |
---|
82 | */ |
---|
83 | |
---|
84 | void cleanTree(CbcModel * model, double cutoff, double & bestPossibleObjective); |
---|
85 | |
---|
86 | /// Get best on list using alternate method |
---|
87 | CbcNode * bestAlternate(); |
---|
88 | |
---|
89 | /// We may have got an intelligent tree so give it one more chance |
---|
90 | virtual void endSearch() {} |
---|
91 | //@} |
---|
92 | protected: |
---|
93 | std::vector <CbcNode *> nodes_; |
---|
94 | CbcCompare comparison_; ///> Sort function for heap ordering. |
---|
95 | |
---|
96 | |
---|
97 | }; |
---|
98 | |
---|
99 | /// New style |
---|
100 | #include "CoinSearchTree.hpp" |
---|
101 | /*! \class tree |
---|
102 | \brief Implementation of live set as a heap. |
---|
103 | |
---|
104 | This class is used to hold the set of live nodes in the search tree. |
---|
105 | */ |
---|
106 | |
---|
107 | class CbcNewTree : public CbcTree, public CoinSearchTreeManager { |
---|
108 | |
---|
109 | public: |
---|
110 | |
---|
111 | // Default Constructor |
---|
112 | CbcNewTree (); |
---|
113 | |
---|
114 | // Copy constructor |
---|
115 | CbcNewTree ( const CbcNewTree & rhs); |
---|
116 | // = operator |
---|
117 | CbcNewTree & operator=(const CbcNewTree & rhs); |
---|
118 | |
---|
119 | virtual ~CbcNewTree(); |
---|
120 | |
---|
121 | /// Clone |
---|
122 | virtual CbcNewTree * clone() const; |
---|
123 | /// Create C++ lines to get to current state |
---|
124 | virtual void generateCpp( FILE * fp) {}; |
---|
125 | |
---|
126 | /*! \name Heap access and maintenance methods */ |
---|
127 | //@{ |
---|
128 | |
---|
129 | /// Set comparison function and resort heap |
---|
130 | void setComparison(CbcCompareBase &compare); |
---|
131 | |
---|
132 | /// Return the top node of the heap |
---|
133 | virtual CbcNode * top() const; |
---|
134 | |
---|
135 | /// Add a node to the heap |
---|
136 | virtual void push(CbcNode * x); |
---|
137 | |
---|
138 | /// Remove the top node from the heap |
---|
139 | virtual void pop() ; |
---|
140 | /// Gets best node and takes off heap |
---|
141 | virtual CbcNode * bestNode(double cutoff); |
---|
142 | |
---|
143 | //@} |
---|
144 | /*! \name vector methods */ |
---|
145 | //@{ |
---|
146 | |
---|
147 | /// Test if empty *** note may be overridden |
---|
148 | virtual bool empty() ; |
---|
149 | |
---|
150 | /// Return size |
---|
151 | inline int size() const |
---|
152 | { return nodes_.size();} |
---|
153 | |
---|
154 | /// [] operator |
---|
155 | inline CbcNode * operator [] (int i) const |
---|
156 | { return nodes_[i];} |
---|
157 | |
---|
158 | /// Return a node pointer |
---|
159 | inline CbcNode * nodePointer (int i) const |
---|
160 | { return nodes_[i];} |
---|
161 | |
---|
162 | //@} |
---|
163 | |
---|
164 | /*! \name Search tree maintenance */ |
---|
165 | //@{ |
---|
166 | |
---|
167 | /*! \brief Prune the tree using an objective function cutoff |
---|
168 | |
---|
169 | This routine removes all nodes with objective worst than the |
---|
170 | specified cutoff value. |
---|
171 | It also sets bestPossibleObjective to best |
---|
172 | of all on tree before deleting. |
---|
173 | */ |
---|
174 | |
---|
175 | void cleanTree(CbcModel * model, double cutoff, double & bestPossibleObjective); |
---|
176 | |
---|
177 | /// Get best on list using alternate method |
---|
178 | CbcNode * bestAlternate(); |
---|
179 | |
---|
180 | /// We may have got an intelligent tree so give it one more chance |
---|
181 | virtual void endSearch() {} |
---|
182 | //@} |
---|
183 | protected: |
---|
184 | |
---|
185 | |
---|
186 | }; |
---|
187 | #endif |
---|
188 | |
---|