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

Last change on this file since 1525 was 1525, checked in by mjs, 10 years ago

Formatted .cpp, .hpp, .c, .h files with "astyle -A4 -p". This matches the formatting used in the grand CBC reorganization.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.7 KB
Line 
1/* $Id: ClpCholeskyBase.hpp 1525 2010-02-26 17:27:59Z mjs $ */
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     }
89     /// numberRowsDropped.  Number of rows gone
90     inline int numberRowsDropped() const {
91          return numberRowsDropped_;
92     }
93     /// reset numberRowsDropped and rowsDropped.
94     void resetRowsDropped();
95     /// rowsDropped - which rows are gone
96     inline char * rowsDropped() const {
97          return rowsDropped_;
98     }
99     /// choleskyCondition.
100     inline double choleskyCondition() const {
101          return choleskyCondition_;
102     }
103     /// goDense i.e. use dense factoriaztion if > this (default 0.7).
104     inline double goDense() const {
105          return goDense_;
106     }
107     /// goDense i.e. use dense factoriaztion if > this (default 0.7).
108     inline void setGoDense(double value) {
109          goDense_ = value;
110     }
111     /// rank.  Returns rank
112     inline int rank() const {
113          return numberRows_ - numberRowsDropped_;
114     }
115     /// Return number of rows
116     inline int numberRows() const {
117          return numberRows_;
118     }
119     /// Return size
120     inline CoinBigIndex size() const {
121          return sizeFactor_;
122     }
123     /// Return sparseFactor
124     inline longDouble * sparseFactor() const {
125          return sparseFactor_;
126     }
127     /// Return diagonal
128     inline longDouble * diagonal() const {
129          return diagonal_;
130     }
131     /// Return workDouble
132     inline longDouble * workDouble() const {
133          return workDouble_;
134     }
135     /// If KKT on
136     inline bool kkt() const {
137          return doKKT_;
138     }
139     /// Set KKT
140     inline void setKKT(bool yesNo) {
141          doKKT_ = yesNo;
142     }
143     /// Set integer parameter
144     inline void setIntegerParameter(int i, int value) {
145          integerParameters_[i] = value;
146     }
147     /// get integer parameter
148     inline int getIntegerParameter(int i) {
149          return integerParameters_[i];
150     }
151     /// Set double parameter
152     inline void setDoubleParameter(int i, double value) {
153          doubleParameters_[i] = value;
154     }
155     /// get double parameter
156     inline double getDoubleParameter(int i) {
157          return doubleParameters_[i];
158     }
159     //@}
160
161
162public:
163
164     /**@name Constructors, destructor
165      */
166     //@{
167     /** Constructor which has dense columns activated.
168         Default is off. */
169     ClpCholeskyBase(int denseThreshold = -1);
170     /** Destructor (has to be public) */
171     virtual ~ClpCholeskyBase();
172     /// Copy
173     ClpCholeskyBase(const ClpCholeskyBase&);
174     /// Assignment
175     ClpCholeskyBase& operator=(const ClpCholeskyBase&);
176     //@}
177     //@{
178     ///@name Other
179     /// Clone
180     virtual ClpCholeskyBase * clone() const;
181
182     /// Returns type
183     inline int type() const {
184          if (doKKT_) return 100;
185          else return type_;
186     }
187protected:
188     /// Sets type
189     inline void setType(int type) {
190          type_ = type;
191     }
192     /// model.
193     inline void setModel(ClpInterior * model) {
194          model_ = model;
195     }
196     //@}
197
198     /**@name Symbolic, factor and solve */
199     //@{
200     /** Symbolic1  - works out size without clever stuff.
201         Uses upper triangular as much easier.
202         Returns size
203      */
204     int symbolic1(const CoinBigIndex * Astart, const int * Arow);
205     /** Symbolic2  - Fills in indices
206         Uses lower triangular so can do cliques etc
207      */
208     void symbolic2(const CoinBigIndex * Astart, const int * Arow);
209     /** Factorize - filling in rowsDropped and returning number dropped
210         in integerParam.
211      */
212     void factorizePart2(int * rowsDropped) ;
213     /** solve - 1 just first half, 2 just second half - 3 both.
214     If 1 and 2 then diagonal has sqrt of inverse otherwise inverse
215     */
216     void solve(CoinWorkDouble * region, int type);
217     /// Forms ADAT - returns nonzero if not enough memory
218     int preOrder(bool lowerTriangular, bool includeDiagonal, bool doKKT);
219     /// Updates dense part (broken out for profiling)
220     void updateDense(longDouble * d, /*longDouble * work,*/ int * first);
221     //@}
222
223protected:
224     /**@name Data members
225        The data members are protected to allow access for derived classes. */
226     //@{
227     /// type (may be useful) if > 20 do KKT
228     int type_;
229     /// Doing full KKT (only used if default symbolic and factorization)
230     bool doKKT_;
231     /// Go dense at this fraction
232     double goDense_;
233     /// choleskyCondition.
234     double choleskyCondition_;
235     /// model.
236     ClpInterior * model_;
237     /// numberTrials.  Number of trials before rejection
238     int numberTrials_;
239     /// numberRows.  Number of Rows in factorization
240     int numberRows_;
241     /// status.  Status of factorization
242     int status_;
243     /// rowsDropped
244     char * rowsDropped_;
245     /// permute inverse.
246     int * permuteInverse_;
247     /// main permute.
248     int * permute_;
249     /// numberRowsDropped.  Number of rows gone
250     int numberRowsDropped_;
251     /// sparseFactor.
252     longDouble * sparseFactor_;
253     /// choleskyStart - element starts
254     CoinBigIndex * choleskyStart_;
255     /// choleskyRow (can be shorter than sparsefactor)
256     int * choleskyRow_;
257     /// Index starts
258     CoinBigIndex * indexStart_;
259     /// Diagonal
260     longDouble * diagonal_;
261     /// double work array
262     longDouble * workDouble_;
263     /// link array
264     int * link_;
265     // Integer work array
266     CoinBigIndex * workInteger_;
267     // Clique information
268     int * clique_;
269     /// sizeFactor.
270     CoinBigIndex sizeFactor_;
271     /// Size of index array
272     CoinBigIndex sizeIndex_;
273     /// First dense row
274     int firstDense_;
275     /// integerParameters
276     int integerParameters_[64];
277     /// doubleParameters;
278     double doubleParameters_[64];
279     /// Row copy of matrix
280     ClpMatrixBase * rowCopy_;
281     /// Dense indicators
282     char * whichDense_;
283     /// Dense columns (updated)
284     longDouble * denseColumn_;
285     /// Dense cholesky
286     ClpCholeskyDense * dense_;
287     /// Dense threshold (for taking out of Cholesky)
288     int denseThreshold_;
289     //@}
290};
291
292#endif
Note: See TracBrowser for help on using the repository browser.