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

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

add ids

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 13.1 KB
Line 
1/* $Id: ClpFactorization.hpp 1370 2009-06-04 09:37:13Z forrest $ */
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"
11class ClpMatrixBase;
12class ClpSimplex;
13class ClpNetworkBasis;
14#ifndef CLP_MULTIPLE_FACTORIZATIONS
15#define CLP_MULTIPLE_FACTORIZATIONS 3
16#endif   
17#if CLP_MULTIPLE_FACTORIZATIONS == 1
18#include "CoinDenseFactorization.hpp"
19typedef CoinDenseFactorization CoinSmallFactorization;
20#elif CLP_MULTIPLE_FACTORIZATIONS == 2
21#include "CoinSimpFactorization.hpp"
22typedef CoinSimpFactorization CoinSmallFactorization;
23#elif CLP_MULTIPLE_FACTORIZATIONS == 3
24#include "CoinDenseFactorization.hpp"
25#include "CoinSimpFactorization.hpp"
26#endif
27
28/** This just implements CoinFactorization when an ClpMatrixBase object
29    is passed.  If a network then has a dummy CoinFactorization and
30    a genuine ClpNetworkBasis object
31*/
32class ClpFactorization 
33#ifndef CLP_MULTIPLE_FACTORIZATIONS   
34  : public CoinFactorization
35#endif
36{
37
38  //friend class CoinFactorization;
39 
40public:
41  /**@name factorization */
42   //@{
43  /** When part of LP - given by basic variables.
44  Actually does factorization.
45  Arrays passed in have non negative value to say basic.
46  If status is okay, basic variables have pivot row - this is only needed
47  if increasingRows_ >1.
48  Allows scaling
49  If status is singular, then basic variables have pivot row
50  and ones thrown out have -1
51  returns 0 -okay, -1 singular, -2 too many in basis, -99 memory */
52  int factorize (ClpSimplex * model,int solveType, bool valuesPass);
53   //@}
54
55
56  /**@name Constructors, destructor */
57   //@{
58   /** Default constructor. */
59   ClpFactorization();
60   /** Destructor */
61   ~ClpFactorization();
62   //@}
63
64   /**@name Copy method */
65   //@{
66   /** The copy constructor from an CoinFactorization. */
67   ClpFactorization(const CoinFactorization&);
68   /** The copy constructor. */
69  ClpFactorization(const ClpFactorization&,int denseIfSmaller=0);
70#ifdef CLP_MULTIPLE_FACTORIZATIONS   
71   /** The copy constructor from an CoinSmallFactorization. */
72   ClpFactorization(const CoinSmallFactorization&);
73#endif
74   ClpFactorization& operator=(const ClpFactorization&);
75   //@}
76   
77  /*  **** below here is so can use networkish basis */
78  /**@name rank one updates which do exist */
79  //@{
80
81  /** Replaces one Column to basis,
82   returns 0=OK, 1=Probably OK, 2=singular, 3=no room
83      If checkBeforeModifying is true will do all accuracy checks
84      before modifying factorization.  Whether to set this depends on
85      speed considerations.  You could just do this on first iteration
86      after factorization and thereafter re-factorize
87   partial update already in U */
88  int replaceColumn ( const ClpSimplex * model,
89                      CoinIndexedVector * regionSparse,
90                      CoinIndexedVector * tableauColumn,
91                      int pivotRow,
92                      double pivotCheck ,
93                      bool checkBeforeModifying=false);
94  //@}
95
96  /**@name various uses of factorization (return code number elements)
97   which user may want to know about */
98  //@{
99  /** Updates one column (FTRAN) from region2
100      Tries to do FT update
101      number returned is negative if no room
102      region1 starts as zero and is zero at end */
103  int updateColumnFT ( CoinIndexedVector * regionSparse,
104                       CoinIndexedVector * regionSparse2);
105  /** Updates one column (FTRAN) from region2
106      region1 starts as zero and is zero at end */
107  int updateColumn ( CoinIndexedVector * regionSparse,
108                     CoinIndexedVector * regionSparse2,
109                     bool noPermute=false) const;
110  /** Updates one column (FTRAN) from region2
111      Tries to do FT update
112      number returned is negative if no room.
113      Also updates region3
114      region1 starts as zero and is zero at end */
115  int updateTwoColumnsFT ( CoinIndexedVector * regionSparse1,
116                           CoinIndexedVector * regionSparse2,
117                           CoinIndexedVector * regionSparse3,
118                           bool noPermuteRegion3=false) ;
119  /// For debug (no statistics update)
120  int updateColumnForDebug ( CoinIndexedVector * regionSparse,
121                     CoinIndexedVector * regionSparse2,
122                     bool noPermute=false) const;
123  /** Updates one column (BTRAN) from region2
124      region1 starts as zero and is zero at end */
125  int updateColumnTranspose ( CoinIndexedVector * regionSparse,
126                              CoinIndexedVector * regionSparse2) const;
127  //@}
128#ifdef CLP_MULTIPLE_FACTORIZATIONS   
129  /**@name Lifted from CoinFactorization */
130  //@{
131  /// Total number of elements in factorization
132  inline int numberElements (  ) const {
133    if (coinFactorizationA_) return coinFactorizationA_->numberElements(); else return coinFactorizationB_->numberElements() ;
134  }
135  /// Returns address of permute region
136  inline int *permute (  ) const {
137    if (coinFactorizationA_) return coinFactorizationA_->permute(); else return coinFactorizationB_->permute() ;
138  }
139  /// Returns address of pivotColumn region (also used for permuting)
140  inline int *pivotColumn (  ) const {
141    if (coinFactorizationA_) return coinFactorizationA_->pivotColumn(); else return coinFactorizationB_->permute() ;
142  }
143  /// Maximum number of pivots between factorizations
144  inline int maximumPivots (  ) const {
145    if (coinFactorizationA_) return coinFactorizationA_->maximumPivots();  else return coinFactorizationB_->maximumPivots() ;
146  }
147  /// Set maximum number of pivots between factorizations
148  inline void maximumPivots (  int value) {
149    if (coinFactorizationA_) coinFactorizationA_->maximumPivots(value); else coinFactorizationB_->maximumPivots(value);
150  }
151  /// Returns number of pivots since factorization
152  inline int pivots (  ) const {
153    if (coinFactorizationA_) return coinFactorizationA_->pivots(); else return coinFactorizationB_->pivots() ;
154  }
155  /// Whether larger areas needed
156  inline double areaFactor (  ) const {
157    if (coinFactorizationA_) return coinFactorizationA_->areaFactor(); else return 0.0 ;
158  }
159  /// Set whether larger areas needed
160  inline void areaFactor ( double value) {
161    if (coinFactorizationA_) coinFactorizationA_->areaFactor(value); 
162  }
163  /// Zero tolerance
164  inline double zeroTolerance (  ) const {
165    if (coinFactorizationA_) return coinFactorizationA_->zeroTolerance();  else return coinFactorizationB_->zeroTolerance() ;
166  }
167  /// Set zero tolerance
168  inline void zeroTolerance (  double value) {
169    if (coinFactorizationA_) coinFactorizationA_->zeroTolerance(value); else coinFactorizationB_->zeroTolerance(value);
170  }
171  /// Set tolerances to safer of existing and given
172  void saferTolerances (  double zeroTolerance, double pivotTolerance);
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.