Clp  1.16.11
ClpFactorization.hpp
Go to the documentation of this file.
1 /* $Id: ClpFactorization.hpp 2078 2015-01-05 12:39:49Z forrest $ */
2 // Copyright (C) 2002, 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 ClpFactorization_H
7 #define ClpFactorization_H
8 
9 
10 #include "CoinPragma.hpp"
11 
12 #include "CoinFactorization.hpp"
13 class ClpMatrixBase;
14 class ClpSimplex;
15 class ClpNetworkBasis;
16 class CoinOtherFactorization;
17 #ifndef CLP_MULTIPLE_FACTORIZATIONS
18 #define CLP_MULTIPLE_FACTORIZATIONS 4
19 #endif
20 #ifdef CLP_MULTIPLE_FACTORIZATIONS
21 #include "CoinDenseFactorization.hpp"
22 #include "ClpSimplex.hpp"
23 #endif
24 #ifndef COIN_FAST_CODE
25 #define COIN_FAST_CODE
26 #endif
27 #ifndef CLP_FACTORIZATION_NEW_TIMING
28 #define CLP_FACTORIZATION_NEW_TIMING 1
29 #endif
30 
37  : public CoinFactorization
38 #endif
39 {
40 
41  //friend class CoinFactorization;
42 
43 public:
55  int factorize (ClpSimplex * model, int solveType, bool valuesPass);
57 
58 
66 
70  ClpFactorization(const CoinFactorization&);
72  ClpFactorization(const ClpFactorization&, int denseIfSmaller = 0);
73 #ifdef CLP_MULTIPLE_FACTORIZATIONS
74 
75  ClpFactorization(const CoinOtherFactorization&);
76 #endif
79 
80  /* **** below here is so can use networkish basis */
83 
91  int replaceColumn ( const ClpSimplex * model,
92  CoinIndexedVector * regionSparse,
93  CoinIndexedVector * tableauColumn,
94  int pivotRow,
95  double pivotCheck ,
96  bool checkBeforeModifying = false,
97  double acceptablePivot = 1.0e-8);
99 
107  int updateColumnFT ( CoinIndexedVector * regionSparse,
108  CoinIndexedVector * regionSparse2);
111  int updateColumn ( CoinIndexedVector * regionSparse,
112  CoinIndexedVector * regionSparse2,
113  bool noPermute = false) const;
119  int updateTwoColumnsFT ( CoinIndexedVector * regionSparse1,
120  CoinIndexedVector * regionSparse2,
121  CoinIndexedVector * regionSparse3,
122  bool noPermuteRegion3 = false) ;
124  int updateColumnForDebug ( CoinIndexedVector * regionSparse,
125  CoinIndexedVector * regionSparse2,
126  bool noPermute = false) const;
129  int updateColumnTranspose ( CoinIndexedVector * regionSparse,
130  CoinIndexedVector * regionSparse2) const;
132 #ifdef CLP_MULTIPLE_FACTORIZATIONS
133 
135  inline int numberElements ( ) const {
137  if (coinFactorizationA_) return coinFactorizationA_->numberElements();
138  else return coinFactorizationB_->numberElements() ;
139  }
141  inline int *permute ( ) const {
142  if (coinFactorizationA_) return coinFactorizationA_->permute();
143  else return coinFactorizationB_->permute() ;
144  }
146  inline int *pivotColumn ( ) const {
147  if (coinFactorizationA_) return coinFactorizationA_->pivotColumn();
148  else return coinFactorizationB_->permute() ;
149  }
151  inline int maximumPivots ( ) const {
152  if (coinFactorizationA_) return coinFactorizationA_->maximumPivots();
153  else return coinFactorizationB_->maximumPivots() ;
154  }
156  inline void maximumPivots ( int value) {
157  if (coinFactorizationA_) coinFactorizationA_->maximumPivots(value);
158  else coinFactorizationB_->maximumPivots(value);
159  }
161  inline int pivots ( ) const {
162  if (coinFactorizationA_) return coinFactorizationA_->pivots();
163  else return coinFactorizationB_->pivots() ;
164  }
166  inline double areaFactor ( ) const {
167  if (coinFactorizationA_) return coinFactorizationA_->areaFactor();
168  else return 0.0 ;
169  }
171  inline void areaFactor ( double value) {
172  if (coinFactorizationA_) coinFactorizationA_->areaFactor(value);
173  }
175  inline double zeroTolerance ( ) const {
176  if (coinFactorizationA_) return coinFactorizationA_->zeroTolerance();
177  else return coinFactorizationB_->zeroTolerance() ;
178  }
180  inline void zeroTolerance ( double value) {
181  if (coinFactorizationA_) coinFactorizationA_->zeroTolerance(value);
182  else coinFactorizationB_->zeroTolerance(value);
183  }
187  inline int sparseThreshold ( ) const {
188  if (coinFactorizationA_) return coinFactorizationA_->sparseThreshold();
189  else return 0 ;
190  }
192  inline void sparseThreshold ( int value) {
193  if (coinFactorizationA_) coinFactorizationA_->sparseThreshold(value);
194  }
196  inline int status ( ) const {
197  if (coinFactorizationA_) return coinFactorizationA_->status();
198  else return coinFactorizationB_->status() ;
199  }
201  inline void setStatus ( int value) {
202  if (coinFactorizationA_) coinFactorizationA_->setStatus(value);
203  else coinFactorizationB_->setStatus(value) ;
204  }
206  inline int numberDense() const {
207  if (coinFactorizationA_) return coinFactorizationA_->numberDense();
208  else return 0 ;
209  }
210 #if 1
211  inline CoinBigIndex numberElementsU ( ) const {
213  if (coinFactorizationA_) return coinFactorizationA_->numberElementsU();
214  else return -1 ;
215  }
217  inline CoinBigIndex numberElementsL ( ) const {
218  if (coinFactorizationA_) return coinFactorizationA_->numberElementsL();
219  else return -1 ;
220  }
222  inline CoinBigIndex numberElementsR ( ) const {
223  if (coinFactorizationA_) return coinFactorizationA_->numberElementsR();
224  else return 0 ;
225  }
226 #endif
227  bool timeToRefactorize() const;
228 #if CLP_FACTORIZATION_NEW_TIMING>1
229  void statsRefactor(char when) const;
230 #endif
231  inline int messageLevel ( ) const {
233  if (coinFactorizationA_) return coinFactorizationA_->messageLevel();
234  else return 1 ;
235  }
237  inline void messageLevel ( int value) {
238  if (coinFactorizationA_) coinFactorizationA_->messageLevel(value);
239  }
241  inline void clearArrays() {
242  if (coinFactorizationA_)
243  coinFactorizationA_->clearArrays();
244  else if (coinFactorizationB_)
245  coinFactorizationB_->clearArrays();
246  }
248  inline int numberRows ( ) const {
249  if (coinFactorizationA_) return coinFactorizationA_->numberRows();
250  else return coinFactorizationB_->numberRows() ;
251  }
253  inline int denseThreshold() const {
254  if (coinFactorizationA_) return coinFactorizationA_->denseThreshold();
255  else return 0 ;
256  }
258  inline void setDenseThreshold(int value) {
259  if (coinFactorizationA_) coinFactorizationA_->setDenseThreshold(value);
260  }
262  inline double pivotTolerance ( ) const {
263  if (coinFactorizationA_) return coinFactorizationA_->pivotTolerance();
264  else if (coinFactorizationB_) return coinFactorizationB_->pivotTolerance();
265  return 1.0e-8 ;
266  }
268  inline void pivotTolerance ( double value) {
269  if (coinFactorizationA_) coinFactorizationA_->pivotTolerance(value);
270  else if (coinFactorizationB_) coinFactorizationB_->pivotTolerance(value);
271  }
273  inline void relaxAccuracyCheck(double value) {
274  if (coinFactorizationA_) coinFactorizationA_->relaxAccuracyCheck(value);
275  }
281  inline int persistenceFlag() const {
282  if (coinFactorizationA_) return coinFactorizationA_->persistenceFlag();
283  else return 0 ;
284  }
285  inline void setPersistenceFlag(int value) {
286  if (coinFactorizationA_) coinFactorizationA_->setPersistenceFlag(value);
287  }
289  inline void almostDestructor() {
290  if (coinFactorizationA_)
291  coinFactorizationA_->almostDestructor();
292  else if (coinFactorizationB_)
293  coinFactorizationB_->clearArrays();
294  }
296  inline double adjustedAreaFactor() const {
297  if (coinFactorizationA_) return coinFactorizationA_->adjustedAreaFactor();
298  else return 0.0 ;
299  }
300  inline void setBiasLU(int value) {
301  if (coinFactorizationA_) coinFactorizationA_->setBiasLU(value);
302  }
304  inline void setForrestTomlin(bool value) {
305  if (coinFactorizationA_) coinFactorizationA_->setForrestTomlin(value);
306  }
308  inline void setDefaultValues() {
309  if (coinFactorizationA_) {
310  // row activities have negative sign
311 #ifndef COIN_FAST_CODE
312  coinFactorizationA_->slackValue(-1.0);
313 #endif
314  coinFactorizationA_->zeroTolerance(1.0e-13);
315  }
316  }
318  void forceOtherFactorization(int which);
320  inline int goOslThreshold() const {
321  return goOslThreshold_;
322  }
324  inline void setGoOslThreshold(int value) {
325  goOslThreshold_ = value;
326  }
328  inline int goDenseThreshold() const {
329  return goDenseThreshold_;
330  }
332  inline void setGoDenseThreshold(int value) {
333  goDenseThreshold_ = value;
334  }
336  inline int goSmallThreshold() const {
337  return goSmallThreshold_;
338  }
340  inline void setGoSmallThreshold(int value) {
341  goSmallThreshold_ = value;
342  }
346  void setFactorization(ClpFactorization & factorization);
348  inline int isDenseOrSmall() const {
349  return coinFactorizationB_ ? 1 : 0;
350  }
351 #else
352  inline bool timeToRefactorize() const {
353  return (pivots() * 3 > maximumPivots() * 2 &&
354  numberElementsR() * 3 > (numberElementsL() + numberElementsU()) * 2 + 1000 &&
355  !numberDense());
356  }
358  inline void setDefaultValues() {
359  // row activities have negative sign
360 #ifndef COIN_FAST_CODE
361  slackValue(-1.0);
362 #endif
363  zeroTolerance(1.0e-13);
364  }
366  inline void goDense() {}
367 #endif
368 
369 
373  void goSparse();
375  void cleanUp();
377  bool needToReorder() const;
378 #ifndef SLIM_CLP
379  inline bool networkBasis() const {
381  return (networkBasis_ != NULL);
382  }
383 #else
384  inline bool networkBasis() const {
386  return false;
387  }
388 #endif
389  void getWeights(int * weights) const;
392 
394 private:
395 
398 #ifndef SLIM_CLP
400  ClpNetworkBasis * networkBasis_;
401 #endif
402 #ifdef CLP_MULTIPLE_FACTORIZATIONS
403  CoinFactorization * coinFactorizationA_;
406  CoinOtherFactorization * coinFactorizationB_;
407 #ifdef CLP_REUSE_ETAS
408  ClpSimplex * model_;
410 #endif
411  int forceB_;
414  int goOslThreshold_;
416  int goSmallThreshold_;
418  int goDenseThreshold_;
419 #endif
420 #ifdef CLP_FACTORIZATION_NEW_TIMING
421  mutable double shortestAverage_;
423  mutable double totalInR_;
424  mutable double totalInIncreasingU_;
425  mutable int endLengthU_;
426  mutable int lastNumberPivots_;
427  mutable int effectiveStartNumberU_;
428 #endif
429 
430 };
431 
432 #endif
ClpFactorization::factorize
int factorize(ClpSimplex *model, int solveType, bool valuesPass)
When part of LP - given by basic variables.
ClpSimplex
This solves LPs using the simplex method.
Definition: ClpSimplex.hpp:70
ClpFactorization::messageLevel
int messageLevel() const
Level of detail of messages.
Definition: ClpFactorization.hpp:232
ClpFactorization
This just implements CoinFactorization when an ClpMatrixBase object is passed.
Definition: ClpFactorization.hpp:39
ClpFactorization::forceOtherFactorization
void forceOtherFactorization(int which)
If nonzero force use of 1,dense 2,small 3,osl.
ClpFactorization::setFactorization
void setFactorization(ClpFactorization &factorization)
Sets factorization.
ClpFactorization::goSmallThreshold
int goSmallThreshold() const
Get switch to small if number rows <= this.
Definition: ClpFactorization.hpp:336
ClpFactorization::setForrestTomlin
void setForrestTomlin(bool value)
true if Forrest Tomlin update, false if PFI
Definition: ClpFactorization.hpp:304
ClpFactorization::ClpFactorization
ClpFactorization(const ClpFactorization &, int denseIfSmaller=0)
The copy constructor.
ClpFactorization::numberElementsR
CoinBigIndex numberElementsR() const
Returns number in R area.
Definition: ClpFactorization.hpp:222
ClpFactorization::setDefaultValues
void setDefaultValues()
Sets default values.
Definition: ClpFactorization.hpp:308
ClpFactorization::updateTwoColumnsFT
int updateTwoColumnsFT(CoinIndexedVector *regionSparse1, CoinIndexedVector *regionSparse2, CoinIndexedVector *regionSparse3, bool noPermuteRegion3=false)
Updates one column (FTRAN) from region2 Tries to do FT update number returned is negative if no room.
ClpFactorization::setDenseThreshold
void setDenseThreshold(int value)
Sets dense threshold.
Definition: ClpFactorization.hpp:258
ClpFactorization::maximumPivots
void maximumPivots(int value)
Set maximum number of pivots between factorizations.
Definition: ClpFactorization.hpp:156
ClpFactorization::goDenseThreshold
int goDenseThreshold() const
Get switch to dense if number rows <= this.
Definition: ClpFactorization.hpp:328
ClpFactorization::almostDestructor
void almostDestructor()
Delete all stuff (leaves as after CoinFactorization())
Definition: ClpFactorization.hpp:289
ClpFactorization::setBiasLU
void setBiasLU(int value)
Definition: ClpFactorization.hpp:300
ClpFactorization::numberDense
int numberDense() const
Returns number of dense rows.
Definition: ClpFactorization.hpp:206
ClpFactorization::ClpFactorization
ClpFactorization(const CoinFactorization &)
The copy constructor from an CoinFactorization.
ClpFactorization::relaxAccuracyCheck
void relaxAccuracyCheck(double value)
Allows change of pivot accuracy check 1.0 == none >1.0 relaxed.
Definition: ClpFactorization.hpp:273
ClpFactorization::saferTolerances
void saferTolerances(double zeroTolerance, double pivotTolerance)
Set tolerances to safer of existing and given.
ClpFactorization::goOslThreshold
int goOslThreshold() const
Get switch to osl if number rows <= this.
Definition: ClpFactorization.hpp:320
ClpFactorization::getWeights
void getWeights(int *weights) const
Fills weighted row list.
ClpFactorization::zeroTolerance
void zeroTolerance(double value)
Set zero tolerance.
Definition: ClpFactorization.hpp:180
ClpFactorization::setGoDenseThreshold
void setGoDenseThreshold(int value)
Set switch to dense if number rows <= this.
Definition: ClpFactorization.hpp:332
ClpFactorization::numberElementsL
CoinBigIndex numberElementsL() const
Returns number in L area.
Definition: ClpFactorization.hpp:217
ClpFactorization::goDenseOrSmall
void goDenseOrSmall(int numberRows)
Go over to dense or small code if small enough.
ClpFactorization::pivots
int pivots() const
Returns number of pivots since factorization.
Definition: ClpFactorization.hpp:161
ClpFactorization::~ClpFactorization
~ClpFactorization()
Destructor.
ClpFactorization::networkBasis
bool networkBasis() const
Says if a network basis.
Definition: ClpFactorization.hpp:380
ClpNetworkBasis
This deals with Factorization and Updates for network structures.
Definition: ClpNetworkBasis.hpp:26
ClpFactorization::cleanUp
void cleanUp()
Cleans up i.e. gets rid of network basis.
ClpFactorization::needToReorder
bool needToReorder() const
Says whether to redo pivot order.
ClpFactorization::numberElementsU
CoinBigIndex numberElementsU() const
Returns number in U area.
Definition: ClpFactorization.hpp:212
ClpFactorization::messageLevel
void messageLevel(int value)
Set level of detail of messages.
Definition: ClpFactorization.hpp:237
ClpMatrixBase
Abstract base class for Clp Matrices.
Definition: ClpMatrixBase.hpp:38
ClpFactorization::replaceColumn
int replaceColumn(const ClpSimplex *model, CoinIndexedVector *regionSparse, CoinIndexedVector *tableauColumn, int pivotRow, double pivotCheck, bool checkBeforeModifying=false, double acceptablePivot=1.0e-8)
Replaces one Column to basis, returns 0=OK, 1=Probably OK, 2=singular, 3=no room If checkBeforeModify...
ClpSimplex.hpp
ClpFactorization::maximumPivots
int maximumPivots() const
Maximum number of pivots between factorizations.
Definition: ClpFactorization.hpp:151
ClpFactorization::adjustedAreaFactor
double adjustedAreaFactor() const
Returns areaFactor but adjusted for dense.
Definition: ClpFactorization.hpp:296
ClpFactorization::numberRows
int numberRows() const
Number of Rows after factorization.
Definition: ClpFactorization.hpp:248
ClpFactorization::areaFactor
double areaFactor() const
Whether larger areas needed.
Definition: ClpFactorization.hpp:166
ClpFactorization::updateColumnForDebug
int updateColumnForDebug(CoinIndexedVector *regionSparse, CoinIndexedVector *regionSparse2, bool noPermute=false) const
For debug (no statistics update)
ClpFactorization::operator=
ClpFactorization & operator=(const ClpFactorization &)
ClpFactorization::pivotColumn
int * pivotColumn() const
Returns address of pivotColumn region (also used for permuting)
Definition: ClpFactorization.hpp:146
ClpFactorization::setPersistenceFlag
void setPersistenceFlag(int value)
Definition: ClpFactorization.hpp:285
ClpFactorization::updateColumnTranspose
int updateColumnTranspose(CoinIndexedVector *regionSparse, CoinIndexedVector *regionSparse2) const
Updates one column (BTRAN) from region2 region1 starts as zero and is zero at end.
ClpFactorization::status
int status() const
Returns status.
Definition: ClpFactorization.hpp:196
ClpFactorization::numberElements
int numberElements() const
Total number of elements in factorization.
Definition: ClpFactorization.hpp:136
CLP_MULTIPLE_FACTORIZATIONS
#define CLP_MULTIPLE_FACTORIZATIONS
Definition: ClpFactorization.hpp:18
ClpFactorization::ClpFactorization
ClpFactorization(const CoinOtherFactorization &)
The copy constructor from an CoinOtherFactorization.
ClpFactorization::clearArrays
void clearArrays()
Get rid of all memory.
Definition: ClpFactorization.hpp:241
ClpFactorization::ClpFactorization
ClpFactorization()
Default constructor.
ClpFactorization::setGoOslThreshold
void setGoOslThreshold(int value)
Set switch to osl if number rows <= this.
Definition: ClpFactorization.hpp:324
ClpFactorization::setGoSmallThreshold
void setGoSmallThreshold(int value)
Set switch to small if number rows <= this.
Definition: ClpFactorization.hpp:340
ClpFactorization::areaFactor
void areaFactor(double value)
Set whether larger areas needed.
Definition: ClpFactorization.hpp:171
ClpFactorization::denseThreshold
int denseThreshold() const
Gets dense threshold.
Definition: ClpFactorization.hpp:253
ClpFactorization::setStatus
void setStatus(int value)
Sets status.
Definition: ClpFactorization.hpp:201
ClpFactorization::goSparse
void goSparse()
makes a row copy of L for speed and to allow very sparse problems
ClpFactorization::sparseThreshold
int sparseThreshold() const
get sparse threshold
Definition: ClpFactorization.hpp:187
ClpFactorization::timeToRefactorize
bool timeToRefactorize() const
ClpFactorization::updateColumn
int updateColumn(CoinIndexedVector *regionSparse, CoinIndexedVector *regionSparse2, bool noPermute=false) const
Updates one column (FTRAN) from region2 region1 starts as zero and is zero at end.
ClpFactorization::isDenseOrSmall
int isDenseOrSmall() const
Return 1 if dense code.
Definition: ClpFactorization.hpp:348
ClpFactorization::persistenceFlag
int persistenceFlag() const
Array persistence flag If 0 then as now (delete/new) 1 then only do arrays if bigger needed 2 as 1 bu...
Definition: ClpFactorization.hpp:281
ClpFactorization::updateColumnFT
int updateColumnFT(CoinIndexedVector *regionSparse, CoinIndexedVector *regionSparse2)
Updates one column (FTRAN) from region2 Tries to do FT update number returned is negative if no room ...
ClpFactorization::zeroTolerance
double zeroTolerance() const
Zero tolerance.
Definition: ClpFactorization.hpp:175
ClpFactorization::sparseThreshold
void sparseThreshold(int value)
Set sparse threshold.
Definition: ClpFactorization.hpp:192
ClpFactorization::permute
int * permute() const
Returns address of permute region.
Definition: ClpFactorization.hpp:141
ClpFactorization::pivotTolerance
void pivotTolerance(double value)
Set pivot tolerance.
Definition: ClpFactorization.hpp:268
ClpFactorization::pivotTolerance
double pivotTolerance() const
Pivot tolerance.
Definition: ClpFactorization.hpp:262