1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* This file is part of the class library */
/* SoPlex --- the Sequential object-oriented simPlex. */
/* */
/* Copyright 1996-2022 Zuse Institute Berlin */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
/* You may obtain a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* */
/* You should have received a copy of the Apache-2.0 license */
/* along with SoPlex; see the file LICENSE. If not email to soplex@zib.de. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**@file slufactor.h
* @brief Implementation of Sparse Linear Solver.
*/
#ifndef _SLUFACTOR_H_
#define _SLUFACTOR_H_
#include <assert.h>
#include "soplex/spxdefines.h"
#include "soplex/timerfactory.h"
#include "soplex/slinsolver.h"
#include "soplex/clufactor.h"
namespace soplex
{
/// maximum nr. of factorization updates allowed before refactorization.
#define MAXUPDATES 1000
/**@brief Implementation of Sparse Linear Solver.
* @ingroup Algo
*
* This class implements a SLinSolver interface by using the sparse LU
* factorization implemented in CLUFactor.
*/
template <class R>
class SLUFactor : public SLinSolver<R>, protected CLUFactor<R>
{
public:
//--------------------------------
/**@name Types */
///@{
/// Specifies how to perform \ref soplex::SLUFactor<R>::change "change" method.
enum UpdateType
{
ETA = 0, ///<
FOREST_TOMLIN ///<
};
/// for convenience
using Status = typename SLinSolver<R>::Status;
///@}
private:
//--------------------------------
/**@name Private data */
///@{
VectorBase<R> vec; ///< Temporary VectorBase<R>
SSVectorBase<R> ssvec; ///< Temporary semi-sparse VectorBase<R>
///@}
protected:
//--------------------------------
/**@name Protected data */
///@{
bool usetup; ///< TRUE iff update vector has been setup
UpdateType uptype; ///< the current \ref soplex::SLUFactor<R>::UpdateType "UpdateType".
SSVectorBase<R> eta; ///<
SSVectorBase<R>
forest; ///< ? Update VectorBase<R> set up by solveRight4update() and solve2right4update()
R lastThreshold; ///< pivoting threshold of last factorization
///@}
//--------------------------------
/**@name Control Parameters */
///@{
/// minimum threshold to use.
R minThreshold;
/// minimum stability to achieve by setting threshold.
R minStability;
/// |x| < epsililon is considered to be 0.
R epsilon;
/// Time spent in solves
Timer* solveTime;
Timer::TYPE timerType;
/// Number of solves
int solveCount;
///@}
protected:
//--------------------------------
/**@name Protected helpers */
///@{
///
void freeAll();
///
void changeEta(int idx, SSVectorBase<R>& eta);
///@}
public:
//--------------------------------
/**@name Update type */
///@{
/// returns the current update type uptype.
UpdateType utype() const
{
return uptype;
}
/// sets update type.
/** The new UpdateType becomes valid only after the next call to
method load().
*/
void setUtype(UpdateType tp)
{
uptype = tp;
}
/// sets minimum Markowitz threshold.
void setMarkowitz(R m)
{
if(m < 0.0001)
m = 0.0001;
if(m > 0.9999)
m = 0.9999;
minThreshold = m;
lastThreshold = m;
}
/// returns Markowitz threshold.
R markowitz()
{
return lastThreshold;
}
///@}
//--------------------------------
/**@name Derived from SLinSolver
See documentation of \ref soplex::SLinSolver "SLinSolver" for a
documentation of these methods.
*/
///@{
///
void clear();
///
int dim() const
{
return this->thedim;
}
///
int memory() const
{
return this->nzCnt + this->l.start[this->l.firstUnused];
}
///
const char* getName() const
{
return (uptype == SLUFactor<R>::ETA) ? "SLU-Eta" : "SLU-Forest-Tomlin";
}
///
Status status() const
{
return Status(this->stat);
}
///
R stability() const;
/** return one of several matrix metrics based on the diagonal of U
* 0: condition number estimate by ratio of min/max
* 1: trace (sum of diagonal elements)
* 2: determinant (product of diagonal elements)
*/
R matrixMetric(int type = 0) const;
///
std::string statistics() const;
///
Status load(const SVectorBase<R>* vec[], int dim);
///@}
public:
//--------------------------------
/**@name Solve */
///@{
/// Solves \f$Ax=b\f$.
void solveRight(VectorBase<R>& x, const VectorBase<R>& b);
void solveRight(SSVectorBase<R>& x, const SSVectorBase<R>& b)
{
x.unSetup();
solveRight((VectorBase<R>&) x, (const VectorBase<R>&) b);
}
/// Solves \f$Ax=b\f$.
void solveRight(SSVectorBase<R>& x, const SVectorBase<R>& b);
/// Solves \f$Ax=b\f$.
void solveRight4update(SSVectorBase<R>& x, const SVectorBase<R>& b);
/// Solves \f$Ax=b\f$ and \f$Ay=d\f$.
void solve2right4update(SSVectorBase<R>& x, VectorBase<R>& y, const SVectorBase<R>& b,
SSVectorBase<R>& d);
/// Sparse version of solving two systems of equations
void solve2right4update(SSVectorBase<R>& x, SSVectorBase<R>& y, const SVectorBase<R>& b,
SSVectorBase<R>& d);
/// Solves \f$Ax=b\f$, \f$Ay=d\f$ and \f$Az=e\f$.
void solve3right4update(SSVectorBase<R>& x, VectorBase<R>& y, VectorBase<R>& z,
const SVectorBase<R>& b, SSVectorBase<R>& d, SSVectorBase<R>& e);
/// sparse version of solving three systems of equations
void solve3right4update(SSVectorBase<R>& x, SSVectorBase<R>& y, SSVectorBase<R>& z,
const SVectorBase<R>& b, SSVectorBase<R>& d, SSVectorBase<R>& e);
/// sparse version of solving one system of equations with transposed basis matrix
void solveLeft(VectorBase<R>& x, const VectorBase<R>& b);
void solveLeft(SSVectorBase<R>& x, const SSVectorBase<R>& b)
{
x.unSetup();
solveLeft((VectorBase<R>&) x, (const VectorBase<R>&) b);
}
/// Solves \f$Ax=b\f$.
void solveLeft(SSVectorBase<R>& x, const SVectorBase<R>& b);
/// Solves \f$Ax=b\f$ and \f$Ay=d\f$.
void solveLeft(SSVectorBase<R>& x, VectorBase<R>& y, const SVectorBase<R>& b, SSVectorBase<R>& d);
/// sparse version of solving two systems of equations with transposed basis matrix
void solveLeft(SSVectorBase<R>& x, SSVectorBase<R>& two, const SVectorBase<R>& b,
SSVectorBase<R>& rhs2);
/// Solves \f$Ax=b\f$, \f$Ay=d\f$ and \f$Az=e\f$.
void solveLeft(SSVectorBase<R>& x, VectorBase<R>& y, VectorBase<R>& z,
const SVectorBase<R>& b, SSVectorBase<R>& d, SSVectorBase<R>& e);
/// sparse version of solving three systems of equations with transposed basis matrix
void solveLeft(SSVectorBase<R>& x, SSVectorBase<R>& y, SSVectorBase<R>& z,
const SVectorBase<R>& b, SSVectorBase<R>& d, SSVectorBase<R>& e);
///
Status change(int idx, const SVectorBase<R>& subst, const SSVectorBase<R>* eta = 0);
///@}
//--------------------------------
/**@name Miscellaneous */
///@{
/// time spent in factorizations
// @todo fix the return type from of the type form Real to a cpp time (Refactoring) TODO
Real getFactorTime() const
{
return this->factorTime->time();
}
/// reset FactorTime
void resetFactorTime()
{
this->factorTime->reset();
}
/// number of factorizations performed
int getFactorCount() const
{
return this->factorCount;
}
/// time spent in solves
// @todo fix the return type of time to a cpp time type TODO
Real getSolveTime() const
{
return solveTime->time();
}
/// reset SolveTime
void resetSolveTime()
{
solveTime->reset();
}
/// number of solves performed
int getSolveCount() const
{
return solveCount;
}
/// reset timers and counters
void resetCounters()
{
this->factorTime->reset();
solveTime->reset();
this->factorCount = 0;
this->hugeValues = 0;
solveCount = 0;
}
void changeTimer(const Timer::TYPE ttype)
{
solveTime = TimerFactory::switchTimer(solveTime, ttype);
this->factorTime = TimerFactory::switchTimer(this->factorTime, ttype);
timerType = ttype;
}
/// prints the LU factorization to stdout.
void dump() const;
/// consistency check.
bool isConsistent() const;
///@}
//------------------------------------
/**@name Constructors / Destructors */
///@{
/// default constructor.
SLUFactor<R>();
/// assignment operator.
SLUFactor<R>& operator=(const SLUFactor<R>& old);
/// copy constructor.
SLUFactor<R>(const SLUFactor<R>& old);
/// destructor.
virtual ~SLUFactor<R>();
/// clone function for polymorphism
inline virtual SLinSolver<R>* clone() const
{
return new SLUFactor<R>(*this);
}
///@}
private:
//------------------------------------
/**@name Private helpers */
///@{
/// used to implement the assignment operator
void assign(const SLUFactor<R>& old);
///@}
};
} // namespace soplex
#include "slufactor.hpp"
#endif // _SLUFACTOR_H_