source: stable/1.10/Clp/src/ClpFactorization.hpp @ 1476

Last change on this file since 1476 was 1476, checked in by tkr, 10 years ago

Rolling back changes for Cbc 2.4 (r1456:1450) from Clp 1.10

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