source: trunk/Clp/src/ClpFactorization.hpp @ 1284

Last change on this file since 1284 was 1284, checked in by forrest, 11 years ago

allow coinsimpfactorization

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