source: releases/1.8.0/Clp/src/ClpFactorization.hpp @ 2257

Last change on this file since 2257 was 1197, checked in by forrest, 12 years ago

many changes to try and improve performance

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