source: trunk/Clp/src/AbcSimplexFactorization.hpp @ 2030

Last change on this file since 2030 was 2024, checked in by forrest, 5 years ago

changes to abc

  • Property svn:keywords set to Id
File size: 13.9 KB
Line 
1/* $Id: AbcSimplexFactorization.hpp 2024 2014-03-07 17:18:15Z forrest $ */
2// Copyright (C) 2002, International Business Machines
3// Corporation and others, Copyright (C) 2012, FasterCoin.  All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
6#ifndef AbcSimplexFactorization_H
7#define AbcSimplexFactorization_H
8
9
10#include "CoinPragma.hpp"
11
12#include "CoinAbcCommon.hpp"
13#include "CoinAbcFactorization.hpp"
14#include "AbcMatrix.hpp"
15//#include "CoinAbcAnyFactorization.hpp"
16#include "AbcSimplex.hpp"
17class ClpFactorization;
18
19/** This just implements AbcFactorization when an AbcMatrix object
20    is passed.
21*/
22class AbcSimplexFactorization
23{
24 
25public:
26  /**@name factorization */
27  //@{
28  /** When part of LP - given by basic variables.
29      Actually does factorization.
30      Arrays passed in have non negative value to say basic.
31      If status is okay, basic variables have pivot row - this is only needed
32      if increasingRows_ >1.
33      Allows scaling
34      If status is singular, then basic variables have pivot row
35      and ones thrown out have -1
36      returns 0 -okay, -1 singular, -2 too many in basis, -99 memory */
37  int factorize (AbcSimplex * model, int solveType, bool valuesPass);
38#ifdef EARLY_FACTORIZE
39  /// Returns -2 if can't, -1 if singular, -99 memory, 0 OK
40  inline int factorize (AbcSimplex * model, CoinIndexedVector & stuff)
41  { return coinAbcFactorization_->factorize(model,stuff);}
42#endif
43  //@}
44 
45 
46  /**@name Constructors, destructor */
47  //@{
48  /** Default constructor. */
49  AbcSimplexFactorization(int numberRows=0);
50  /** Destructor */
51  ~AbcSimplexFactorization();
52  //@}
53 
54  /**@name Copy method */
55  //@{
56  /** The copy constructor. */
57  AbcSimplexFactorization(const AbcSimplexFactorization&, int denseIfSmaller = 0);
58  AbcSimplexFactorization& operator=(const AbcSimplexFactorization&);
59  /// Sets factorization
60  void setFactorization(AbcSimplexFactorization & rhs);
61  //@}
62 
63  /*  **** below here is so can use networkish basis */
64  /**@name rank one updates which do exist */
65  //@{
66 
67  /** Checks if can replace one Column to basis,
68      returns update alpha
69      Fills in region for use later
70      partial update already in U */
71  inline
72#ifdef ABC_LONG_FACTORIZATION
73  long
74#endif
75  double checkReplacePart1 ( CoinIndexedVector * regionSparse,
76                             int pivotRow)
77  {return coinAbcFactorization_->checkReplacePart1(regionSparse,pivotRow);}
78  /** Checks if can replace one Column to basis,
79      returns update alpha
80      Fills in region for use later
81      partial update in vector */
82  inline 
83#ifdef ABC_LONG_FACTORIZATION
84  long
85#endif
86  double checkReplacePart1 ( CoinIndexedVector * regionSparse,
87                                  CoinIndexedVector * partialUpdate,
88                                  int pivotRow)
89  {return coinAbcFactorization_->checkReplacePart1(regionSparse,partialUpdate,pivotRow);}
90  /** Checks if can replace one Column to basis,
91      returns update alpha
92      Fills in region for use later
93      partial update already in U */
94  inline void checkReplacePart1a ( CoinIndexedVector * regionSparse,
95                             int pivotRow)
96  {coinAbcFactorization_->checkReplacePart1a(regionSparse,pivotRow);}
97  inline double checkReplacePart1b (CoinIndexedVector * regionSparse,
98                             int pivotRow)
99  {return coinAbcFactorization_->checkReplacePart1b(regionSparse,pivotRow);}
100  /** Checks if can replace one Column to basis,
101      returns 0=OK, 1=Probably OK, 2=singular, 3=no room, 5 max pivots */
102  inline int checkReplacePart2 ( int pivotRow,
103                                 double btranAlpha, 
104                                 double ftranAlpha, 
105#ifdef ABC_LONG_FACTORIZATION
106                                 long
107#endif
108                                 double ftAlpha)
109  {return coinAbcFactorization_->checkReplacePart2(pivotRow,btranAlpha,ftranAlpha,ftAlpha);}
110#ifdef ABC_LONG_FACTORIZATION
111  /// Clear all hidden arrays
112  inline void clearHiddenArrays()
113  { coinAbcFactorization_->clearHiddenArrays();}
114#endif
115  /** Replaces one Column to basis,
116      partial update already in U */
117  void replaceColumnPart3 ( const AbcSimplex * model,
118                            CoinIndexedVector * regionSparse,
119                            CoinIndexedVector * tableauColumn,
120                            int pivotRow,
121#ifdef ABC_LONG_FACTORIZATION
122                            long
123#endif
124                            double alpha );
125  /** Replaces one Column to basis,
126      partial update in vector */
127  void replaceColumnPart3 ( const AbcSimplex * model,
128                            CoinIndexedVector * regionSparse,
129                            CoinIndexedVector * tableauColumn,
130                            CoinIndexedVector * partialUpdate,
131                            int pivotRow,
132#ifdef ABC_LONG_FACTORIZATION
133                            long
134#endif
135                            double alpha );
136#ifdef EARLY_FACTORIZE
137  /// 0 success, -1 can't +1 accuracy problems
138  inline int replaceColumns ( const AbcSimplex * model,
139                        CoinIndexedVector & stuff,
140                              int firstPivot,int lastPivot,bool cleanUp)
141  { return coinAbcFactorization_->replaceColumns(model,stuff,firstPivot,lastPivot,cleanUp);}
142#endif
143  //@}
144 
145  /**@name various uses of factorization (return code number elements)
146     which user may want to know about */
147  //@{
148#if 0
149  /** Updates one column (FTRAN) from region2
150      Tries to do FT update
151      number returned is negative if no room
152      region1 starts as zero and is zero at end */
153  int updateColumnFT ( CoinIndexedVector * regionSparse,
154                       CoinIndexedVector * regionSparse2);
155  /** Updates one column (FTRAN) from region2
156      region1 starts as zero and is zero at end */
157  int updateColumn ( CoinIndexedVector * regionSparse,
158                     CoinIndexedVector * regionSparse2) const;
159  /** Updates one column (FTRAN) from region2
160      Tries to do FT update
161      number returned is negative if no room.
162      Also updates region3
163      region1 starts as zero and is zero at end */
164  int updateTwoColumnsFT ( CoinIndexedVector * regionSparse1,
165                           CoinIndexedVector * regionSparse2,
166                           CoinIndexedVector * regionSparse3) ;
167  /** Updates one column (BTRAN) from region2
168      region1 starts as zero and is zero at end */
169  int updateColumnTranspose ( CoinIndexedVector * regionSparse,
170                              CoinIndexedVector * regionSparse2) const;
171#endif
172  /** Updates one column (FTRAN)
173      Tries to do FT update
174      number returned is negative if no room */
175  inline int updateColumnFT ( CoinIndexedVector & regionSparseFT)
176  { return coinAbcFactorization_->updateColumnFT(regionSparseFT);}
177  inline int updateColumnFTPart1 ( CoinIndexedVector & regionSparseFT)
178  { return coinAbcFactorization_->updateColumnFTPart1(regionSparseFT);}
179  inline void updateColumnFTPart2 ( CoinIndexedVector & regionSparseFT)
180  { coinAbcFactorization_->updateColumnFTPart2(regionSparseFT);}
181  /** Updates one column (FTRAN)
182      Tries to do FT update
183      puts partial update in vector */
184  inline void updateColumnFT ( CoinIndexedVector & regionSparseFT,
185                               CoinIndexedVector & partialUpdate,
186                               int which)
187  { coinAbcFactorization_->updateColumnFT(regionSparseFT,partialUpdate,which);}
188  /** Updates one column (FTRAN) */
189  inline int updateColumn ( CoinIndexedVector & regionSparse) const
190  { return coinAbcFactorization_->updateColumn(regionSparse);}
191  /** Updates one column (FTRAN) from regionFT
192      Tries to do FT update
193      number returned is negative if no room.
194      Also updates regionOther */
195  inline int updateTwoColumnsFT ( CoinIndexedVector & regionSparseFT,
196                           CoinIndexedVector & regionSparseOther)
197  { return coinAbcFactorization_->updateTwoColumnsFT(regionSparseFT,regionSparseOther);}
198  /** Updates one column (BTRAN) */
199  inline int updateColumnTranspose ( CoinIndexedVector & regionSparse) const
200  { return coinAbcFactorization_->updateColumnTranspose(regionSparse);}
201  /** Updates one column (FTRAN) */
202  inline void updateColumnCpu ( CoinIndexedVector & regionSparse,int whichCpu) const
203  { coinAbcFactorization_->updateColumnCpu(regionSparse,whichCpu);}
204  /** Updates one column (BTRAN) */
205  inline void updateColumnTransposeCpu ( CoinIndexedVector & regionSparse,int whichCpu) const
206  { coinAbcFactorization_->updateColumnTransposeCpu(regionSparse,whichCpu);}
207  /** Updates one full column (FTRAN) */
208  inline void updateFullColumn ( CoinIndexedVector & regionSparse) const
209  { coinAbcFactorization_->updateFullColumn(regionSparse);}
210  /** Updates one full column (BTRAN) */
211  inline void updateFullColumnTranspose ( CoinIndexedVector & regionSparse) const
212  { coinAbcFactorization_->updateFullColumnTranspose(regionSparse);}
213  /** Updates one column for dual steepest edge weights (FTRAN) */
214  void updateWeights ( CoinIndexedVector & regionSparse) const
215  { coinAbcFactorization_->updateWeights(regionSparse);}
216  //@}
217  /**@name Lifted from CoinFactorization */
218  //@{
219  /// Total number of elements in factorization
220  inline int numberElements (  ) const {
221    return coinAbcFactorization_->numberElements() ;
222  }
223  /// Maximum number of pivots between factorizations
224  inline int maximumPivots (  ) const {
225    return coinAbcFactorization_->maximumPivots() ;
226  }
227  /// Set maximum number of pivots between factorizations
228  inline void maximumPivots (  int value) {
229    coinAbcFactorization_->maximumPivots(value);
230  }
231  /// Returns true if doing FT
232  inline bool usingFT() const
233  { return !coinAbcFactorization_->wantsTableauColumn();}
234  /// Returns number of pivots since factorization
235  inline int pivots (  ) const {
236    return coinAbcFactorization_->pivots() ;
237  }
238  /// Sets model
239  inline void setModel(AbcSimplex * model)
240  {model_ = model;}
241  /// Sets number of pivots since factorization
242  inline void setPivots ( int value ) const {
243    coinAbcFactorization_->setPivots(value) ;
244  }
245  /// Whether larger areas needed
246  inline double areaFactor (  ) const {
247    return coinAbcFactorization_->areaFactor() ;
248  }
249  /// Set whether larger areas needed
250  inline void areaFactor ( double value) {
251    coinAbcFactorization_->areaFactor(value);
252  }
253  /// Zero tolerance
254  inline double zeroTolerance (  ) const {
255    return coinAbcFactorization_->zeroTolerance() ;
256  }
257  /// Set zero tolerance
258  inline void zeroTolerance (  double value) {
259    coinAbcFactorization_->zeroTolerance(value);
260  }
261  /// Set tolerances to safer of existing and given
262  void saferTolerances (  double zeroTolerance, double pivotTolerance);
263  /// Returns status
264  inline int status (  ) const {
265    return coinAbcFactorization_->status() ;
266  }
267  /// Sets status
268  inline void setStatus (  int value) {
269    coinAbcFactorization_->setStatus(value) ;
270  }
271#if ABC_PARALLEL==2
272  /// Says parallel
273  inline void setParallelMode(int value)
274  {coinAbcFactorization_->setParallelMode(value);};
275#endif
276  /// Returns number of dense rows
277  inline int numberDense() const {
278    return coinAbcFactorization_->numberDense() ;
279  }
280  inline bool timeToRefactorize() const {
281    return coinAbcFactorization_->pivots() > coinAbcFactorization_->numberRows() / 2.45 + 20;
282  }
283  /// Get rid of all memory
284  inline void clearArrays() {
285    coinAbcFactorization_->clearArrays();
286  }
287  /// Number of Rows after factorization
288  inline int numberRows (  ) const {
289    return coinAbcFactorization_->numberRows() ;
290  }
291  /// Number of slacks at last factorization
292  inline int numberSlacks() const
293  { return numberSlacks_;}
294  /// Pivot tolerance
295  inline double pivotTolerance (  ) const {
296    return coinAbcFactorization_->pivotTolerance();
297  }
298  /// Set pivot tolerance
299  inline void pivotTolerance (  double value) {
300    coinAbcFactorization_->pivotTolerance(value);
301  }
302  /// Minimum pivot tolerance
303  inline double minimumPivotTolerance (  ) const {
304    return coinAbcFactorization_->minimumPivotTolerance();
305  }
306  /// Set minimum pivot tolerance
307  inline void minimumPivotTolerance (  double value) {
308    coinAbcFactorization_->minimumPivotTolerance(value);
309  }
310  /// pivot region
311  inline double * pivotRegion() const
312  { return coinAbcFactorization_->pivotRegion();}
313  /// Allows change of pivot accuracy check 1.0 == none >1.0 relaxed
314  //inline void relaxAccuracyCheck(double /*value*/) {
315  //abort();
316  //}
317  /// Delete all stuff (leaves as after CoinFactorization())
318  inline void almostDestructor() {
319    coinAbcFactorization_->clearArrays();
320  }
321  /// So we can temporarily switch off dense
322  void setDenseThreshold(int number);
323  int getDenseThreshold() const;
324  /// If nonzero force use of 1,dense 2,small 3,long
325  void forceOtherFactorization(int which);
326  /// Go over to dense code
327  void goDenseOrSmall(int numberRows);
328  /// Get switch to dense if number rows <= this
329  inline int goDenseThreshold() const {
330    return goDenseThreshold_;
331  }
332  /// Set switch to dense if number rows <= this
333  inline void setGoDenseThreshold(int value) {
334    goDenseThreshold_ = value;
335  }
336  /// Get switch to small if number rows <= this
337  inline int goSmallThreshold() const {
338    return goSmallThreshold_;
339  }
340  /// Set switch to small if number rows <= this
341  inline void setGoSmallThreshold(int value) {
342    goSmallThreshold_ = value;
343  }
344  /// Get switch to long/ordered if number rows >= this
345  inline int goLongThreshold() const {
346    return goLongThreshold_;
347  }
348  /// Set switch to long/ordered if number rows >= this
349  inline void setGoLongThreshold(int value) {
350    goLongThreshold_ = value;
351  }
352  /// Returns type
353  inline int typeOfFactorization() const
354  { return forceB_;}
355  /// Synchronize stuff
356  void synchronize(const ClpFactorization * otherFactorization,const AbcSimplex * model);
357  //@}
358 
359  /**@name other stuff */
360  //@{
361  /** makes a row copy of L for speed and to allow very sparse problems */
362  void goSparse();
363#ifndef NDEBUG
364  inline void checkMarkArrays() const
365  { coinAbcFactorization_->checkMarkArrays();}
366#endif
367  /// Says whether to redo pivot order
368  inline bool needToReorder() const {abort();return true;}
369  /// Pointer to factorization
370  CoinAbcAnyFactorization * factorization() const
371  { return coinAbcFactorization_;}
372  //@}
373 
374  ////////////////// data //////////////////
375private:
376 
377  /**@name data */
378  //@{
379  /// Pointer to model
380  AbcSimplex * model_;
381  /// Pointer to factorization
382  CoinAbcAnyFactorization * coinAbcFactorization_;
383  /// If nonzero force use of 1,dense 2,small 3,long
384  int forceB_;
385  /// Switch to dense if number rows <= this
386  int goDenseThreshold_;
387  /// Switch to small if number rows <= this
388  int goSmallThreshold_;
389  /// Switch to long/ordered if number rows >= this
390  int goLongThreshold_;
391  /// Number of slacks at last factorization
392  int numberSlacks_;
393  //@}
394};
395
396#endif
Note: See TracBrowser for help on using the repository browser.