1 | // Copyright (C) 2004, International Business Machines |
---|
2 | // Corporation and others. All Rights Reserved. |
---|
3 | #ifndef CbcBranchLotsize_H |
---|
4 | #define CbcBranchLotsize_H |
---|
5 | |
---|
6 | #include "CbcBranchBase.hpp" |
---|
7 | |
---|
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(int & preferredWay) const; |
---|
38 | |
---|
39 | /** Set bounds to contain the current solution. |
---|
40 | |
---|
41 | More precisely, for the variable associated with this object, take the |
---|
42 | value given in the current solution, force it within the current bounds |
---|
43 | if required, then set the bounds to fix the variable at the integer |
---|
44 | nearest the solution value. |
---|
45 | */ |
---|
46 | virtual void feasibleRegion(); |
---|
47 | |
---|
48 | /// Creates a branching object |
---|
49 | virtual CbcBranchingObject * createBranch(int way) ; |
---|
50 | |
---|
51 | /** \brief Given a valid solution (with reduced costs, etc.), |
---|
52 | return a branching object which would give a new feasible |
---|
53 | point in the good direction. |
---|
54 | |
---|
55 | The preferred branching object will force the variable to be +/-1 from |
---|
56 | its current value, depending on the reduced cost and objective sense. If |
---|
57 | movement in the direction which improves the objective is impossible due |
---|
58 | to bounds on the variable, the branching object will move in the other |
---|
59 | direction. If no movement is possible, the method returns NULL. |
---|
60 | |
---|
61 | Only the bounds on this variable are considered when determining if the new |
---|
62 | point is feasible. |
---|
63 | */ |
---|
64 | virtual CbcBranchingObject * preferredNewFeasible() const; |
---|
65 | |
---|
66 | /** \brief Given a valid solution (with reduced costs, etc.), |
---|
67 | return a branching object which would give a new feasible |
---|
68 | point in a bad direction. |
---|
69 | |
---|
70 | As for preferredNewFeasible(), but the preferred branching object will |
---|
71 | force movement in a direction that degrades the objective. |
---|
72 | */ |
---|
73 | virtual CbcBranchingObject * notPreferredNewFeasible() const ; |
---|
74 | |
---|
75 | /** Reset original upper and lower bound values from the solver. |
---|
76 | |
---|
77 | Handy for updating bounds held in this object after bounds held in the |
---|
78 | solver have been tightened. |
---|
79 | */ |
---|
80 | virtual void resetBounds(const OsiSolverInterface * solver); |
---|
81 | |
---|
82 | /** Finds range of interest so value is feasible in range range_ or infeasible |
---|
83 | between hi[range_] and lo[range_+1]. Returns true if feasible. |
---|
84 | */ |
---|
85 | bool findRange(double value) const; |
---|
86 | |
---|
87 | /** Returns floor and ceiling |
---|
88 | */ |
---|
89 | virtual void floorCeiling(double & floorLotsize, double & ceilingLotsize, double value, |
---|
90 | double tolerance) const; |
---|
91 | |
---|
92 | /// Model column number |
---|
93 | inline int modelSequence() const |
---|
94 | {return columnNumber_;} |
---|
95 | |
---|
96 | /** Column number if single column object -1 otherwise, |
---|
97 | so returns >= 0 |
---|
98 | Used by heuristics |
---|
99 | */ |
---|
100 | virtual int columnNumber() const; |
---|
101 | /// Original bounds |
---|
102 | inline double originalLowerBound() const |
---|
103 | { return bound_[0];} |
---|
104 | inline double originalUpperBound() const |
---|
105 | { return bound_[rangeType_*numberRanges_-1];} |
---|
106 | /// Type - 1 points, 2 ranges |
---|
107 | inline int rangeType() const |
---|
108 | { return rangeType_;} |
---|
109 | /// Number of points |
---|
110 | inline int numberRanges() const |
---|
111 | { return numberRanges_;} |
---|
112 | /// Ranges |
---|
113 | inline double * bound() const |
---|
114 | { return bound_;} |
---|
115 | /** \brief Return true if object can take part in normal heuristics |
---|
116 | */ |
---|
117 | virtual bool canDoHeuristics() const |
---|
118 | {return false;} |
---|
119 | |
---|
120 | private: |
---|
121 | /// Just for debug (CBC_PRINT defined in CbcBranchLotsize.cpp) |
---|
122 | void printLotsize(double value,bool condition,int type) const; |
---|
123 | |
---|
124 | private: |
---|
125 | /// data |
---|
126 | |
---|
127 | /// Column number in model |
---|
128 | int columnNumber_; |
---|
129 | /// Type - 1 points, 2 ranges |
---|
130 | int rangeType_; |
---|
131 | /// Number of points |
---|
132 | int numberRanges_; |
---|
133 | // largest gap |
---|
134 | double largestGap_; |
---|
135 | /// Ranges |
---|
136 | double * bound_; |
---|
137 | /// Current range |
---|
138 | mutable int range_; |
---|
139 | }; |
---|
140 | |
---|
141 | |
---|
142 | /** Lotsize branching object |
---|
143 | |
---|
144 | This object can specify a two-way branch on an integer variable. For each |
---|
145 | arm of the branch, the upper and lower bounds on the variable can be |
---|
146 | independently specified. |
---|
147 | |
---|
148 | Variable_ holds the index of the integer variable in the integerVariable_ |
---|
149 | array of the model. |
---|
150 | */ |
---|
151 | |
---|
152 | class CbcLotsizeBranchingObject : public CbcBranchingObject { |
---|
153 | |
---|
154 | public: |
---|
155 | |
---|
156 | /// Default constructor |
---|
157 | CbcLotsizeBranchingObject (); |
---|
158 | |
---|
159 | /** Create a lotsize floor/ceiling branch object |
---|
160 | |
---|
161 | Specifies a simple two-way branch. Let \p value = x*. One arm of the |
---|
162 | branch will be is lb <= x <= valid range below(x*), the other valid range above(x*) <= x <= ub. |
---|
163 | Specify way = -1 to set the object state to perform the down arm first, |
---|
164 | way = 1 for the up arm. |
---|
165 | */ |
---|
166 | CbcLotsizeBranchingObject (CbcModel *model, int variable, |
---|
167 | int way , double value,const CbcLotsize * lotsize) ; |
---|
168 | |
---|
169 | /** Create a degenerate branch object |
---|
170 | |
---|
171 | Specifies a `one-way branch'. Calling branch() for this object will |
---|
172 | always result in lowerValue <= x <= upperValue. Used to fix in valid range |
---|
173 | */ |
---|
174 | |
---|
175 | CbcLotsizeBranchingObject (CbcModel *model, int variable, int way, |
---|
176 | double lowerValue, double upperValue) ; |
---|
177 | |
---|
178 | /// Copy constructor |
---|
179 | CbcLotsizeBranchingObject ( const CbcLotsizeBranchingObject &); |
---|
180 | |
---|
181 | /// Assignment operator |
---|
182 | CbcLotsizeBranchingObject & operator= (const CbcLotsizeBranchingObject& rhs); |
---|
183 | |
---|
184 | /// Clone |
---|
185 | virtual CbcBranchingObject * clone() const; |
---|
186 | |
---|
187 | /// Destructor |
---|
188 | virtual ~CbcLotsizeBranchingObject (); |
---|
189 | |
---|
190 | /** \brief Sets the bounds for the variable according to the current arm |
---|
191 | of the branch and advances the object state to the next arm. |
---|
192 | */ |
---|
193 | virtual double branch(); |
---|
194 | |
---|
195 | /** \brief Print something about branch - only if log level high |
---|
196 | */ |
---|
197 | virtual void print(); |
---|
198 | |
---|
199 | protected: |
---|
200 | /// Lower [0] and upper [1] bounds for the down arm (way_ = -1) |
---|
201 | double down_[2]; |
---|
202 | /// Lower [0] and upper [1] bounds for the up arm (way_ = 1) |
---|
203 | double up_[2]; |
---|
204 | }; |
---|
205 | |
---|
206 | |
---|
207 | #endif |
---|