ClpFactorization.hpp
Go to the documentation of this file.
1 /* $Id: ClpFactorization.hpp 1525 2010-02-26 17:27:59Z mjs $ */
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 #ifndef COIN_FAST_CODE
22 #define COIN_FAST_CODE
23 #endif
24 
31  : public CoinFactorization
32 #endif
33 {
34 
35  //friend class CoinFactorization;
36 
37 public:
49  int factorize (ClpSimplex * model, int solveType, bool valuesPass);
51 
52 
60 
64  ClpFactorization(const CoinFactorization&);
66  ClpFactorization(const ClpFactorization&, int denseIfSmaller = 0);
67 #ifdef CLP_MULTIPLE_FACTORIZATIONS
68 
69  ClpFactorization(const CoinOtherFactorization&);
70 #endif
73 
74  /* **** below here is so can use networkish basis */
77 
85  int replaceColumn ( const ClpSimplex * model,
86  CoinIndexedVector * regionSparse,
87  CoinIndexedVector * tableauColumn,
88  int pivotRow,
89  double pivotCheck ,
90  bool checkBeforeModifying = false,
91  double acceptablePivot = 1.0e-8);
93 
101  int updateColumnFT ( CoinIndexedVector * regionSparse,
102  CoinIndexedVector * regionSparse2);
105  int updateColumn ( CoinIndexedVector * regionSparse,
106  CoinIndexedVector * regionSparse2,
107  bool noPermute = false) const;
113  int updateTwoColumnsFT ( CoinIndexedVector * regionSparse1,
114  CoinIndexedVector * regionSparse2,
115  CoinIndexedVector * regionSparse3,
116  bool noPermuteRegion3 = false) ;
118  int updateColumnForDebug ( CoinIndexedVector * regionSparse,
119  CoinIndexedVector * regionSparse2,
120  bool noPermute = false) const;
123  int updateColumnTranspose ( CoinIndexedVector * regionSparse,
124  CoinIndexedVector * regionSparse2) const;
126 #ifdef CLP_MULTIPLE_FACTORIZATIONS
127 
129  inline int numberElements ( ) const {
131  if (coinFactorizationA_) return coinFactorizationA_->numberElements();
132  else return coinFactorizationB_->numberElements() ;
133  }
135  inline int *permute ( ) const {
136  if (coinFactorizationA_) return coinFactorizationA_->permute();
137  else return coinFactorizationB_->permute() ;
138  }
140  inline int *pivotColumn ( ) const {
141  if (coinFactorizationA_) return coinFactorizationA_->pivotColumn();
142  else return coinFactorizationB_->permute() ;
143  }
145  inline int maximumPivots ( ) const {
146  if (coinFactorizationA_) return coinFactorizationA_->maximumPivots();
147  else return coinFactorizationB_->maximumPivots() ;
148  }
150  inline void maximumPivots ( int value) {
151  if (coinFactorizationA_) coinFactorizationA_->maximumPivots(value);
152  else coinFactorizationB_->maximumPivots(value);
153  }
155  inline int pivots ( ) const {
156  if (coinFactorizationA_) return coinFactorizationA_->pivots();
157  else return coinFactorizationB_->pivots() ;
158  }
160  inline double areaFactor ( ) const {
161  if (coinFactorizationA_) return coinFactorizationA_->areaFactor();
162  else return 0.0 ;
163  }
165  inline void areaFactor ( double value) {
166  if (coinFactorizationA_) coinFactorizationA_->areaFactor(value);
167  }
169  inline double zeroTolerance ( ) const {
170  if (coinFactorizationA_) return coinFactorizationA_->zeroTolerance();
171  else return coinFactorizationB_->zeroTolerance() ;
172  }
174  inline void zeroTolerance ( double value) {
175  if (coinFactorizationA_) coinFactorizationA_->zeroTolerance(value);
176  else coinFactorizationB_->zeroTolerance(value);
177  }
179  void saferTolerances ( double zeroTolerance, double pivotTolerance);
181  inline int sparseThreshold ( ) const {
182  if (coinFactorizationA_) return coinFactorizationA_->sparseThreshold();
183  else return 0 ;
184  }
186  inline void sparseThreshold ( int value) {
187  if (coinFactorizationA_) coinFactorizationA_->sparseThreshold(value);
188  }
190  inline int status ( ) const {
191  if (coinFactorizationA_) return coinFactorizationA_->status();
192  else return coinFactorizationB_->status() ;
193  }
195  inline void setStatus ( int value) {
196  if (coinFactorizationA_) coinFactorizationA_->setStatus(value);
197  else coinFactorizationB_->setStatus(value) ;
198  }
200  inline int numberDense() const {
201  if (coinFactorizationA_) return coinFactorizationA_->numberDense();
202  else return 0 ;
203  }
204 #if 1
205  inline CoinBigIndex numberElementsU ( ) const {
207  if (coinFactorizationA_) return coinFactorizationA_->numberElementsU();
208  else return -1 ;
209  }
211  inline CoinBigIndex numberElementsL ( ) const {
212  if (coinFactorizationA_) return coinFactorizationA_->numberElementsL();
213  else return -1 ;
214  }
216  inline CoinBigIndex numberElementsR ( ) const {
217  if (coinFactorizationA_) return coinFactorizationA_->numberElementsR();
218  else return 0 ;
219  }
220 #endif
221  inline bool timeToRefactorize() const {
222  if (coinFactorizationA_) {
223  return (coinFactorizationA_->pivots() * 3 > coinFactorizationA_->maximumPivots() * 2 &&
224  coinFactorizationA_->numberElementsR() * 3 > (coinFactorizationA_->numberElementsL() +
225  coinFactorizationA_->numberElementsU()) * 2 + 1000 &&
226  !coinFactorizationA_->numberDense());
227  } else {
228  return coinFactorizationB_->pivots() > coinFactorizationB_->numberRows() / 2.45 + 20;
229  }
230  }
232  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() {
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() {
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  }
344  void goDenseOrSmall(int numberRows) ;
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
401 #endif
402 #ifdef CLP_MULTIPLE_FACTORIZATIONS
403  CoinFactorization * coinFactorizationA_;
406  CoinOtherFactorization * coinFactorizationB_;
408  int forceB_;
415 #endif
416 
417 };
418 
419 #endif
void forceOtherFactorization(int which)
If nonzero force use of 1,dense 2,small 3,osl.
int numberDense() const
Returns number of dense rows.
int updateColumnTranspose(CoinIndexedVector *regionSparse, CoinIndexedVector *regionSparse2) const
Updates one column (BTRAN) from region2 region1 starts as zero and is zero at end.
int goSmallThreshold() const
Get switch to small if number rows <= this.
int factorize(ClpSimplex *model, int solveType, bool valuesPass)
When part of LP - given by basic variables.
bool networkBasis() const
Says if a network basis.
void almostDestructor()
Delete all stuff (leaves as after CoinFactorization())
~ClpFactorization()
Destructor.
bool needToReorder() const
Says whether to redo pivot order.
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...
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.
int numberElements() const
Total number of elements in factorization.
int updateColumnForDebug(CoinIndexedVector *regionSparse, CoinIndexedVector *regionSparse2, bool noPermute=false) const
For debug (no statistics update)
double adjustedAreaFactor() const
Returns areaFactor but adjusted for dense.
void setPersistenceFlag(int value)
Total number of elements in factorization.
void zeroTolerance(double value)
Set zero tolerance.
ClpNetworkBasis * networkBasis_
Pointer to network basis.
int status() const
Returns status.
void setStatus(int value)
Sets status.
CoinBigIndex numberElementsR() const
Returns number in R area.
#define CLP_MULTIPLE_FACTORIZATIONS
ClpFactorization()
Default constructor.
This deals with Factorization and Updates for network structures.
CoinOtherFactorization * coinFactorizationB_
Pointer to CoinOtherFactorization.
bool timeToRefactorize() const
Total number of elements in factorization.
int * permute() const
Returns address of permute region.
CoinBigIndex numberElementsU() const
Returns number in U area.
int maximumPivots() const
Maximum number of pivots between factorizations.
int goDenseThreshold() const
Get switch to dense if number rows <= this.
int numberRows() const
Number of Rows after factorization.
ClpFactorization & operator=(const ClpFactorization &)
The copy constructor from an CoinFactorization.
int denseThreshold() const
Gets dense threshold.
void setFactorization(ClpFactorization &factorization)
Sets factorization.
double zeroTolerance() const
Zero tolerance.
void clearArrays()
Get rid of all memory.
void saferTolerances(double zeroTolerance, double pivotTolerance)
Set tolerances to safer of existing and given.
double pivotTolerance() const
Pivot tolerance.
void cleanUp()
Cleans up i.e. gets rid of network basis.
void pivotTolerance(double value)
Set pivot tolerance.
void setForrestTomlin(bool value)
true if Forrest Tomlin update, false if PFI
int goSmallThreshold_
Switch to small if number rows <= this.
void setGoOslThreshold(int value)
Set switch to osl if number rows <= this.
void setGoSmallThreshold(int value)
Set switch to small if number rows <= this.
This solves LPs using the simplex method.
Definition: ClpSimplex.hpp:49
void sparseThreshold(int value)
Set sparse threshold.
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...
int goOslThreshold() const
Get switch to osl if number rows <= this.
void setGoDenseThreshold(int value)
Set switch to dense if number rows <= this.
int updateColumnFT(CoinIndexedVector *regionSparse, CoinIndexedVector *regionSparse2)
Updates one column (FTRAN) from region2 Tries to do FT update number returned is negative if no room ...
Abstract base class for Clp Matrices.
void setDefaultValues()
Sets default values.
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...
int * pivotColumn() const
Returns address of pivotColumn region (also used for permuting)
void areaFactor(double value)
Set whether larger areas needed.
void getWeights(int *weights) const
Fills weighted row list.
int forceB_
If nonzero force use of 1,dense 2,small 3,osl.
double areaFactor() const
Whether larger areas needed.
void goDenseOrSmall(int numberRows)
Go over to dense or small code if small enough.
CoinFactorization * coinFactorizationA_
Pointer to CoinFactorization.
int goDenseThreshold_
Switch to dense if number rows <= this.
CoinBigIndex numberElementsL() const
Returns number in L area.
void messageLevel(int value)
Set level of detail of messages.
int sparseThreshold() const
get sparse threshold
void goSparse()
makes a row copy of L for speed and to allow very sparse problems
void maximumPivots(int value)
Set maximum number of pivots between factorizations.
void setDenseThreshold(int value)
Sets dense threshold.
void relaxAccuracyCheck(double value)
Allows change of pivot accuracy check 1.0 == none >1.0 relaxed.
int isDenseOrSmall() const
Return 1 if dense code.
int messageLevel() const
Level of detail of messages.
void setBiasLU(int value)
Total number of elements in factorization.
This just implements CoinFactorization when an ClpMatrixBase object is passed.
int goOslThreshold_
Switch to osl if number rows <= this.
int pivots() const
Returns number of pivots since factorization.