1 | /* $Id: ClpGubDynamicMatrix.hpp 2385 2019-01-06 19:43:06Z forrest $ */ |
---|
2 | // Copyright (C) 2003, 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 ClpGubDynamicMatrix_H |
---|
7 | #define ClpGubDynamicMatrix_H |
---|
8 | |
---|
9 | #include "CoinPragma.hpp" |
---|
10 | |
---|
11 | #include "ClpGubMatrix.hpp" |
---|
12 | /** This implements Gub rows plus a ClpPackedMatrix. |
---|
13 | This a dynamic version which stores the gub part and dynamically creates matrix. |
---|
14 | All bounds are assumed to be zero and infinity |
---|
15 | |
---|
16 | This is just a simple example for real column generation |
---|
17 | */ |
---|
18 | |
---|
19 | class ClpGubDynamicMatrix : public ClpGubMatrix { |
---|
20 | |
---|
21 | public: |
---|
22 | /**@name Main functions provided */ |
---|
23 | //@{ |
---|
24 | /// Partial pricing |
---|
25 | virtual void partialPricing(ClpSimplex *model, double start, double end, |
---|
26 | int &bestSequence, int &numberWanted); |
---|
27 | /** This is local to Gub to allow synchronization: |
---|
28 | mode=0 when status of basis is good |
---|
29 | mode=1 when variable is flagged |
---|
30 | mode=2 when all variables unflagged (returns number flagged) |
---|
31 | mode=3 just reset costs (primal) |
---|
32 | mode=4 correct number of dual infeasibilities |
---|
33 | mode=5 return 4 if time to re-factorize |
---|
34 | mode=8 - make sure set is clean |
---|
35 | mode=9 - adjust lower, upper on set by incoming |
---|
36 | */ |
---|
37 | virtual int synchronize(ClpSimplex *model, int mode); |
---|
38 | /// Sets up an effective RHS and does gub crash if needed |
---|
39 | virtual void useEffectiveRhs(ClpSimplex *model, bool cheapest = true); |
---|
40 | /** |
---|
41 | update information for a pivot (and effective rhs) |
---|
42 | */ |
---|
43 | virtual int updatePivot(ClpSimplex *model, double oldInValue, double oldOutValue); |
---|
44 | /// Add a new variable to a set |
---|
45 | void insertNonBasic(int sequence, int iSet); |
---|
46 | /** Returns effective RHS offset if it is being used. This is used for long problems |
---|
47 | or big gub or anywhere where going through full columns is |
---|
48 | expensive. This may re-compute */ |
---|
49 | virtual double *rhsOffset(ClpSimplex *model, bool forceRefresh = false, |
---|
50 | bool check = false); |
---|
51 | |
---|
52 | using ClpPackedMatrix::times; |
---|
53 | /** Return <code>y + A * scalar *x</code> in <code>y</code>. |
---|
54 | @pre <code>x</code> must be of size <code>numColumns()</code> |
---|
55 | @pre <code>y</code> must be of size <code>numRows()</code> */ |
---|
56 | virtual void times(double scalar, |
---|
57 | const double *x, double *y) const; |
---|
58 | /** Just for debug |
---|
59 | Returns sum and number of primal infeasibilities. Recomputes keys |
---|
60 | */ |
---|
61 | virtual int checkFeasible(ClpSimplex *model, double &sum) const; |
---|
62 | /// Cleans data after setWarmStart |
---|
63 | void cleanData(ClpSimplex *model); |
---|
64 | //@} |
---|
65 | |
---|
66 | /**@name Constructors, destructor */ |
---|
67 | //@{ |
---|
68 | /** Default constructor. */ |
---|
69 | ClpGubDynamicMatrix(); |
---|
70 | /** Destructor */ |
---|
71 | virtual ~ClpGubDynamicMatrix(); |
---|
72 | //@} |
---|
73 | |
---|
74 | /**@name Copy method */ |
---|
75 | //@{ |
---|
76 | /** The copy constructor. */ |
---|
77 | ClpGubDynamicMatrix(const ClpGubDynamicMatrix &); |
---|
78 | /** This is the real constructor. |
---|
79 | It assumes factorization frequency will not be changed. |
---|
80 | This resizes model !!!! |
---|
81 | */ |
---|
82 | ClpGubDynamicMatrix(ClpSimplex *model, int numberSets, |
---|
83 | int numberColumns, const int *starts, |
---|
84 | const double *lower, const double *upper, |
---|
85 | const CoinBigIndex *startColumn, const int *row, |
---|
86 | const double *element, const double *cost, |
---|
87 | const double *lowerColumn = NULL, const double *upperColumn = NULL, |
---|
88 | const unsigned char *status = NULL); |
---|
89 | |
---|
90 | ClpGubDynamicMatrix &operator=(const ClpGubDynamicMatrix &); |
---|
91 | /// Clone |
---|
92 | virtual ClpMatrixBase *clone() const; |
---|
93 | //@} |
---|
94 | /**@name gets and sets */ |
---|
95 | //@{ |
---|
96 | /// enums for status of various sorts |
---|
97 | enum DynamicStatus { |
---|
98 | inSmall = 0x01, |
---|
99 | atUpperBound = 0x02, |
---|
100 | atLowerBound = 0x03 |
---|
101 | }; |
---|
102 | /// Whether flagged |
---|
103 | inline bool flagged(int i) const |
---|
104 | { |
---|
105 | return (dynamicStatus_[i] & 8) != 0; |
---|
106 | } |
---|
107 | inline void setFlagged(int i) |
---|
108 | { |
---|
109 | dynamicStatus_[i] = static_cast< unsigned char >(dynamicStatus_[i] | 8); |
---|
110 | } |
---|
111 | inline void unsetFlagged(int i) |
---|
112 | { |
---|
113 | dynamicStatus_[i] = static_cast< unsigned char >(dynamicStatus_[i] & ~8); |
---|
114 | } |
---|
115 | inline void setDynamicStatus(int sequence, DynamicStatus status) |
---|
116 | { |
---|
117 | unsigned char &st_byte = dynamicStatus_[sequence]; |
---|
118 | st_byte = static_cast< unsigned char >(st_byte & ~7); |
---|
119 | st_byte = static_cast< unsigned char >(st_byte | status); |
---|
120 | } |
---|
121 | inline DynamicStatus getDynamicStatus(int sequence) const |
---|
122 | { |
---|
123 | return static_cast< DynamicStatus >(dynamicStatus_[sequence] & 7); |
---|
124 | } |
---|
125 | /// Saved value of objective offset |
---|
126 | inline double objectiveOffset() const |
---|
127 | { |
---|
128 | return objectiveOffset_; |
---|
129 | } |
---|
130 | /// Starts of each column |
---|
131 | inline CoinBigIndex *startColumn() const |
---|
132 | { |
---|
133 | return startColumn_; |
---|
134 | } |
---|
135 | /// rows |
---|
136 | inline int *row() const |
---|
137 | { |
---|
138 | return row_; |
---|
139 | } |
---|
140 | /// elements |
---|
141 | inline double *element() const |
---|
142 | { |
---|
143 | return element_; |
---|
144 | } |
---|
145 | /// costs |
---|
146 | inline double *cost() const |
---|
147 | { |
---|
148 | return cost_; |
---|
149 | } |
---|
150 | /// full starts |
---|
151 | inline int *fullStart() const |
---|
152 | { |
---|
153 | return fullStart_; |
---|
154 | } |
---|
155 | /// ids of active columns (just index here) |
---|
156 | inline int *id() const |
---|
157 | { |
---|
158 | return id_; |
---|
159 | } |
---|
160 | /// Optional lower bounds on columns |
---|
161 | inline double *lowerColumn() const |
---|
162 | { |
---|
163 | return lowerColumn_; |
---|
164 | } |
---|
165 | /// Optional upper bounds on columns |
---|
166 | inline double *upperColumn() const |
---|
167 | { |
---|
168 | return upperColumn_; |
---|
169 | } |
---|
170 | /// Optional true lower bounds on sets |
---|
171 | inline double *lowerSet() const |
---|
172 | { |
---|
173 | return lowerSet_; |
---|
174 | } |
---|
175 | /// Optional true upper bounds on sets |
---|
176 | inline double *upperSet() const |
---|
177 | { |
---|
178 | return upperSet_; |
---|
179 | } |
---|
180 | /// size |
---|
181 | inline int numberGubColumns() const |
---|
182 | { |
---|
183 | return numberGubColumns_; |
---|
184 | } |
---|
185 | /// first free |
---|
186 | inline int firstAvailable() const |
---|
187 | { |
---|
188 | return firstAvailable_; |
---|
189 | } |
---|
190 | /// set first free |
---|
191 | inline void setFirstAvailable(int value) |
---|
192 | { |
---|
193 | firstAvailable_ = value; |
---|
194 | } |
---|
195 | /// first dynamic |
---|
196 | inline int firstDynamic() const |
---|
197 | { |
---|
198 | return firstDynamic_; |
---|
199 | } |
---|
200 | /// number of columns in dynamic model |
---|
201 | inline int lastDynamic() const |
---|
202 | { |
---|
203 | return lastDynamic_; |
---|
204 | } |
---|
205 | /// size of working matrix (max) |
---|
206 | inline CoinBigIndex numberElements() const |
---|
207 | { |
---|
208 | return numberElements_; |
---|
209 | } |
---|
210 | /// Status region for gub slacks |
---|
211 | inline unsigned char *gubRowStatus() const |
---|
212 | { |
---|
213 | return status_; |
---|
214 | } |
---|
215 | /// Status region for gub variables |
---|
216 | inline unsigned char *dynamicStatus() const |
---|
217 | { |
---|
218 | return dynamicStatus_; |
---|
219 | } |
---|
220 | /// Returns which set a variable is in |
---|
221 | int whichSet(int sequence) const; |
---|
222 | //@} |
---|
223 | |
---|
224 | protected: |
---|
225 | /**@name Data members |
---|
226 | The data members are protected to allow access for derived classes. */ |
---|
227 | //@{ |
---|
228 | /// Saved value of objective offset |
---|
229 | double objectiveOffset_; |
---|
230 | /// Starts of each column |
---|
231 | CoinBigIndex *startColumn_; |
---|
232 | /// rows |
---|
233 | int *row_; |
---|
234 | /// elements |
---|
235 | double *element_; |
---|
236 | /// costs |
---|
237 | double *cost_; |
---|
238 | /// full starts |
---|
239 | int *fullStart_; |
---|
240 | /// ids of active columns (just index here) |
---|
241 | int *id_; |
---|
242 | /// for status and which bound |
---|
243 | unsigned char *dynamicStatus_; |
---|
244 | /// Optional lower bounds on columns |
---|
245 | double *lowerColumn_; |
---|
246 | /// Optional upper bounds on columns |
---|
247 | double *upperColumn_; |
---|
248 | /// Optional true lower bounds on sets |
---|
249 | double *lowerSet_; |
---|
250 | /// Optional true upper bounds on sets |
---|
251 | double *upperSet_; |
---|
252 | /// size |
---|
253 | int numberGubColumns_; |
---|
254 | /// first free |
---|
255 | int firstAvailable_; |
---|
256 | /// saved first free |
---|
257 | int savedFirstAvailable_; |
---|
258 | /// first dynamic |
---|
259 | int firstDynamic_; |
---|
260 | /// number of columns in dynamic model |
---|
261 | int lastDynamic_; |
---|
262 | /// size of working matrix (max) |
---|
263 | CoinBigIndex numberElements_; |
---|
264 | //@} |
---|
265 | }; |
---|
266 | |
---|
267 | #endif |
---|
268 | |
---|
269 | /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2 |
---|
270 | */ |
---|