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(); |
---|
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 | |
---|
116 | private: |
---|
117 | /// Just for debug (CBC_PRINT defined in CbcBranchLotsize.cpp) |
---|
118 | void printLotsize(double value,bool condition,int type) const; |
---|
119 | |
---|
120 | private: |
---|
121 | /// data |
---|
122 | |
---|
123 | /// Column number in model |
---|
124 | int columnNumber_; |
---|
125 | /// Type - 1 points, 2 ranges |
---|
126 | int rangeType_; |
---|
127 | /// Number of points |
---|
128 | int numberRanges_; |
---|
129 | // largest gap |
---|
130 | double largestGap_; |
---|
131 | /// Ranges |
---|
132 | double * bound_; |
---|
133 | /// Current range |
---|
134 | mutable int range_; |
---|
135 | }; |
---|
136 | |
---|
137 | |
---|
138 | /** Lotsize branching object |
---|
139 | |
---|
140 | This object can specify a two-way branch on an integer variable. For each |
---|
141 | arm of the branch, the upper and lower bounds on the variable can be |
---|
142 | independently specified. |
---|
143 | |
---|
144 | Variable_ holds the index of the integer variable in the integerVariable_ |
---|
145 | array of the model. |
---|
146 | */ |
---|
147 | |
---|
148 | class CbcLotsizeBranchingObject : public CbcBranchingObject { |
---|
149 | |
---|
150 | public: |
---|
151 | |
---|
152 | /// Default constructor |
---|
153 | CbcLotsizeBranchingObject (); |
---|
154 | |
---|
155 | /** Create a lotsize floor/ceiling branch object |
---|
156 | |
---|
157 | Specifies a simple two-way branch. Let \p value = x*. One arm of the |
---|
158 | branch will be is lb <= x <= valid range below(x*), the other valid range above(x*) <= x <= ub. |
---|
159 | Specify way = -1 to set the object state to perform the down arm first, |
---|
160 | way = 1 for the up arm. |
---|
161 | */ |
---|
162 | CbcLotsizeBranchingObject (CbcModel *model, int variable, |
---|
163 | int way , double value,const CbcLotsize * lotsize) ; |
---|
164 | |
---|
165 | /** Create a degenerate branch object |
---|
166 | |
---|
167 | Specifies a `one-way branch'. Calling branch() for this object will |
---|
168 | always result in lowerValue <= x <= upperValue. Used to fix in valid range |
---|
169 | */ |
---|
170 | |
---|
171 | CbcLotsizeBranchingObject (CbcModel *model, int variable, int way, |
---|
172 | double lowerValue, double upperValue) ; |
---|
173 | |
---|
174 | /// Copy constructor |
---|
175 | CbcLotsizeBranchingObject ( const CbcLotsizeBranchingObject &); |
---|
176 | |
---|
177 | /// Assignment operator |
---|
178 | CbcLotsizeBranchingObject & operator= (const CbcLotsizeBranchingObject& rhs); |
---|
179 | |
---|
180 | /// Clone |
---|
181 | virtual CbcBranchingObject * clone() const; |
---|
182 | |
---|
183 | /// Destructor |
---|
184 | virtual ~CbcLotsizeBranchingObject (); |
---|
185 | |
---|
186 | /** \brief Sets the bounds for the variable according to the current arm |
---|
187 | of the branch and advances the object state to the next arm. |
---|
188 | */ |
---|
189 | virtual double branch(bool normalBranch=false); |
---|
190 | |
---|
191 | /** \brief Print something about branch - only if log level high |
---|
192 | */ |
---|
193 | virtual void print(bool normalBranch); |
---|
194 | |
---|
195 | protected: |
---|
196 | /// Lower [0] and upper [1] bounds for the down arm (way_ = -1) |
---|
197 | double down_[2]; |
---|
198 | /// Lower [0] and upper [1] bounds for the up arm (way_ = 1) |
---|
199 | double up_[2]; |
---|
200 | }; |
---|
201 | |
---|
202 | |
---|
203 | #endif |
---|