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