1 | /* $Id: CbcBranchLotsize.hpp 1351 2009-12-04 16:26:41Z EdwinStraver $ */ |
---|
2 | // Copyright (C) 2004, International Business Machines |
---|
3 | // Corporation and others. All Rights Reserved. |
---|
4 | #ifndef CbcBranchLotsize_H |
---|
5 | #define CbcBranchLotsize_H |
---|
6 | |
---|
7 | #include "CbcBranchBase.hpp" |
---|
8 | /** Lotsize class */ |
---|
9 | |
---|
10 | |
---|
11 | class CbcLotsize : public CbcObject { |
---|
12 | |
---|
13 | public: |
---|
14 | |
---|
15 | // Default Constructor |
---|
16 | CbcLotsize (); |
---|
17 | |
---|
18 | /* Useful constructor - passed model index. |
---|
19 | Also passed valid values - if range then pairs |
---|
20 | */ |
---|
21 | CbcLotsize (CbcModel * model, int iColumn, |
---|
22 | int numberPoints, const double * points, bool range = false); |
---|
23 | |
---|
24 | // Copy constructor |
---|
25 | CbcLotsize ( const CbcLotsize &); |
---|
26 | |
---|
27 | /// Clone |
---|
28 | virtual CbcObject * clone() const; |
---|
29 | |
---|
30 | // Assignment operator |
---|
31 | CbcLotsize & operator=( const CbcLotsize& rhs); |
---|
32 | |
---|
33 | // Destructor |
---|
34 | ~CbcLotsize (); |
---|
35 | |
---|
36 | /// Infeasibility - large is 0.5 |
---|
37 | virtual double infeasibility(const OsiBranchingInformation * info, |
---|
38 | int &preferredWay) const; |
---|
39 | |
---|
40 | using CbcObject::feasibleRegion ; |
---|
41 | /** Set bounds to contain the current solution. |
---|
42 | |
---|
43 | More precisely, for the variable associated with this object, take the |
---|
44 | value given in the current solution, force it within the current bounds |
---|
45 | if required, then set the bounds to fix the variable at the integer |
---|
46 | nearest the solution value. |
---|
47 | */ |
---|
48 | virtual void feasibleRegion(); |
---|
49 | |
---|
50 | /// Creates a branching object |
---|
51 | virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) ; |
---|
52 | |
---|
53 | /** \brief Given a valid solution (with reduced costs, etc.), |
---|
54 | return a branching object which would give a new feasible |
---|
55 | point in the good direction. |
---|
56 | |
---|
57 | The preferred branching object will force the variable to be +/-1 from |
---|
58 | its current value, depending on the reduced cost and objective sense. If |
---|
59 | movement in the direction which improves the objective is impossible due |
---|
60 | to bounds on the variable, the branching object will move in the other |
---|
61 | direction. If no movement is possible, the method returns NULL. |
---|
62 | |
---|
63 | Only the bounds on this variable are considered when determining if the new |
---|
64 | point is feasible. |
---|
65 | */ |
---|
66 | virtual CbcBranchingObject * preferredNewFeasible() const; |
---|
67 | |
---|
68 | /** \brief Given a valid solution (with reduced costs, etc.), |
---|
69 | return a branching object which would give a new feasible |
---|
70 | point in a bad direction. |
---|
71 | |
---|
72 | As for preferredNewFeasible(), but the preferred branching object will |
---|
73 | force movement in a direction that degrades the objective. |
---|
74 | */ |
---|
75 | virtual CbcBranchingObject * notPreferredNewFeasible() const ; |
---|
76 | |
---|
77 | /** Reset original upper and lower bound values from the solver. |
---|
78 | |
---|
79 | Handy for updating bounds held in this object after bounds held in the |
---|
80 | solver have been tightened. |
---|
81 | */ |
---|
82 | virtual void resetBounds(const OsiSolverInterface * solver); |
---|
83 | |
---|
84 | /** Finds range of interest so value is feasible in range range_ or infeasible |
---|
85 | between hi[range_] and lo[range_+1]. Returns true if feasible. |
---|
86 | */ |
---|
87 | bool findRange(double value) const; |
---|
88 | |
---|
89 | /** Returns floor and ceiling |
---|
90 | */ |
---|
91 | virtual void floorCeiling(double & floorLotsize, double & ceilingLotsize, double value, |
---|
92 | double tolerance) const; |
---|
93 | |
---|
94 | /// Model column number |
---|
95 | inline int modelSequence() const { |
---|
96 | return columnNumber_; |
---|
97 | } |
---|
98 | /// Set model column number |
---|
99 | inline void setModelSequence(int value) { |
---|
100 | columnNumber_ = value; |
---|
101 | } |
---|
102 | |
---|
103 | /** Column number if single column object -1 otherwise, |
---|
104 | so returns >= 0 |
---|
105 | Used by heuristics |
---|
106 | */ |
---|
107 | virtual int columnNumber() const; |
---|
108 | /// Original bounds |
---|
109 | inline double originalLowerBound() const { |
---|
110 | return bound_[0]; |
---|
111 | } |
---|
112 | inline double originalUpperBound() const { |
---|
113 | return bound_[rangeType_*numberRanges_-1]; |
---|
114 | } |
---|
115 | /// Type - 1 points, 2 ranges |
---|
116 | inline int rangeType() const { |
---|
117 | return rangeType_; |
---|
118 | } |
---|
119 | /// Number of points |
---|
120 | inline int numberRanges() const { |
---|
121 | return numberRanges_; |
---|
122 | } |
---|
123 | /// Ranges |
---|
124 | inline double * bound() const { |
---|
125 | return bound_; |
---|
126 | } |
---|
127 | /** \brief Return true if object can take part in normal heuristics |
---|
128 | */ |
---|
129 | virtual bool canDoHeuristics() const { |
---|
130 | return false; |
---|
131 | } |
---|
132 | |
---|
133 | private: |
---|
134 | /// Just for debug (CBC_PRINT defined in CbcBranchLotsize.cpp) |
---|
135 | void printLotsize(double value, bool condition, int type) const; |
---|
136 | |
---|
137 | private: |
---|
138 | /// data |
---|
139 | |
---|
140 | /// Column number in model |
---|
141 | int columnNumber_; |
---|
142 | /// Type - 1 points, 2 ranges |
---|
143 | int rangeType_; |
---|
144 | /// Number of points |
---|
145 | int numberRanges_; |
---|
146 | // largest gap |
---|
147 | double largestGap_; |
---|
148 | /// Ranges |
---|
149 | double * bound_; |
---|
150 | /// Current range |
---|
151 | mutable int range_; |
---|
152 | }; |
---|
153 | |
---|
154 | /** Lotsize branching object |
---|
155 | |
---|
156 | This object can specify a two-way branch on an integer variable. For each |
---|
157 | arm of the branch, the upper and lower bounds on the variable can be |
---|
158 | independently specified. |
---|
159 | |
---|
160 | Variable_ holds the index of the integer variable in the integerVariable_ |
---|
161 | array of the model. |
---|
162 | */ |
---|
163 | |
---|
164 | class CbcLotsizeBranchingObject : public CbcBranchingObject { |
---|
165 | |
---|
166 | public: |
---|
167 | |
---|
168 | /// Default constructor |
---|
169 | CbcLotsizeBranchingObject (); |
---|
170 | |
---|
171 | /** Create a lotsize floor/ceiling branch object |
---|
172 | |
---|
173 | Specifies a simple two-way branch. Let \p value = x*. One arm of the |
---|
174 | branch will be is lb <= x <= valid range below(x*), the other valid range above(x*) <= x <= ub. |
---|
175 | Specify way = -1 to set the object state to perform the down arm first, |
---|
176 | way = 1 for the up arm. |
---|
177 | */ |
---|
178 | CbcLotsizeBranchingObject (CbcModel *model, int variable, |
---|
179 | int way , double value, const CbcLotsize * lotsize) ; |
---|
180 | |
---|
181 | /** Create a degenerate branch object |
---|
182 | |
---|
183 | Specifies a `one-way branch'. Calling branch() for this object will |
---|
184 | always result in lowerValue <= x <= upperValue. Used to fix in valid range |
---|
185 | */ |
---|
186 | |
---|
187 | CbcLotsizeBranchingObject (CbcModel *model, int variable, int way, |
---|
188 | double lowerValue, double upperValue) ; |
---|
189 | |
---|
190 | /// Copy constructor |
---|
191 | CbcLotsizeBranchingObject ( const CbcLotsizeBranchingObject &); |
---|
192 | |
---|
193 | /// Assignment operator |
---|
194 | CbcLotsizeBranchingObject & operator= (const CbcLotsizeBranchingObject& rhs); |
---|
195 | |
---|
196 | /// Clone |
---|
197 | virtual CbcBranchingObject * clone() const; |
---|
198 | |
---|
199 | /// Destructor |
---|
200 | virtual ~CbcLotsizeBranchingObject (); |
---|
201 | |
---|
202 | using CbcBranchingObject::branch ; |
---|
203 | /** \brief Sets the bounds for the variable according to the current arm |
---|
204 | of the branch and advances the object state to the next arm. |
---|
205 | */ |
---|
206 | virtual double branch(); |
---|
207 | |
---|
208 | #if 0 |
---|
209 | // No need to override. Default works fine. |
---|
210 | /** Reset every information so that the branching object appears to point to |
---|
211 | the previous child. This method does not need to modify anything in any |
---|
212 | solver. */ |
---|
213 | virtual void previousBranch(); |
---|
214 | #endif |
---|
215 | |
---|
216 | using CbcBranchingObject::print ; |
---|
217 | /** \brief Print something about branch - only if log level high |
---|
218 | */ |
---|
219 | virtual void print(); |
---|
220 | |
---|
221 | /** Return the type (an integer identifier) of \c this */ |
---|
222 | virtual int type() const { |
---|
223 | return 300; |
---|
224 | } |
---|
225 | |
---|
226 | // LL: compareOriginalObject can be inherited from the CbcBranchingObject |
---|
227 | // since variable_ uniquely defines the lot sizing object. |
---|
228 | |
---|
229 | /** Compare the \c this with \c brObj. \c this and \c brObj must be os the |
---|
230 | same type and must have the same original object, but they may have |
---|
231 | different feasible regions. |
---|
232 | Return the appropriate CbcRangeCompare value (first argument being the |
---|
233 | sub/superset if that's the case). In case of overlap (and if \c |
---|
234 | replaceIfOverlap is true) replace the current branching object with one |
---|
235 | whose feasible region is the overlap. |
---|
236 | */ |
---|
237 | virtual CbcRangeCompare compareBranchingObject |
---|
238 | (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false); |
---|
239 | |
---|
240 | protected: |
---|
241 | /// Lower [0] and upper [1] bounds for the down arm (way_ = -1) |
---|
242 | double down_[2]; |
---|
243 | /// Lower [0] and upper [1] bounds for the up arm (way_ = 1) |
---|
244 | double up_[2]; |
---|
245 | }; |
---|
246 | |
---|
247 | #endif |
---|