1 | // $Id: CbcGeneralDepth.hpp 1899 2013-04-09 18:12:08Z stefan $ |
---|
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 | // Edwin 11/10/2009-- carved out of CbcBranchActual |
---|
7 | |
---|
8 | #ifndef CbcGeneralDepth_H |
---|
9 | #define CbcGeneralDepth_H |
---|
10 | |
---|
11 | #include "CbcGeneral.hpp" |
---|
12 | #include "CbcBranchBase.hpp" |
---|
13 | #include "CbcSubProblem.hpp" |
---|
14 | |
---|
15 | #ifdef COIN_HAS_CLP |
---|
16 | |
---|
17 | /** Define a catch all class. |
---|
18 | This will create a list of subproblems using partial evaluation |
---|
19 | */ |
---|
20 | #include "ClpSimplex.hpp" |
---|
21 | #include "ClpNode.hpp" |
---|
22 | |
---|
23 | |
---|
24 | class CbcGeneralDepth : public CbcGeneral { |
---|
25 | |
---|
26 | public: |
---|
27 | |
---|
28 | // Default Constructor |
---|
29 | CbcGeneralDepth (); |
---|
30 | |
---|
31 | /** Useful constructor |
---|
32 | Just needs to point to model. |
---|
33 | Initial version does evaluation to depth N |
---|
34 | This is stored in CbcModel but may be |
---|
35 | better here |
---|
36 | */ |
---|
37 | CbcGeneralDepth (CbcModel * model, int maximumDepth); |
---|
38 | |
---|
39 | // Copy constructor |
---|
40 | CbcGeneralDepth ( const CbcGeneralDepth &); |
---|
41 | |
---|
42 | /// Clone |
---|
43 | virtual CbcObject * clone() const; |
---|
44 | |
---|
45 | // Assignment operator |
---|
46 | CbcGeneralDepth & operator=( const CbcGeneralDepth& rhs); |
---|
47 | |
---|
48 | // Destructor |
---|
49 | ~CbcGeneralDepth (); |
---|
50 | |
---|
51 | /// Infeasibility - large is 0.5 |
---|
52 | virtual double infeasibility(const OsiBranchingInformation * info, |
---|
53 | int &preferredWay) const; |
---|
54 | |
---|
55 | using CbcObject::feasibleRegion ; |
---|
56 | /// This looks at solution and sets bounds to contain solution |
---|
57 | virtual void feasibleRegion(); |
---|
58 | |
---|
59 | /// Creates a branching object |
---|
60 | virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) ; |
---|
61 | /// Return maximum number of nodes |
---|
62 | inline int maximumNodes() const { |
---|
63 | return maximumNodes_; |
---|
64 | } |
---|
65 | /// Get maximum depth |
---|
66 | inline int maximumDepth() const { |
---|
67 | return maximumDepth_; |
---|
68 | } |
---|
69 | /// Set maximum depth |
---|
70 | inline void setMaximumDepth(int value) { |
---|
71 | maximumDepth_ = value; |
---|
72 | } |
---|
73 | /// Return number of nodes |
---|
74 | inline int numberNodes() const { |
---|
75 | return numberNodes_; |
---|
76 | } |
---|
77 | /// Get which solution |
---|
78 | inline int whichSolution() const { |
---|
79 | return whichSolution_; |
---|
80 | } |
---|
81 | /// Get ClpNode info |
---|
82 | inline ClpNode * nodeInfo(int which) { |
---|
83 | return nodeInfo_->nodeInfo_[which]; |
---|
84 | } |
---|
85 | |
---|
86 | /// Redoes data when sequence numbers change |
---|
87 | virtual void redoSequenceEtc(CbcModel * model, int numberColumns, const int * originalColumns); |
---|
88 | |
---|
89 | protected: |
---|
90 | /// data |
---|
91 | /// Maximum depth |
---|
92 | int maximumDepth_; |
---|
93 | /// Maximum nodes |
---|
94 | int maximumNodes_; |
---|
95 | /// Which node has solution (or -1) |
---|
96 | mutable int whichSolution_; |
---|
97 | /// Number of valid nodes (including whichSolution_) |
---|
98 | mutable int numberNodes_; |
---|
99 | /// For solving nodes |
---|
100 | mutable ClpNodeStuff * nodeInfo_; |
---|
101 | }; |
---|
102 | /** Branching object for general objects |
---|
103 | |
---|
104 | */ |
---|
105 | class CbcNode; |
---|
106 | class CbcGeneralBranchingObject : public CbcBranchingObject { |
---|
107 | |
---|
108 | public: |
---|
109 | |
---|
110 | // Default Constructor |
---|
111 | CbcGeneralBranchingObject (); |
---|
112 | |
---|
113 | // Useful constructor |
---|
114 | CbcGeneralBranchingObject (CbcModel * model); |
---|
115 | |
---|
116 | // Copy constructor |
---|
117 | CbcGeneralBranchingObject ( const CbcGeneralBranchingObject &); |
---|
118 | |
---|
119 | // Assignment operator |
---|
120 | CbcGeneralBranchingObject & operator=( const CbcGeneralBranchingObject& rhs); |
---|
121 | |
---|
122 | /// Clone |
---|
123 | virtual CbcBranchingObject * clone() const; |
---|
124 | |
---|
125 | // Destructor |
---|
126 | virtual ~CbcGeneralBranchingObject (); |
---|
127 | |
---|
128 | using CbcBranchingObject::branch ; |
---|
129 | /// Does next branch and updates state |
---|
130 | virtual double branch(); |
---|
131 | /** Double checks in case node can change its mind! |
---|
132 | Can change objective etc */ |
---|
133 | virtual void checkIsCutoff(double cutoff); |
---|
134 | |
---|
135 | using CbcBranchingObject::print ; |
---|
136 | /** \brief Print something about branch - only if log level high |
---|
137 | */ |
---|
138 | virtual void print(); |
---|
139 | /// Fill in current objective etc |
---|
140 | void state(double & objectiveValue, double & sumInfeasibilities, |
---|
141 | int & numberUnsatisfied, int which) const; |
---|
142 | /// Set CbcNode |
---|
143 | inline void setNode(CbcNode * node) { |
---|
144 | node_ = node; |
---|
145 | } |
---|
146 | /** Return the type (an integer identifier) of \c this */ |
---|
147 | virtual CbcBranchObjType type() const { |
---|
148 | return GeneralDepthBranchObj; |
---|
149 | } |
---|
150 | |
---|
151 | /** Compare the original object of \c this with the original object of \c |
---|
152 | brObj. Assumes that there is an ordering of the original objects. |
---|
153 | This method should be invoked only if \c this and brObj are of the same |
---|
154 | type. |
---|
155 | Return negative/0/positive depending on whether \c this is |
---|
156 | smaller/same/larger than the argument. |
---|
157 | */ |
---|
158 | virtual int compareOriginalObject(const CbcBranchingObject* brObj) const; |
---|
159 | |
---|
160 | /** Compare the \c this with \c brObj. \c this and \c brObj must be os the |
---|
161 | same type and must have the same original object, but they may have |
---|
162 | different feasible regions. |
---|
163 | Return the appropriate CbcRangeCompare value (first argument being the |
---|
164 | sub/superset if that's the case). In case of overlap (and if \c |
---|
165 | replaceIfOverlap is true) replace the current branching object with one |
---|
166 | whose feasible region is the overlap. |
---|
167 | */ |
---|
168 | virtual CbcRangeCompare compareBranchingObject |
---|
169 | (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false); |
---|
170 | /// Number of subproblems |
---|
171 | inline int numberSubProblems() const { |
---|
172 | return numberSubProblems_; |
---|
173 | } |
---|
174 | /// Decrement number left and return number |
---|
175 | inline int decrementNumberLeft() { |
---|
176 | numberSubLeft_--; |
---|
177 | return numberSubLeft_; |
---|
178 | } |
---|
179 | /// Which node we want to use |
---|
180 | inline int whichNode() const { |
---|
181 | return whichNode_; |
---|
182 | } |
---|
183 | /// Set which node we want to use |
---|
184 | inline void setWhichNode(int value) { |
---|
185 | whichNode_ = value; |
---|
186 | } |
---|
187 | // Sub problem |
---|
188 | const CbcSubProblem * subProblem(int which) const { |
---|
189 | return subProblems_ + which; |
---|
190 | } |
---|
191 | |
---|
192 | public: |
---|
193 | /// data |
---|
194 | // Sub problems |
---|
195 | CbcSubProblem * subProblems_; |
---|
196 | /// Node |
---|
197 | CbcNode * node_; |
---|
198 | /// Number of subproblems |
---|
199 | int numberSubProblems_; |
---|
200 | /// Number of subproblems left |
---|
201 | int numberSubLeft_; |
---|
202 | /// Which node we want to use (-1 for default) |
---|
203 | int whichNode_; |
---|
204 | /// Number of rows |
---|
205 | int numberRows_; |
---|
206 | }; |
---|
207 | /** Branching object for general objects - just one |
---|
208 | |
---|
209 | */ |
---|
210 | class CbcOneGeneralBranchingObject : public CbcBranchingObject { |
---|
211 | |
---|
212 | public: |
---|
213 | |
---|
214 | // Default Constructor |
---|
215 | CbcOneGeneralBranchingObject (); |
---|
216 | |
---|
217 | // Useful constructor |
---|
218 | CbcOneGeneralBranchingObject (CbcModel * model, |
---|
219 | CbcGeneralBranchingObject * object, |
---|
220 | int whichOne); |
---|
221 | |
---|
222 | // Copy constructor |
---|
223 | CbcOneGeneralBranchingObject ( const CbcOneGeneralBranchingObject &); |
---|
224 | |
---|
225 | // Assignment operator |
---|
226 | CbcOneGeneralBranchingObject & operator=( const CbcOneGeneralBranchingObject& rhs); |
---|
227 | |
---|
228 | /// Clone |
---|
229 | virtual CbcBranchingObject * clone() const; |
---|
230 | |
---|
231 | // Destructor |
---|
232 | virtual ~CbcOneGeneralBranchingObject (); |
---|
233 | |
---|
234 | using CbcBranchingObject::branch ; |
---|
235 | /// Does next branch and updates state |
---|
236 | virtual double branch(); |
---|
237 | /** Double checks in case node can change its mind! |
---|
238 | Can change objective etc */ |
---|
239 | virtual void checkIsCutoff(double cutoff); |
---|
240 | |
---|
241 | using CbcBranchingObject::print ; |
---|
242 | /** \brief Print something about branch - only if log level high |
---|
243 | */ |
---|
244 | virtual void print(); |
---|
245 | /** Return the type (an integer identifier) of \c this */ |
---|
246 | virtual CbcBranchObjType type() const { |
---|
247 | return OneGeneralBranchingObj; |
---|
248 | } |
---|
249 | |
---|
250 | /** Compare the original object of \c this with the original object of \c |
---|
251 | brObj. Assumes that there is an ordering of the original objects. |
---|
252 | This method should be invoked only if \c this and brObj are of the same |
---|
253 | type. |
---|
254 | Return negative/0/positive depending on whether \c this is |
---|
255 | smaller/same/larger than the argument. |
---|
256 | */ |
---|
257 | virtual int compareOriginalObject(const CbcBranchingObject* brObj) const; |
---|
258 | |
---|
259 | /** Compare the \c this with \c brObj. \c this and \c brObj must be os the |
---|
260 | same type and must have the same original object, but they may have |
---|
261 | different feasible regions. |
---|
262 | Return the appropriate CbcRangeCompare value (first argument being the |
---|
263 | sub/superset if that's the case). In case of overlap (and if \c |
---|
264 | replaceIfOverlap is true) replace the current branching object with one |
---|
265 | whose feasible region is the overlap. |
---|
266 | */ |
---|
267 | virtual CbcRangeCompare compareBranchingObject |
---|
268 | (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false); |
---|
269 | |
---|
270 | public: |
---|
271 | /// data |
---|
272 | /// Object |
---|
273 | CbcGeneralBranchingObject * object_; |
---|
274 | /// Which one |
---|
275 | int whichOne_; |
---|
276 | }; |
---|
277 | #endif //COIN_HAS_CLP |
---|
278 | #endif |
---|
279 | |
---|