1 | // $Id$ |
---|
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 | /// Get which solution |
---|
74 | inline int whichSolution() const { |
---|
75 | return whichSolution_; |
---|
76 | } |
---|
77 | /// Get ClpNode info |
---|
78 | inline ClpNode * nodeInfo(int which) { |
---|
79 | return nodeInfo_->nodeInfo_[which]; |
---|
80 | } |
---|
81 | |
---|
82 | /// Redoes data when sequence numbers change |
---|
83 | virtual void redoSequenceEtc(CbcModel * model, int numberColumns, const int * originalColumns); |
---|
84 | |
---|
85 | protected: |
---|
86 | /// data |
---|
87 | /// Maximum depth |
---|
88 | int maximumDepth_; |
---|
89 | /// Maximum nodes |
---|
90 | int maximumNodes_; |
---|
91 | /// Which node has solution (or -1) |
---|
92 | mutable int whichSolution_; |
---|
93 | /// Number of valid nodes (including whichSolution_) |
---|
94 | mutable int numberNodes_; |
---|
95 | /// For solving nodes |
---|
96 | mutable ClpNodeStuff * nodeInfo_; |
---|
97 | }; |
---|
98 | /** Branching object for general objects |
---|
99 | |
---|
100 | */ |
---|
101 | class CbcNode; |
---|
102 | class CbcGeneralBranchingObject : public CbcBranchingObject { |
---|
103 | |
---|
104 | public: |
---|
105 | |
---|
106 | // Default Constructor |
---|
107 | CbcGeneralBranchingObject (); |
---|
108 | |
---|
109 | // Useful constructor |
---|
110 | CbcGeneralBranchingObject (CbcModel * model); |
---|
111 | |
---|
112 | // Copy constructor |
---|
113 | CbcGeneralBranchingObject ( const CbcGeneralBranchingObject &); |
---|
114 | |
---|
115 | // Assignment operator |
---|
116 | CbcGeneralBranchingObject & operator=( const CbcGeneralBranchingObject& rhs); |
---|
117 | |
---|
118 | /// Clone |
---|
119 | virtual CbcBranchingObject * clone() const; |
---|
120 | |
---|
121 | // Destructor |
---|
122 | virtual ~CbcGeneralBranchingObject (); |
---|
123 | |
---|
124 | using CbcBranchingObject::branch ; |
---|
125 | /// Does next branch and updates state |
---|
126 | virtual double branch(); |
---|
127 | /** Double checks in case node can change its mind! |
---|
128 | Can change objective etc */ |
---|
129 | virtual void checkIsCutoff(double cutoff); |
---|
130 | |
---|
131 | using CbcBranchingObject::print ; |
---|
132 | /** \brief Print something about branch - only if log level high |
---|
133 | */ |
---|
134 | virtual void print(); |
---|
135 | /// Fill in current objective etc |
---|
136 | void state(double & objectiveValue, double & sumInfeasibilities, |
---|
137 | int & numberUnsatisfied, int which) const; |
---|
138 | /// Set CbcNode |
---|
139 | inline void setNode(CbcNode * node) { |
---|
140 | node_ = node; |
---|
141 | } |
---|
142 | /** Return the type (an integer identifier) of \c this */ |
---|
143 | virtual CbcBranchObjType type() const { |
---|
144 | return GeneralDepthBranchObj; |
---|
145 | } |
---|
146 | |
---|
147 | /** Compare the original object of \c this with the original object of \c |
---|
148 | brObj. Assumes that there is an ordering of the original objects. |
---|
149 | This method should be invoked only if \c this and brObj are of the same |
---|
150 | type. |
---|
151 | Return negative/0/positive depending on whether \c this is |
---|
152 | smaller/same/larger than the argument. |
---|
153 | */ |
---|
154 | virtual int compareOriginalObject(const CbcBranchingObject* brObj) const; |
---|
155 | |
---|
156 | /** Compare the \c this with \c brObj. \c this and \c brObj must be os the |
---|
157 | same type and must have the same original object, but they may have |
---|
158 | different feasible regions. |
---|
159 | Return the appropriate CbcRangeCompare value (first argument being the |
---|
160 | sub/superset if that's the case). In case of overlap (and if \c |
---|
161 | replaceIfOverlap is true) replace the current branching object with one |
---|
162 | whose feasible region is the overlap. |
---|
163 | */ |
---|
164 | virtual CbcRangeCompare compareBranchingObject |
---|
165 | (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false); |
---|
166 | /// Number of subproblems |
---|
167 | inline int numberSubProblems() const { |
---|
168 | return numberSubProblems_; |
---|
169 | } |
---|
170 | /// Decrement number left and return number |
---|
171 | inline int decrementNumberLeft() { |
---|
172 | numberSubLeft_--; |
---|
173 | return numberSubLeft_; |
---|
174 | } |
---|
175 | /// Which node we want to use |
---|
176 | inline int whichNode() const { |
---|
177 | return whichNode_; |
---|
178 | } |
---|
179 | /// Set which node we want to use |
---|
180 | inline void setWhichNode(int value) { |
---|
181 | whichNode_ = value; |
---|
182 | } |
---|
183 | // Sub problem |
---|
184 | const CbcSubProblem * subProblem(int which) const { |
---|
185 | return subProblems_ + which; |
---|
186 | } |
---|
187 | |
---|
188 | public: |
---|
189 | /// data |
---|
190 | // Sub problems |
---|
191 | CbcSubProblem * subProblems_; |
---|
192 | /// Node |
---|
193 | CbcNode * node_; |
---|
194 | /// Number of subproblems |
---|
195 | int numberSubProblems_; |
---|
196 | /// Number of subproblems left |
---|
197 | int numberSubLeft_; |
---|
198 | /// Which node we want to use (-1 for default) |
---|
199 | int whichNode_; |
---|
200 | /// Number of rows |
---|
201 | int numberRows_; |
---|
202 | }; |
---|
203 | /** Branching object for general objects - just one |
---|
204 | |
---|
205 | */ |
---|
206 | class CbcOneGeneralBranchingObject : public CbcBranchingObject { |
---|
207 | |
---|
208 | public: |
---|
209 | |
---|
210 | // Default Constructor |
---|
211 | CbcOneGeneralBranchingObject (); |
---|
212 | |
---|
213 | // Useful constructor |
---|
214 | CbcOneGeneralBranchingObject (CbcModel * model, |
---|
215 | CbcGeneralBranchingObject * object, |
---|
216 | int whichOne); |
---|
217 | |
---|
218 | // Copy constructor |
---|
219 | CbcOneGeneralBranchingObject ( const CbcOneGeneralBranchingObject &); |
---|
220 | |
---|
221 | // Assignment operator |
---|
222 | CbcOneGeneralBranchingObject & operator=( const CbcOneGeneralBranchingObject& rhs); |
---|
223 | |
---|
224 | /// Clone |
---|
225 | virtual CbcBranchingObject * clone() const; |
---|
226 | |
---|
227 | // Destructor |
---|
228 | virtual ~CbcOneGeneralBranchingObject (); |
---|
229 | |
---|
230 | using CbcBranchingObject::branch ; |
---|
231 | /// Does next branch and updates state |
---|
232 | virtual double branch(); |
---|
233 | /** Double checks in case node can change its mind! |
---|
234 | Can change objective etc */ |
---|
235 | virtual void checkIsCutoff(double cutoff); |
---|
236 | |
---|
237 | using CbcBranchingObject::print ; |
---|
238 | /** \brief Print something about branch - only if log level high |
---|
239 | */ |
---|
240 | virtual void print(); |
---|
241 | /** Return the type (an integer identifier) of \c this */ |
---|
242 | virtual CbcBranchObjType type() const { |
---|
243 | return OneGeneralBranchingObj; |
---|
244 | } |
---|
245 | |
---|
246 | /** Compare the original object of \c this with the original object of \c |
---|
247 | brObj. Assumes that there is an ordering of the original objects. |
---|
248 | This method should be invoked only if \c this and brObj are of the same |
---|
249 | type. |
---|
250 | Return negative/0/positive depending on whether \c this is |
---|
251 | smaller/same/larger than the argument. |
---|
252 | */ |
---|
253 | virtual int compareOriginalObject(const CbcBranchingObject* brObj) const; |
---|
254 | |
---|
255 | /** Compare the \c this with \c brObj. \c this and \c brObj must be os the |
---|
256 | same type and must have the same original object, but they may have |
---|
257 | different feasible regions. |
---|
258 | Return the appropriate CbcRangeCompare value (first argument being the |
---|
259 | sub/superset if that's the case). In case of overlap (and if \c |
---|
260 | replaceIfOverlap is true) replace the current branching object with one |
---|
261 | whose feasible region is the overlap. |
---|
262 | */ |
---|
263 | virtual CbcRangeCompare compareBranchingObject |
---|
264 | (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false); |
---|
265 | |
---|
266 | public: |
---|
267 | /// data |
---|
268 | /// Object |
---|
269 | CbcGeneralBranchingObject * object_; |
---|
270 | /// Which one |
---|
271 | int whichOne_; |
---|
272 | }; |
---|
273 | #endif //COIN_HAS_CLP |
---|
274 | #endif |
---|
275 | |
---|