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

Last change on this file since 1910 was 1910, checked in by stefan, 7 years ago
  • add configure option --enable-aboca={1,2,3,4,yes,no}
  • compile Aboca source only if --enable-aboca set (instead of compiling empty source files)
  • fix svn properties
  • Property svn:keywords set to Id
File size: 13.8 KB
Line 
1/* $Id: AbcSimplexFactorization.hpp 1910 2013-01-27 02:00:13Z stefan $ */
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 number of pivots since factorization
239  inline void setPivots ( int value ) const {
240    coinAbcFactorization_->setPivots(value) ;
241  }
242  /// Whether larger areas needed
243  inline double areaFactor (  ) const {
244    return coinAbcFactorization_->areaFactor() ;
245  }
246  /// Set whether larger areas needed
247  inline void areaFactor ( double value) {
248    coinAbcFactorization_->areaFactor(value);
249  }
250  /// Zero tolerance
251  inline double zeroTolerance (  ) const {
252    return coinAbcFactorization_->zeroTolerance() ;
253  }
254  /// Set zero tolerance
255  inline void zeroTolerance (  double value) {
256    coinAbcFactorization_->zeroTolerance(value);
257  }
258  /// Set tolerances to safer of existing and given
259  void saferTolerances (  double zeroTolerance, double pivotTolerance);
260  /// Returns status
261  inline int status (  ) const {
262    return coinAbcFactorization_->status() ;
263  }
264  /// Sets status
265  inline void setStatus (  int value) {
266    coinAbcFactorization_->setStatus(value) ;
267  }
268#if ABC_PARALLEL==2
269  /// Says parallel
270  inline void setParallelMode(int value)
271  {coinAbcFactorization_->setParallelMode(value);};
272#endif
273  /// Returns number of dense rows
274  inline int numberDense() const {
275    return coinAbcFactorization_->numberDense() ;
276  }
277  inline bool timeToRefactorize() const {
278    return coinAbcFactorization_->pivots() > coinAbcFactorization_->numberRows() / 2.45 + 20;
279  }
280  /// Get rid of all memory
281  inline void clearArrays() {
282    coinAbcFactorization_->clearArrays();
283  }
284  /// Number of Rows after factorization
285  inline int numberRows (  ) const {
286    return coinAbcFactorization_->numberRows() ;
287  }
288  /// Number of slacks at last factorization
289  inline int numberSlacks() const
290  { return numberSlacks_;}
291  /// Pivot tolerance
292  inline double pivotTolerance (  ) const {
293    return coinAbcFactorization_->pivotTolerance();
294  }
295  /// Set pivot tolerance
296  inline void pivotTolerance (  double value) {
297    coinAbcFactorization_->pivotTolerance(value);
298  }
299  /// Minimum pivot tolerance
300  inline double minimumPivotTolerance (  ) const {
301    return coinAbcFactorization_->minimumPivotTolerance();
302  }
303  /// Set minimum pivot tolerance
304  inline void minimumPivotTolerance (  double value) {
305    coinAbcFactorization_->minimumPivotTolerance(value);
306  }
307  /// pivot region
308  inline double * pivotRegion() const
309  { return coinAbcFactorization_->pivotRegion();}
310  /// Allows change of pivot accuracy check 1.0 == none >1.0 relaxed
311  //inline void relaxAccuracyCheck(double /*value*/) {
312  //abort();
313  //}
314  /// Delete all stuff (leaves as after CoinFactorization())
315  inline void almostDestructor() {
316    coinAbcFactorization_->clearArrays();
317  }
318  /// So we can temporarily switch off dense
319  void setDenseThreshold(int number);
320  int getDenseThreshold() const;
321  /// If nonzero force use of 1,dense 2,small 3,long
322  void forceOtherFactorization(int which);
323  /// Go over to dense code
324  void goDenseOrSmall(int numberRows);
325  /// Get switch to dense if number rows <= this
326  inline int goDenseThreshold() const {
327    return goDenseThreshold_;
328  }
329  /// Set switch to dense if number rows <= this
330  inline void setGoDenseThreshold(int value) {
331    goDenseThreshold_ = value;
332  }
333  /// Get switch to small if number rows <= this
334  inline int goSmallThreshold() const {
335    return goSmallThreshold_;
336  }
337  /// Set switch to small if number rows <= this
338  inline void setGoSmallThreshold(int value) {
339    goSmallThreshold_ = value;
340  }
341  /// Get switch to long/ordered if number rows >= this
342  inline int goLongThreshold() const {
343    return goLongThreshold_;
344  }
345  /// Set switch to long/ordered if number rows >= this
346  inline void setGoLongThreshold(int value) {
347    goLongThreshold_ = value;
348  }
349  /// Returns type
350  inline int typeOfFactorization() const
351  { return forceB_;}
352  /// Synchronize stuff
353  void synchronize(const ClpFactorization * otherFactorization,const AbcSimplex * model);
354  //@}
355 
356  /**@name other stuff */
357  //@{
358  /** makes a row copy of L for speed and to allow very sparse problems */
359  void goSparse();
360#ifndef NDEBUG
361  inline void checkMarkArrays() const
362  { coinAbcFactorization_->checkMarkArrays();}
363#endif
364  /// Says whether to redo pivot order
365  inline bool needToReorder() const {abort();return true;}
366  /// Pointer to factorization
367  CoinAbcAnyFactorization * factorization() const
368  { return coinAbcFactorization_;}
369  //@}
370 
371  ////////////////// data //////////////////
372private:
373 
374  /**@name data */
375  //@{
376  /// Pointer to model
377  AbcSimplex * model_;
378  /// Pointer to factorization
379  CoinAbcAnyFactorization * coinAbcFactorization_;
380  /// If nonzero force use of 1,dense 2,small 3,long
381  int forceB_;
382  /// Switch to dense if number rows <= this
383  int goDenseThreshold_;
384  /// Switch to small if number rows <= this
385  int goSmallThreshold_;
386  /// Switch to long/ordered if number rows >= this
387  int goLongThreshold_;
388  /// Number of slacks at last factorization
389  int numberSlacks_;
390  //@}
391};
392
393#endif
Note: See TracBrowser for help on using the repository browser.