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

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

changes for factorization and aux region

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