Clp  1.15.10
ClpFactorization.hpp
Go to the documentation of this file.
1 /* $Id: ClpFactorization.hpp 1665 2011-01-04 17:55:54Z lou $ */
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 
34  : public CoinFactorization
35 #endif
36 {
37 
38  //friend class CoinFactorization;
39 
40 public:
52  int factorize (ClpSimplex * model, int solveType, bool valuesPass);
54 
55 
63 
67  ClpFactorization(const CoinFactorization&);
69  ClpFactorization(const ClpFactorization&, int denseIfSmaller = 0);
70 #ifdef CLP_MULTIPLE_FACTORIZATIONS
71 
72  ClpFactorization(const CoinOtherFactorization&);
73 #endif
76 
77  /* **** below here is so can use networkish basis */
80 
88  int replaceColumn ( const ClpSimplex * model,
89  CoinIndexedVector * regionSparse,
90  CoinIndexedVector * tableauColumn,
91  int pivotRow,
92  double pivotCheck ,
93  bool checkBeforeModifying = false,
94  double acceptablePivot = 1.0e-8);
96 
104  int updateColumnFT ( CoinIndexedVector * regionSparse,
105  CoinIndexedVector * regionSparse2);
108  int updateColumn ( CoinIndexedVector * regionSparse,
109  CoinIndexedVector * regionSparse2,
110  bool noPermute = false) const;
116  int updateTwoColumnsFT ( CoinIndexedVector * regionSparse1,
117  CoinIndexedVector * regionSparse2,
118  CoinIndexedVector * regionSparse3,
119  bool noPermuteRegion3 = false) ;
121  int updateColumnForDebug ( CoinIndexedVector * regionSparse,
122  CoinIndexedVector * regionSparse2,
123  bool noPermute = false) const;
126  int updateColumnTranspose ( CoinIndexedVector * regionSparse,
127  CoinIndexedVector * regionSparse2) const;
129 #ifdef CLP_MULTIPLE_FACTORIZATIONS
130 
132  inline int numberElements ( ) const {
134  if (coinFactorizationA_) return coinFactorizationA_->numberElements();
135  else return coinFactorizationB_->numberElements() ;
136  }
138  inline int *permute ( ) const {
139  if (coinFactorizationA_) return coinFactorizationA_->permute();
140  else return coinFactorizationB_->permute() ;
141  }
143  inline int *pivotColumn ( ) const {
144  if (coinFactorizationA_) return coinFactorizationA_->pivotColumn();
145  else return coinFactorizationB_->permute() ;
146  }
148  inline int maximumPivots ( ) const {
149  if (coinFactorizationA_) return coinFactorizationA_->maximumPivots();
150  else return coinFactorizationB_->maximumPivots() ;
151  }
153  inline void maximumPivots ( int value) {
154  if (coinFactorizationA_) coinFactorizationA_->maximumPivots(value);
155  else coinFactorizationB_->maximumPivots(value);
156  }
158  inline int pivots ( ) const {
159  if (coinFactorizationA_) return coinFactorizationA_->pivots();
160  else return coinFactorizationB_->pivots() ;
161  }
163  inline double areaFactor ( ) const {
164  if (coinFactorizationA_) return coinFactorizationA_->areaFactor();
165  else return 0.0 ;
166  }
168  inline void areaFactor ( double value) {
169  if (coinFactorizationA_) coinFactorizationA_->areaFactor(value);
170  }
172  inline double zeroTolerance ( ) const {
173  if (coinFactorizationA_) return coinFactorizationA_->zeroTolerance();
174  else return coinFactorizationB_->zeroTolerance() ;
175  }
177  inline void zeroTolerance ( double value) {
178  if (coinFactorizationA_) coinFactorizationA_->zeroTolerance(value);
179  else coinFactorizationB_->zeroTolerance(value);
180  }
182  void saferTolerances ( double zeroTolerance, double pivotTolerance);
184  inline int sparseThreshold ( ) const {
185  if (coinFactorizationA_) return coinFactorizationA_->sparseThreshold();
186  else return 0 ;
187  }
189  inline void sparseThreshold ( int value) {
190  if (coinFactorizationA_) coinFactorizationA_->sparseThreshold(value);
191  }
193  inline int status ( ) const {
194  if (coinFactorizationA_) return coinFactorizationA_->status();
195  else return coinFactorizationB_->status() ;
196  }
198  inline void setStatus ( int value) {
199  if (coinFactorizationA_) coinFactorizationA_->setStatus(value);
200  else coinFactorizationB_->setStatus(value) ;
201  }
203  inline int numberDense() const {
204  if (coinFactorizationA_) return coinFactorizationA_->numberDense();
205  else return 0 ;
206  }
207 #if 1
208  inline CoinBigIndex numberElementsU ( ) const {
210  if (coinFactorizationA_) return coinFactorizationA_->numberElementsU();
211  else return -1 ;
212  }
214  inline CoinBigIndex numberElementsL ( ) const {
215  if (coinFactorizationA_) return coinFactorizationA_->numberElementsL();
216  else return -1 ;
217  }
219  inline CoinBigIndex numberElementsR ( ) const {
220  if (coinFactorizationA_) return coinFactorizationA_->numberElementsR();
221  else return 0 ;
222  }
223 #endif
224  inline bool timeToRefactorize() const {
225  if (coinFactorizationA_) {
226  return (coinFactorizationA_->pivots() * 3 > coinFactorizationA_->maximumPivots() * 2 &&
227  coinFactorizationA_->numberElementsR() * 3 > (coinFactorizationA_->numberElementsL() +
228  coinFactorizationA_->numberElementsU()) * 2 + 1000 &&
229  !coinFactorizationA_->numberDense());
230  } else {
231  return coinFactorizationB_->pivots() > coinFactorizationB_->numberRows() / 2.45 + 20;
232  }
233  }
235  inline int messageLevel ( ) const {
236  if (coinFactorizationA_) return coinFactorizationA_->messageLevel();
237  else return 1 ;
238  }
240  inline void messageLevel ( int value) {
241  if (coinFactorizationA_) coinFactorizationA_->messageLevel(value);
242  }
244  inline void clearArrays() {
245  if (coinFactorizationA_)
246  coinFactorizationA_->clearArrays();
247  else if (coinFactorizationB_)
248  coinFactorizationB_->clearArrays();
249  }
251  inline int numberRows ( ) const {
252  if (coinFactorizationA_) return coinFactorizationA_->numberRows();
253  else return coinFactorizationB_->numberRows() ;
254  }
256  inline int denseThreshold() const {
257  if (coinFactorizationA_) return coinFactorizationA_->denseThreshold();
258  else return 0 ;
259  }
261  inline void setDenseThreshold(int value) {
262  if (coinFactorizationA_) coinFactorizationA_->setDenseThreshold(value);
263  }
265  inline double pivotTolerance ( ) const {
266  if (coinFactorizationA_) return coinFactorizationA_->pivotTolerance();
267  else if (coinFactorizationB_) return coinFactorizationB_->pivotTolerance();
268  return 1.0e-8 ;
269  }
271  inline void pivotTolerance ( double value) {
272  if (coinFactorizationA_) coinFactorizationA_->pivotTolerance(value);
273  else if (coinFactorizationB_) coinFactorizationB_->pivotTolerance(value);
274  }
276  inline void relaxAccuracyCheck(double value) {
277  if (coinFactorizationA_) coinFactorizationA_->relaxAccuracyCheck(value);
278  }
284  inline int persistenceFlag() const {
285  if (coinFactorizationA_) return coinFactorizationA_->persistenceFlag();
286  else return 0 ;
287  }
288  inline void setPersistenceFlag(int value) {
289  if (coinFactorizationA_) coinFactorizationA_->setPersistenceFlag(value);
290  }
292  inline void almostDestructor() {
293  if (coinFactorizationA_)
294  coinFactorizationA_->almostDestructor();
295  else if (coinFactorizationB_)
296  coinFactorizationB_->clearArrays();
297  }
299  inline double adjustedAreaFactor() const {
300  if (coinFactorizationA_) return coinFactorizationA_->adjustedAreaFactor();
301  else return 0.0 ;
302  }
303  inline void setBiasLU(int value) {
304  if (coinFactorizationA_) coinFactorizationA_->setBiasLU(value);
305  }
307  inline void setForrestTomlin(bool value) {
308  if (coinFactorizationA_) coinFactorizationA_->setForrestTomlin(value);
309  }
311  inline void setDefaultValues() {
312  if (coinFactorizationA_) {
313  // row activities have negative sign
314 #ifndef COIN_FAST_CODE
315  coinFactorizationA_->slackValue(-1.0);
316 #endif
317  coinFactorizationA_->zeroTolerance(1.0e-13);
318  }
319  }
321  void forceOtherFactorization(int which);
323  inline int goOslThreshold() const {
324  return goOslThreshold_;
325  }
327  inline void setGoOslThreshold(int value) {
328  goOslThreshold_ = value;
329  }
331  inline int goDenseThreshold() const {
332  return goDenseThreshold_;
333  }
335  inline void setGoDenseThreshold(int value) {
336  goDenseThreshold_ = value;
337  }
339  inline int goSmallThreshold() const {
340  return goSmallThreshold_;
341  }
343  inline void setGoSmallThreshold(int value) {
344  goSmallThreshold_ = value;
345  }
347  void goDenseOrSmall(int numberRows) ;
349  void setFactorization(ClpFactorization & factorization);
351  inline int isDenseOrSmall() const {
352  return coinFactorizationB_ ? 1 : 0;
353  }
354 #else
355  inline bool timeToRefactorize() const {
356  return (pivots() * 3 > maximumPivots() * 2 &&
357  numberElementsR() * 3 > (numberElementsL() + numberElementsU()) * 2 + 1000 &&
358  !numberDense());
359  }
361  inline void setDefaultValues() {
362  // row activities have negative sign
363 #ifndef COIN_FAST_CODE
364  slackValue(-1.0);
365 #endif
366  zeroTolerance(1.0e-13);
367  }
369  inline void goDense() {}
370 #endif
371 
372 
376  void goSparse();
378  void cleanUp();
380  bool needToReorder() const;
381 #ifndef SLIM_CLP
382  inline bool networkBasis() const {
384  return (networkBasis_ != NULL);
385  }
386 #else
387  inline bool networkBasis() const {
389  return false;
390  }
391 #endif
392  void getWeights(int * weights) const;
395 
397 private:
398 
401 #ifndef SLIM_CLP
403  ClpNetworkBasis * networkBasis_;
404 #endif
405 #ifdef CLP_MULTIPLE_FACTORIZATIONS
406  CoinFactorization * coinFactorizationA_;
409  CoinOtherFactorization * coinFactorizationB_;
410 #ifdef CLP_REUSE_ETAS
411  ClpSimplex * model_;
413 #endif
414  int forceB_;
417  int goOslThreshold_;
419  int goSmallThreshold_;
421  int goDenseThreshold_;
422 #endif
423 
424 };
425 
426 #endif
int pivots() const
Returns number of pivots since factorization.
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.
void setGoOslThreshold(int value)
Set switch to osl if number rows <= this.
void setGoSmallThreshold(int value)
Set switch to small if number rows <= this.
void sparseThreshold(int value)
Set sparse threshold.
Abstract base class for Clp Matrices.
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...
void setStatus(int value)
Sets status.
int goDenseThreshold() const
Get switch to dense if number rows <= this.
int factorize(ClpSimplex *model, int solveType, bool valuesPass)
When part of LP - given by basic variables.
void setDenseThreshold(int value)
Sets dense threshold.
double pivotTolerance() const
Pivot tolerance.
void almostDestructor()
Delete all stuff (leaves as after CoinFactorization())
void forceOtherFactorization(int which)
If nonzero force use of 1,dense 2,small 3,osl.
void setFactorization(ClpFactorization &factorization)
Sets factorization.
double areaFactor() const
Whether larger areas needed.
CoinBigIndex numberElementsR() const
Returns number in R area.
void saferTolerances(double zeroTolerance, double pivotTolerance)
Set tolerances to safer of existing and given.
void setGoDenseThreshold(int value)
Set switch to dense if number rows <= this.
void setDefaultValues()
Sets default values.
double adjustedAreaFactor() const
Returns areaFactor but adjusted for dense.
int status() const
Returns status.
This deals with Factorization and Updates for network structures.
This just implements CoinFactorization when an ClpMatrixBase object is passed.
void setBiasLU(int value)
CoinBigIndex numberElementsL() const
Returns number in L area.
void setPersistenceFlag(int value)
#define CLP_MULTIPLE_FACTORIZATIONS
bool networkBasis() const
Says if a network basis.
int sparseThreshold() const
get sparse threshold
CoinBigIndex numberElementsU() const
Returns number in U area.
void maximumPivots(int value)
Set maximum number of pivots between factorizations.
~ClpFactorization()
Destructor.
int denseThreshold() const
Gets dense threshold.
void cleanUp()
Cleans up i.e. gets rid of network basis.
This solves LPs using the simplex method.
Definition: ClpSimplex.hpp:55
int updateColumnTranspose(CoinIndexedVector *regionSparse, CoinIndexedVector *regionSparse2) const
Updates one column (BTRAN) from region2 region1 starts as zero and is zero at end.
void goDenseOrSmall(int numberRows)
Go over to dense or small code if small enough.
void clearArrays()
Get rid of all memory.
int goSmallThreshold() const
Get switch to small if number rows <= this.
ClpFactorization()
Default constructor.
int numberRows() const
Number of Rows after factorization.
void zeroTolerance(double value)
Set zero tolerance.
int maximumPivots() const
Maximum number of pivots between factorizations.
ClpFactorization & operator=(const ClpFactorization &)
void goSparse()
makes a row copy of L for speed and to allow very sparse problems
double zeroTolerance() const
Zero tolerance.
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 goOslThreshold() const
Get switch to osl if number rows <= this.
int numberDense() const
Returns number of dense rows.
int * permute() const
Returns address of permute region.
void messageLevel(int value)
Set level of detail of messages.
int * pivotColumn() const
Returns address of pivotColumn region (also used for permuting)
bool needToReorder() const
Says whether to redo pivot order.
int isDenseOrSmall() const
Return 1 if dense code.
int numberElements() const
Total number of elements in factorization.
bool timeToRefactorize() const
int updateColumnFT(CoinIndexedVector *regionSparse, CoinIndexedVector *regionSparse2)
Updates one column (FTRAN) from region2 Tries to do FT update number returned is negative if no room ...
void getWeights(int *weights) const
Fills weighted row list.
int messageLevel() const
Level of detail of messages.
int updateColumnForDebug(CoinIndexedVector *regionSparse, CoinIndexedVector *regionSparse2, bool noPermute=false) const
For debug (no statistics update)
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...
void pivotTolerance(double value)
Set pivot tolerance.
void setForrestTomlin(bool value)
true if Forrest Tomlin update, false if PFI
void areaFactor(double value)
Set whether larger areas needed.
void relaxAccuracyCheck(double value)
Allows change of pivot accuracy check 1.0 == none >1.0 relaxed.