1 | /* $Id: ClpFactorization.hpp 1394 2009-07-09 14:05:23Z forrest $ */ |
---|
2 | // Copyright (C) 2002, International Business Machines |
---|
3 | // Corporation and others. All Rights Reserved. |
---|
4 | #ifndef ClpFactorization_H |
---|
5 | #define ClpFactorization_H |
---|
6 | |
---|
7 | |
---|
8 | #include "CoinPragma.hpp" |
---|
9 | |
---|
10 | #include "CoinFactorization.hpp" |
---|
11 | class ClpMatrixBase; |
---|
12 | class ClpSimplex; |
---|
13 | class ClpNetworkBasis; |
---|
14 | class CoinOtherFactorization; |
---|
15 | #ifndef CLP_MULTIPLE_FACTORIZATIONS |
---|
16 | #define CLP_MULTIPLE_FACTORIZATIONS 4 |
---|
17 | #endif |
---|
18 | #ifdef CLP_MULTIPLE_FACTORIZATIONS |
---|
19 | #include "CoinDenseFactorization.hpp" |
---|
20 | #endif |
---|
21 | |
---|
22 | /** This just implements CoinFactorization when an ClpMatrixBase object |
---|
23 | is passed. If a network then has a dummy CoinFactorization and |
---|
24 | a genuine ClpNetworkBasis object |
---|
25 | */ |
---|
26 | class ClpFactorization |
---|
27 | #ifndef CLP_MULTIPLE_FACTORIZATIONS |
---|
28 | : public CoinFactorization |
---|
29 | #endif |
---|
30 | { |
---|
31 | |
---|
32 | //friend class CoinFactorization; |
---|
33 | |
---|
34 | public: |
---|
35 | /**@name factorization */ |
---|
36 | //@{ |
---|
37 | /** When part of LP - given by basic variables. |
---|
38 | Actually does factorization. |
---|
39 | Arrays passed in have non negative value to say basic. |
---|
40 | If status is okay, basic variables have pivot row - this is only needed |
---|
41 | if increasingRows_ >1. |
---|
42 | Allows scaling |
---|
43 | If status is singular, then basic variables have pivot row |
---|
44 | and ones thrown out have -1 |
---|
45 | returns 0 -okay, -1 singular, -2 too many in basis, -99 memory */ |
---|
46 | int factorize (ClpSimplex * model,int solveType, bool valuesPass); |
---|
47 | //@} |
---|
48 | |
---|
49 | |
---|
50 | /**@name Constructors, destructor */ |
---|
51 | //@{ |
---|
52 | /** Default constructor. */ |
---|
53 | ClpFactorization(); |
---|
54 | /** Destructor */ |
---|
55 | ~ClpFactorization(); |
---|
56 | //@} |
---|
57 | |
---|
58 | /**@name Copy method */ |
---|
59 | //@{ |
---|
60 | /** The copy constructor from an CoinFactorization. */ |
---|
61 | ClpFactorization(const CoinFactorization&); |
---|
62 | /** The copy constructor. */ |
---|
63 | ClpFactorization(const ClpFactorization&,int denseIfSmaller=0); |
---|
64 | #ifdef CLP_MULTIPLE_FACTORIZATIONS |
---|
65 | /** The copy constructor from an CoinOtherFactorization. */ |
---|
66 | ClpFactorization(const CoinOtherFactorization&); |
---|
67 | #endif |
---|
68 | ClpFactorization& operator=(const ClpFactorization&); |
---|
69 | //@} |
---|
70 | |
---|
71 | /* **** below here is so can use networkish basis */ |
---|
72 | /**@name rank one updates which do exist */ |
---|
73 | //@{ |
---|
74 | |
---|
75 | /** Replaces one Column to basis, |
---|
76 | returns 0=OK, 1=Probably OK, 2=singular, 3=no room |
---|
77 | If checkBeforeModifying is true will do all accuracy checks |
---|
78 | before modifying factorization. Whether to set this depends on |
---|
79 | speed considerations. You could just do this on first iteration |
---|
80 | after factorization and thereafter re-factorize |
---|
81 | partial update already in U */ |
---|
82 | int replaceColumn ( const ClpSimplex * model, |
---|
83 | CoinIndexedVector * regionSparse, |
---|
84 | CoinIndexedVector * tableauColumn, |
---|
85 | int pivotRow, |
---|
86 | double pivotCheck , |
---|
87 | bool checkBeforeModifying=false, |
---|
88 | double acceptablePivot=1.0e-8); |
---|
89 | //@} |
---|
90 | |
---|
91 | /**@name various uses of factorization (return code number elements) |
---|
92 | which user may want to know about */ |
---|
93 | //@{ |
---|
94 | /** Updates one column (FTRAN) from region2 |
---|
95 | Tries to do FT update |
---|
96 | number returned is negative if no room |
---|
97 | region1 starts as zero and is zero at end */ |
---|
98 | int updateColumnFT ( CoinIndexedVector * regionSparse, |
---|
99 | CoinIndexedVector * regionSparse2); |
---|
100 | /** Updates one column (FTRAN) from region2 |
---|
101 | region1 starts as zero and is zero at end */ |
---|
102 | int updateColumn ( CoinIndexedVector * regionSparse, |
---|
103 | CoinIndexedVector * regionSparse2, |
---|
104 | bool noPermute=false) const; |
---|
105 | /** Updates one column (FTRAN) from region2 |
---|
106 | Tries to do FT update |
---|
107 | number returned is negative if no room. |
---|
108 | Also updates region3 |
---|
109 | region1 starts as zero and is zero at end */ |
---|
110 | int updateTwoColumnsFT ( CoinIndexedVector * regionSparse1, |
---|
111 | CoinIndexedVector * regionSparse2, |
---|
112 | CoinIndexedVector * regionSparse3, |
---|
113 | bool noPermuteRegion3=false) ; |
---|
114 | /// For debug (no statistics update) |
---|
115 | int updateColumnForDebug ( CoinIndexedVector * regionSparse, |
---|
116 | CoinIndexedVector * regionSparse2, |
---|
117 | bool noPermute=false) const; |
---|
118 | /** Updates one column (BTRAN) from region2 |
---|
119 | region1 starts as zero and is zero at end */ |
---|
120 | int updateColumnTranspose ( CoinIndexedVector * regionSparse, |
---|
121 | CoinIndexedVector * regionSparse2) const; |
---|
122 | //@} |
---|
123 | #ifdef CLP_MULTIPLE_FACTORIZATIONS |
---|
124 | /**@name Lifted from CoinFactorization */ |
---|
125 | //@{ |
---|
126 | /// Total number of elements in factorization |
---|
127 | inline int numberElements ( ) const { |
---|
128 | if (coinFactorizationA_) return coinFactorizationA_->numberElements(); else return coinFactorizationB_->numberElements() ; |
---|
129 | } |
---|
130 | /// Returns address of permute region |
---|
131 | inline int *permute ( ) const { |
---|
132 | if (coinFactorizationA_) return coinFactorizationA_->permute(); else return coinFactorizationB_->permute() ; |
---|
133 | } |
---|
134 | /// Returns address of pivotColumn region (also used for permuting) |
---|
135 | inline int *pivotColumn ( ) const { |
---|
136 | if (coinFactorizationA_) return coinFactorizationA_->pivotColumn(); else return coinFactorizationB_->permute() ; |
---|
137 | } |
---|
138 | /// Maximum number of pivots between factorizations |
---|
139 | inline int maximumPivots ( ) const { |
---|
140 | if (coinFactorizationA_) return coinFactorizationA_->maximumPivots(); else return coinFactorizationB_->maximumPivots() ; |
---|
141 | } |
---|
142 | /// Set maximum number of pivots between factorizations |
---|
143 | inline void maximumPivots ( int value) { |
---|
144 | if (coinFactorizationA_) coinFactorizationA_->maximumPivots(value); else coinFactorizationB_->maximumPivots(value); |
---|
145 | } |
---|
146 | /// Returns number of pivots since factorization |
---|
147 | inline int pivots ( ) const { |
---|
148 | if (coinFactorizationA_) return coinFactorizationA_->pivots(); else return coinFactorizationB_->pivots() ; |
---|
149 | } |
---|
150 | /// Whether larger areas needed |
---|
151 | inline double areaFactor ( ) const { |
---|
152 | if (coinFactorizationA_) return coinFactorizationA_->areaFactor(); else return 0.0 ; |
---|
153 | } |
---|
154 | /// Set whether larger areas needed |
---|
155 | inline void areaFactor ( double value) { |
---|
156 | if (coinFactorizationA_) coinFactorizationA_->areaFactor(value); |
---|
157 | } |
---|
158 | /// Zero tolerance |
---|
159 | inline double zeroTolerance ( ) const { |
---|
160 | if (coinFactorizationA_) return coinFactorizationA_->zeroTolerance(); else return coinFactorizationB_->zeroTolerance() ; |
---|
161 | } |
---|
162 | /// Set zero tolerance |
---|
163 | inline void zeroTolerance ( double value) { |
---|
164 | if (coinFactorizationA_) coinFactorizationA_->zeroTolerance(value); else coinFactorizationB_->zeroTolerance(value); |
---|
165 | } |
---|
166 | /// Set tolerances to safer of existing and given |
---|
167 | void saferTolerances ( double zeroTolerance, double pivotTolerance); |
---|
168 | /** get sparse threshold */ |
---|
169 | inline int sparseThreshold ( ) const |
---|
170 | { if (coinFactorizationA_) return coinFactorizationA_->sparseThreshold(); else return 0 ;} |
---|
171 | /** Set sparse threshold */ |
---|
172 | inline void sparseThreshold ( int value) |
---|
173 | { if (coinFactorizationA_) coinFactorizationA_->sparseThreshold(value); } |
---|
174 | /// Returns status |
---|
175 | inline int status ( ) const { |
---|
176 | if (coinFactorizationA_) return coinFactorizationA_->status(); else return coinFactorizationB_->status() ; |
---|
177 | } |
---|
178 | /// Sets status |
---|
179 | inline void setStatus ( int value) { |
---|
180 | if (coinFactorizationA_) coinFactorizationA_->setStatus(value); else coinFactorizationB_->setStatus(value) ; |
---|
181 | } |
---|
182 | /// Returns number of dense rows |
---|
183 | inline int numberDense() const |
---|
184 | { if (coinFactorizationA_) return coinFactorizationA_->numberDense(); else return 0 ;} |
---|
185 | #if 1 |
---|
186 | /// Returns number in U area |
---|
187 | inline CoinBigIndex numberElementsU ( ) const { |
---|
188 | if (coinFactorizationA_) return coinFactorizationA_->numberElementsU(); else return -1 ; |
---|
189 | } |
---|
190 | /// Returns number in L area |
---|
191 | inline CoinBigIndex numberElementsL ( ) const { |
---|
192 | if (coinFactorizationA_) return coinFactorizationA_->numberElementsL(); else return -1 ; |
---|
193 | } |
---|
194 | /// Returns number in R area |
---|
195 | inline CoinBigIndex numberElementsR ( ) const { |
---|
196 | if (coinFactorizationA_) return coinFactorizationA_->numberElementsR(); else return 0 ; |
---|
197 | } |
---|
198 | #endif |
---|
199 | inline bool timeToRefactorize() const |
---|
200 | { |
---|
201 | if (coinFactorizationA_) { |
---|
202 | return (coinFactorizationA_->pivots()*3>coinFactorizationA_->maximumPivots()*2&& |
---|
203 | coinFactorizationA_->numberElementsR()*3>(coinFactorizationA_->numberElementsL()+ |
---|
204 | coinFactorizationA_->numberElementsU())*2+1000&& |
---|
205 | !coinFactorizationA_->numberDense()); |
---|
206 | } else { |
---|
207 | return coinFactorizationB_->pivots()>coinFactorizationB_->numberRows()/2.45+20; |
---|
208 | } |
---|
209 | } |
---|
210 | /// Level of detail of messages |
---|
211 | inline int messageLevel ( ) const { |
---|
212 | if (coinFactorizationA_) return coinFactorizationA_->messageLevel(); else return 1 ; |
---|
213 | } |
---|
214 | /// Set level of detail of messages |
---|
215 | inline void messageLevel ( int value) { |
---|
216 | if (coinFactorizationA_) coinFactorizationA_->messageLevel(value); |
---|
217 | } |
---|
218 | /// Get rid of all memory |
---|
219 | inline void clearArrays() |
---|
220 | { if (coinFactorizationA_) |
---|
221 | coinFactorizationA_->clearArrays(); |
---|
222 | else if (coinFactorizationB_) |
---|
223 | coinFactorizationB_->clearArrays(); |
---|
224 | } |
---|
225 | /// Number of Rows after factorization |
---|
226 | inline int numberRows ( ) const { |
---|
227 | if (coinFactorizationA_) return coinFactorizationA_->numberRows(); else return coinFactorizationB_->numberRows() ; |
---|
228 | } |
---|
229 | /// Gets dense threshold |
---|
230 | inline int denseThreshold() const |
---|
231 | { if (coinFactorizationA_) return coinFactorizationA_->denseThreshold(); else return 0 ;} |
---|
232 | /// Sets dense threshold |
---|
233 | inline void setDenseThreshold(int value) |
---|
234 | { if (coinFactorizationA_) coinFactorizationA_->setDenseThreshold(value);} |
---|
235 | /// Pivot tolerance |
---|
236 | inline double pivotTolerance ( ) const { |
---|
237 | if (coinFactorizationA_) return coinFactorizationA_->pivotTolerance(); else if (coinFactorizationB_) return coinFactorizationB_->pivotTolerance();return 1.0e-8 ; |
---|
238 | } |
---|
239 | /// Set pivot tolerance |
---|
240 | inline void pivotTolerance ( double value) { |
---|
241 | if (coinFactorizationA_) coinFactorizationA_->pivotTolerance(value); |
---|
242 | else if (coinFactorizationB_) coinFactorizationB_->pivotTolerance(value); |
---|
243 | } |
---|
244 | /// Allows change of pivot accuracy check 1.0 == none >1.0 relaxed |
---|
245 | inline void relaxAccuracyCheck(double value) |
---|
246 | { if (coinFactorizationA_) coinFactorizationA_->relaxAccuracyCheck(value);} |
---|
247 | /** Array persistence flag |
---|
248 | If 0 then as now (delete/new) |
---|
249 | 1 then only do arrays if bigger needed |
---|
250 | 2 as 1 but give a bit extra if bigger needed |
---|
251 | */ |
---|
252 | inline int persistenceFlag() const |
---|
253 | { if (coinFactorizationA_) return coinFactorizationA_->persistenceFlag(); else return 0 ;} |
---|
254 | inline void setPersistenceFlag(int value) |
---|
255 | { if (coinFactorizationA_) coinFactorizationA_->setPersistenceFlag(value);} |
---|
256 | /// Delete all stuff (leaves as after CoinFactorization()) |
---|
257 | inline void almostDestructor() |
---|
258 | { if (coinFactorizationA_) |
---|
259 | coinFactorizationA_->almostDestructor(); |
---|
260 | else if (coinFactorizationB_) |
---|
261 | coinFactorizationB_->clearArrays(); |
---|
262 | } |
---|
263 | /// Returns areaFactor but adjusted for dense |
---|
264 | inline double adjustedAreaFactor() const |
---|
265 | { if (coinFactorizationA_) return coinFactorizationA_->adjustedAreaFactor(); else return 0.0 ; } |
---|
266 | inline void setBiasLU(int value) |
---|
267 | { if (coinFactorizationA_) coinFactorizationA_->setBiasLU(value);} |
---|
268 | /// true if Forrest Tomlin update, false if PFI |
---|
269 | inline void setForrestTomlin(bool value) |
---|
270 | { if (coinFactorizationA_) coinFactorizationA_->setForrestTomlin(value);} |
---|
271 | /// Sets default values |
---|
272 | inline void setDefaultValues() { |
---|
273 | if (coinFactorizationA_) { |
---|
274 | // row activities have negative sign |
---|
275 | #ifndef COIN_FAST_CODE |
---|
276 | coinFactorizationA_->slackValue(-1.0); |
---|
277 | #endif |
---|
278 | coinFactorizationA_->zeroTolerance(1.0e-13); |
---|
279 | } |
---|
280 | } |
---|
281 | /// If nonzero force use of 1,dense 2,small 3,osl |
---|
282 | void forceOtherFactorization(int which); |
---|
283 | /// Get switch to osl if number rows <= this |
---|
284 | inline int goOslThreshold() const |
---|
285 | { return goOslThreshold_;} |
---|
286 | /// Set switch to osl if number rows <= this |
---|
287 | inline void setGoOslThreshold(int value) |
---|
288 | { goOslThreshold_ = value;} |
---|
289 | /// Get switch to dense if number rows <= this |
---|
290 | inline int goDenseThreshold() const |
---|
291 | { return goDenseThreshold_;} |
---|
292 | /// Set switch to dense if number rows <= this |
---|
293 | inline void setGoDenseThreshold(int value) |
---|
294 | { goDenseThreshold_ = value;} |
---|
295 | /// Get switch to small if number rows <= this |
---|
296 | inline int goSmallThreshold() const |
---|
297 | { return goSmallThreshold_;} |
---|
298 | /// Set switch to small if number rows <= this |
---|
299 | inline void setGoSmallThreshold(int value) |
---|
300 | { goSmallThreshold_ = value;} |
---|
301 | /// Go over to dense or small code if small enough |
---|
302 | void goDenseOrSmall(int numberRows) ; |
---|
303 | /// Sets factorization |
---|
304 | void setFactorization(ClpFactorization & factorization); |
---|
305 | /// Return 1 if dense code |
---|
306 | inline int isDenseOrSmall() const |
---|
307 | { return coinFactorizationB_ ? 1 : 0;} |
---|
308 | #else |
---|
309 | inline bool timeToRefactorize() const |
---|
310 | { |
---|
311 | return (pivots()*3>maximumPivots()*2&& |
---|
312 | numberElementsR()*3>(numberElementsL()+numberElementsU())*2+1000&& |
---|
313 | !numberDense()); |
---|
314 | } |
---|
315 | /// Sets default values |
---|
316 | inline void setDefaultValues() { |
---|
317 | // row activities have negative sign |
---|
318 | #ifndef COIN_FAST_CODE |
---|
319 | slackValue(-1.0); |
---|
320 | #endif |
---|
321 | zeroTolerance(1.0e-13); |
---|
322 | } |
---|
323 | /// Go over to dense code |
---|
324 | inline void goDense() {} |
---|
325 | #endif |
---|
326 | //@} |
---|
327 | |
---|
328 | /**@name other stuff */ |
---|
329 | //@{ |
---|
330 | /** makes a row copy of L for speed and to allow very sparse problems */ |
---|
331 | void goSparse(); |
---|
332 | /// Cleans up i.e. gets rid of network basis |
---|
333 | void cleanUp(); |
---|
334 | /// Says whether to redo pivot order |
---|
335 | bool needToReorder() const; |
---|
336 | #ifndef SLIM_CLP |
---|
337 | /// Says if a network basis |
---|
338 | inline bool networkBasis() const |
---|
339 | { return (networkBasis_!=NULL);} |
---|
340 | #else |
---|
341 | /// Says if a network basis |
---|
342 | inline bool networkBasis() const |
---|
343 | { return false;} |
---|
344 | #endif |
---|
345 | /// Fills weighted row list |
---|
346 | void getWeights(int * weights) const; |
---|
347 | //@} |
---|
348 | |
---|
349 | ////////////////// data ////////////////// |
---|
350 | private: |
---|
351 | |
---|
352 | /**@name data */ |
---|
353 | //@{ |
---|
354 | /// Pointer to network basis |
---|
355 | #ifndef SLIM_CLP |
---|
356 | ClpNetworkBasis * networkBasis_; |
---|
357 | #endif |
---|
358 | #ifdef CLP_MULTIPLE_FACTORIZATIONS |
---|
359 | /// Pointer to CoinFactorization |
---|
360 | CoinFactorization * coinFactorizationA_; |
---|
361 | /// Pointer to CoinOtherFactorization |
---|
362 | CoinOtherFactorization * coinFactorizationB_; |
---|
363 | /// If nonzero force use of 1,dense 2,small 3,osl |
---|
364 | int forceB_; |
---|
365 | /// Switch to osl if number rows <= this |
---|
366 | int goOslThreshold_; |
---|
367 | /// Switch to small if number rows <= this |
---|
368 | int goSmallThreshold_; |
---|
369 | /// Switch to dense if number rows <= this |
---|
370 | int goDenseThreshold_; |
---|
371 | #endif |
---|
372 | //@} |
---|
373 | }; |
---|
374 | |
---|
375 | #endif |
---|