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