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

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

changes to try and make faster

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