source: trunk/Clp/src/ClpCholeskyBase.hpp @ 1368

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

changes for cholesky including code from Anshul Gupta

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 KB
Line 
1// Copyright (C) 2003, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#ifndef ClpCholeskyBase_H
4#define ClpCholeskyBase_H
5
6#include "CoinPragma.hpp"
7#include "CoinFinite.hpp"
8//#define CLP_LONG_CHOLESKY 0
9#ifndef CLP_LONG_CHOLESKY
10#define CLP_LONG_CHOLESKY 0
11#endif
12/* valid combinations are
13   CLP_LONG_CHOLESKY 0 and COIN_LONG_WORK 0
14   CLP_LONG_CHOLESKY 1 and COIN_LONG_WORK 1
15   CLP_LONG_CHOLESKY 2 and COIN_LONG_WORK 1
16*/
17#if COIN_LONG_WORK==0
18#if CLP_LONG_CHOLESKY>0
19#define CHOLESKY_BAD_COMBINATION
20#endif
21#else
22#if CLP_LONG_CHOLESKY==0
23#define CHOLESKY_BAD_COMBINATION
24#endif
25#endif
26#ifdef CHOLESKY_BAD_COMBINATION
27#  warning("Bad combination of CLP_LONG_CHOLESKY and COIN_BIG_DOUBLE/COIN_LONG_WORK");
28"Bad combination of CLP_LONG_CHOLESKY and COIN_LONG_WORK"
29#endif
30#if CLP_LONG_CHOLESKY>1
31typedef long double longDouble;
32#define CHOL_SMALL_VALUE 1.0e-15
33#elif CLP_LONG_CHOLESKY==1
34typedef double longDouble;
35#define CHOL_SMALL_VALUE 1.0e-11
36#else
37typedef double longDouble;
38#define CHOL_SMALL_VALUE 1.0e-11
39#endif
40class ClpInterior;
41class ClpCholeskyDense;
42class ClpMatrixBase;
43
44/** Base class for Clp Cholesky factorization
45    Will do better factorization.  very crude ordering
46
47    Derived classes may be using more sophisticated methods
48*/
49
50class ClpCholeskyBase  {
51 
52public:
53   /**@name Virtual methods that the derived classes may provide  */
54   //@{
55  /** Orders rows and saves pointer to matrix.and model.
56   returns non-zero if not enough memory.
57   You can use preOrder to set up ADAT
58   If using default symbolic etc then must set sizeFactor_ to
59   size of input matrix to order (and to symbolic).
60   Also just permute_ and permuteInverse_ should be created */
61  virtual int order(ClpInterior * model);
62  /** Does Symbolic factorization given permutation.
63      This is called immediately after order.  If user provides this then
64      user must provide factorize and solve.  Otherwise the default factorization is used
65      returns non-zero if not enough memory */
66  virtual int symbolic();
67  /** Factorize - filling in rowsDropped and returning number dropped.
68      If return code negative then out of memory */
69  virtual int factorize(const CoinWorkDouble * diagonal, int * rowsDropped) ;
70  /** Uses factorization to solve. */
71  virtual void solve (double * region) ;
72  /** Uses factorization to solve. - given as if KKT.
73   region1 is rows+columns, region2 is rows */
74  virtual void solveKKT (CoinWorkDouble * region1, CoinWorkDouble * region2, const CoinWorkDouble * diagonal,
75                         CoinWorkDouble diagonalScaleFactor);
76#if CLP_LONG_CHOLESKY
77  /** Uses factorization to solve. */
78  virtual void solve (CoinWorkDouble * region) ;
79#endif
80private:
81  /// AMD ordering
82  int orderAMD();
83public:
84  //@}
85
86  /**@name Gets */
87  //@{
88  /// status.  Returns status
89  inline int status() const 
90  {return status_;}
91  /// numberRowsDropped.  Number of rows gone
92  inline int numberRowsDropped() const 
93  {return numberRowsDropped_;}
94  /// reset numberRowsDropped and rowsDropped.
95  void resetRowsDropped();
96  /// rowsDropped - which rows are gone
97  inline char * rowsDropped() const 
98  {return rowsDropped_;}
99  /// choleskyCondition.
100  inline double choleskyCondition() const 
101  {return choleskyCondition_;}
102  /// goDense i.e. use dense factoriaztion if > this (default 0.7).
103  inline double goDense() const 
104  {return goDense_;}
105  /// goDense i.e. use dense factoriaztion if > this (default 0.7).
106  inline void setGoDense(double value)
107  {goDense_=value;}
108  /// rank.  Returns rank
109  inline int rank() const 
110  {return numberRows_-numberRowsDropped_;}
111  /// Return number of rows
112  inline int numberRows() const 
113  {return numberRows_;}
114  /// Return size
115  inline CoinBigIndex size() const
116  { return sizeFactor_;}
117  /// Return sparseFactor
118  inline longDouble * sparseFactor() const
119  { return sparseFactor_;}
120  /// Return diagonal
121  inline longDouble * diagonal() const
122  { return diagonal_;}
123  /// Return workDouble
124  inline longDouble * workDouble() const
125  { return workDouble_;}
126  /// If KKT on
127  inline bool kkt() const
128  { return doKKT_;}
129  /// Set KKT
130  inline void setKKT(bool yesNo)
131  { doKKT_ = yesNo;}
132  /// Set integer parameter
133  inline void setIntegerParameter(int i,int value)
134  { integerParameters_[i]=value;}
135  /// get integer parameter
136  inline int getIntegerParameter(int i)
137  { return integerParameters_[i];}
138  /// Set double parameter
139  inline void setDoubleParameter(int i,double value)
140  { doubleParameters_[i]=value;}
141  /// get double parameter
142  inline double getDoubleParameter(int i)
143  { return doubleParameters_[i];}
144   //@}
145 
146 
147public:
148
149   /**@name Constructors, destructor
150    */
151   //@{
152  /** Constructor which has dense columns activated.
153      Default is off. */
154  ClpCholeskyBase(int denseThreshold=-1);
155   /** Destructor (has to be public) */
156   virtual ~ClpCholeskyBase();
157  /// Copy
158   ClpCholeskyBase(const ClpCholeskyBase&);
159  /// Assignment
160   ClpCholeskyBase& operator=(const ClpCholeskyBase&);
161   //@}
162  //@{
163  ///@name Other
164  /// Clone
165  virtual ClpCholeskyBase * clone() const;
166 
167  /// Returns type
168  inline int type() const
169  { if (doKKT_) return 100; else return type_;}
170protected:
171  /// Sets type
172  inline void setType(int type) {type_=type;}
173  /// model.
174  inline void setModel(ClpInterior * model)
175  { model_=model;}
176   //@}
177   
178  /**@name Symbolic, factor and solve */
179  //@{
180  /** Symbolic1  - works out size without clever stuff.
181      Uses upper triangular as much easier.
182      Returns size
183   */
184  int symbolic1(const CoinBigIndex * Astart, const int * Arow);
185  /** Symbolic2  - Fills in indices
186      Uses lower triangular so can do cliques etc
187   */
188  void symbolic2(const CoinBigIndex * Astart, const int * Arow);
189  /** Factorize - filling in rowsDropped and returning number dropped
190      in integerParam.
191   */
192  void factorizePart2(int * rowsDropped) ;
193  /** solve - 1 just first half, 2 just second half - 3 both.
194  If 1 and 2 then diagonal has sqrt of inverse otherwise inverse
195  */
196  void solve(double * region, int type);
197  /// Forms ADAT - returns nonzero if not enough memory
198  int preOrder(bool lowerTriangular, bool includeDiagonal, bool doKKT);
199  /// Updates dense part (broken out for profiling)
200  void updateDense(longDouble * d, longDouble * work, int * first);
201  //@}
202   
203protected:
204  /**@name Data members
205     The data members are protected to allow access for derived classes. */
206  //@{
207  /// type (may be useful) if > 20 do KKT
208  int type_;
209  /// Doing full KKT (only used if default symbolic and factorization)
210  bool doKKT_;
211  /// Go dense at this fraction
212  double goDense_;
213  /// choleskyCondition.
214  double choleskyCondition_;
215  /// model.
216  ClpInterior * model_;
217  /// numberTrials.  Number of trials before rejection
218  int numberTrials_;
219  /// numberRows.  Number of Rows in factorization
220  int numberRows_;
221  /// status.  Status of factorization
222  int status_;
223  /// rowsDropped
224  char * rowsDropped_;
225  /// permute inverse.
226  int * permuteInverse_;
227  /// main permute.
228  int * permute_;
229  /// numberRowsDropped.  Number of rows gone
230  int numberRowsDropped_;
231  /// sparseFactor.
232  longDouble * sparseFactor_;
233  /// choleskyStart - element starts
234  CoinBigIndex * choleskyStart_;
235  /// choleskyRow (can be shorter than sparsefactor)
236  int * choleskyRow_;
237  /// Index starts
238  CoinBigIndex * indexStart_;
239  /// Diagonal
240  longDouble * diagonal_;
241  /// double work array
242  longDouble * workDouble_;
243  /// link array
244  int * link_;
245  // Integer work array
246  CoinBigIndex * workInteger_;
247  // Clique information
248  int * clique_;
249  /// sizeFactor.
250  CoinBigIndex sizeFactor_;
251  /// Size of index array
252  CoinBigIndex sizeIndex_;
253  /// First dense row
254  int firstDense_;
255  /// integerParameters
256  int integerParameters_[64];
257  /// doubleParameters;
258  double doubleParameters_[64];
259  /// Row copy of matrix
260  ClpMatrixBase * rowCopy_;
261  /// Dense indicators
262  char * whichDense_;
263  /// Dense columns (updated)
264  longDouble * denseColumn_;
265  /// Dense cholesky
266  ClpCholeskyDense * dense_;
267  /// Dense threshold (for taking out of Cholesky)
268  int denseThreshold_;
269  //@}
270};
271
272#endif
Note: See TracBrowser for help on using the repository browser.