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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* 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_rational.h
* @brief Implementation of Sparse Linear Solver with Rational precision.
*/
#ifndef _SLUFACTOR_RATIONAL_H_
#define _SLUFACTOR_RATIONAL_H_
#include <assert.h>
#include "soplex/spxdefines.h"
#include "soplex/timerfactory.h"
#include "soplex/slinsolver_rational.h"
#include "soplex/clufactor_rational.h"
#include "soplex/rational.h"
namespace soplex
{
/// maximum nr. of factorization updates allowed before refactorization.
#define MAXUPDATES 1000
/**@brief Implementation of Sparse Linear Solver with Rational precision.
* @ingroup Algo
*
* This class implements a SLinSolverRational interface by using the sparse LU
* factorization implemented in CLUFactorRational.
*/
class SLUFactorRational : public SLinSolverRational, protected CLUFactorRational
{
public:
//--------------------------------
/**@name Types */
///@{
/// Specifies how to perform \ref soplex::SLUFactorRational::change "change" method.
enum UpdateType
{
ETA = 0, ///<
FOREST_TOMLIN ///<
};
/// for convenience
typedef SLinSolverRational::Status Status;
///@}
private:
//--------------------------------
/**@name Private data */
///@{
VectorRational vec; ///< Temporary vector
SSVectorRational ssvec; ///< Temporary semi-sparse vector
///@}
protected:
//--------------------------------
/**@name Protected data */
///@{
bool usetup; ///< TRUE iff update vector has been setup
UpdateType uptype; ///< the current \ref soplex::SLUFactor<R>::UpdateType "UpdateType".
SSVectorRational eta; ///<
SSVectorRational
forest; ///< ? Update vector set up by solveRight4update() and solve2right4update()
Rational lastThreshold; ///< pivoting threshold of last factorization
///@}
//--------------------------------
/**@name Control Parameters */
///@{
/// minimum threshold to use.
Rational minThreshold;
/// minimum stability to achieve by setting threshold.
Rational minStability;
/// Time spent in solves
Timer* solveTime;
Timer::TYPE timerType;
/// Number of solves
int solveCount;
///@}
protected:
//--------------------------------
/**@name Protected helpers */
///@{
///
void freeAll();
///
void changeEta(int idx, SSVectorRational& 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(const Rational& m)
{
if(m < 0.01)
{
minThreshold = 0.01;
lastThreshold = 0.01;
}
else if(m > 0.99)
{
minThreshold = 0.99;
lastThreshold = 0.99;
}
else
{
minThreshold = m;
lastThreshold = m;
}
}
/// returns Markowitz threshold.
Rational markowitz()
{
return lastThreshold;
}
///@}
//--------------------------------
/**@name Derived from SLinSolverRational
See documentation of \ref soplex::SLinSolverRational "SLinSolverRational" for a
documentation of these methods.
*/
///@{
///
void clear();
///
int dim() const
{
return thedim;
}
///
int memory() const
{
return nzCnt + l.start[l.firstUnused];
}
///
const char* getName() const
{
return (uptype == SLUFactorRational::ETA) ? "SLU-Eta" : "SLU-Forest-Tomlin";
}
///
Status status() const
{
return Status(stat);
}
///
Rational stability() const;
///
std::string statistics() const;
///
Status load(const SVectorRational* vec[], int dim);
///@}
public:
//--------------------------------
/**@name Solve */
///@{
/// Solves \f$Ax=b\f$.
void solveRight(VectorRational& x, const VectorRational& b);
/// Solves \f$Ax=b\f$.
void solveRight(SSVectorRational& x, const SVectorRational& b);
/// Solves \f$Ax=b\f$.
void solveRight4update(SSVectorRational& x, const SVectorRational& b);
/// Solves \f$Ax=b\f$ and \f$Ay=d\f$.
void solve2right4update(SSVectorRational& x, VectorRational& y, const SVectorRational& b,
SSVectorRational& d);
/// Solves \f$Ax=b\f$, \f$Ay=d\f$ and \f$Az=e\f$.
void solve3right4update(SSVectorRational& x, VectorRational& y, VectorRational& z,
const SVectorRational& b, SSVectorRational& d, SSVectorRational& e);
/// Solves \f$Ax=b\f$.
void solveLeft(VectorRational& x, const VectorRational& b);
/// Solves \f$Ax=b\f$.
void solveLeft(SSVectorRational& x, const SVectorRational& b);
/// Solves \f$Ax=b\f$ and \f$Ay=d\f$.
void solveLeft(SSVectorRational& x, VectorRational& y, const SVectorRational& b,
SSVectorRational& d);
/// Solves \f$Ax=b\f$, \f$Ay=d\f$ and \f$Az=e\f$.
void solveLeft(SSVectorRational& x, VectorRational& y, VectorRational& z,
const SVectorRational& b, SSVectorRational& d, SSVectorRational& e);
///
Status change(int idx, const SVectorRational& subst, const SSVectorRational* eta = 0);
///@}
//--------------------------------
/**@name Miscellaneous */
///@{
/// time spent in factorizations
Real getFactorTime() const
{
return factorTime->time();
}
/// set time limit on factorization
void setTimeLimit(const Real limit)
{
timeLimit = limit;
}
/// reset FactorTime
void resetFactorTime()
{
factorTime->reset();
}
/// number of factorizations performed
int getFactorCount() const
{
return factorCount;
}
/// time spent in solves
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()
{
factorTime->reset();
solveTime->reset();
factorCount = 0;
solveCount = 0;
}
/// prints the LU factorization to stdout.
void dump() const;
/// consistency check.
bool isConsistent() const;
///@}
//------------------------------------
/**@name Constructors / Destructors */
///@{
/// default constructor.
SLUFactorRational()
: CLUFactorRational()
, vec(1)
, ssvec(1)
, usetup(false)
, uptype(FOREST_TOMLIN)
, eta(1)
, forest(1)
, minThreshold(0.01)
, timerType(Timer::USER_TIME)
{
row.perm = 0;
row.orig = 0;
col.perm = 0;
col.orig = 0;
u.row.elem = 0;
u.row.idx = 0;
u.row.start = 0;
u.row.len = 0;
u.row.max = 0;
u.col.elem = 0;
u.col.idx = 0;
u.col.start = 0;
u.col.len = 0;
u.col.max = 0;
l.idx = 0;
l.start = 0;
l.row = 0;
l.ridx = 0;
l.rbeg = 0;
l.rorig = 0;
l.rperm = 0;
nzCnt = 0;
thedim = 0;
try
{
solveTime = TimerFactory::createTimer(timerType);
factorTime = TimerFactory::createTimer(timerType);
spx_alloc(row.perm, thedim);
spx_alloc(row.orig, thedim);
spx_alloc(col.perm, thedim);
spx_alloc(col.orig, thedim);
diag.reDim(thedim);
work = vec.get_ptr();
u.row.used = 0;
spx_alloc(u.row.elem, thedim);
u.row.val.reDim(1);
spx_alloc(u.row.idx, u.row.val.dim());
spx_alloc(u.row.start, thedim + 1);
spx_alloc(u.row.len, thedim + 1);
spx_alloc(u.row.max, thedim + 1);
u.row.list.idx = thedim;
u.row.start[thedim] = 0;
u.row.max [thedim] = 0;
u.row.len [thedim] = 0;
u.col.size = 1;
u.col.used = 0;
spx_alloc(u.col.elem, thedim);
spx_alloc(u.col.idx, u.col.size);
spx_alloc(u.col.start, thedim + 1);
spx_alloc(u.col.len, thedim + 1);
spx_alloc(u.col.max, thedim + 1);
u.col.val.reDim(0);
u.col.list.idx = thedim;
u.col.start[thedim] = 0;
u.col.max[thedim] = 0;
u.col.len[thedim] = 0;
l.val.reDim(1);
spx_alloc(l.idx, l.val.dim());
l.startSize = 1;
l.firstUpdate = 0;
l.firstUnused = 0;
spx_alloc(l.start, l.startSize);
spx_alloc(l.row, l.startSize);
}
catch(const SPxMemoryException& x)
{
freeAll();
throw x;
}
l.rval.reDim(0);
l.ridx = 0;
l.rbeg = 0;
l.rorig = 0;
l.rperm = 0;
SLUFactorRational::clear(); // clear() is virtual
factorCount = 0;
timeLimit = -1.0;
solveCount = 0;
assert(row.perm != 0);
assert(row.orig != 0);
assert(col.perm != 0);
assert(col.orig != 0);
assert(u.row.elem != 0);
assert(u.row.idx != 0);
assert(u.row.start != 0);
assert(u.row.len != 0);
assert(u.row.max != 0);
assert(u.col.elem != 0);
assert(u.col.idx != 0);
assert(u.col.start != 0);
assert(u.col.len != 0);
assert(u.col.max != 0);
assert(l.idx != 0);
assert(l.start != 0);
assert(l.row != 0);
assert(SLUFactorRational::isConsistent());
}
/// assignment operator.
SLUFactorRational& operator=(const SLUFactorRational& old)
{
if(this != &old)
{
// we don't need to copy them, because they are temporary vectors
vec.clear();
ssvec.clear();
eta = old.eta;
forest = old.forest;
freeAll();
try
{
assign(old);
}
catch(const SPxMemoryException& x)
{
freeAll();
throw x;
}
assert(isConsistent());
}
return *this;
}
/// copy constructor.
SLUFactorRational(const SLUFactorRational& old)
: SLinSolverRational(old)
, CLUFactorRational()
, vec(1) // we don't need to copy it, because they are temporary vectors
, ssvec(1) // we don't need to copy it, because they are temporary vectors
, usetup(old.usetup)
, eta(old.eta)
, forest(old.forest)
, timerType(old.timerType)
{
row.perm = 0;
row.orig = 0;
col.perm = 0;
col.orig = 0;
u.row.elem = 0;
u.row.idx = 0;
u.row.start = 0;
u.row.len = 0;
u.row.max = 0;
u.col.elem = 0;
u.col.idx = 0;
u.col.start = 0;
u.col.len = 0;
u.col.max = 0;
l.idx = 0;
l.start = 0;
l.row = 0;
l.ridx = 0;
l.rbeg = 0;
l.rorig = 0;
l.rperm = 0;
solveCount = 0;
solveTime = TimerFactory::createTimer(timerType);
factorTime = TimerFactory::createTimer(timerType);
try
{
assign(old);
}
catch(const SPxMemoryException& x)
{
freeAll();
throw x;
}
assert(SLUFactorRational::isConsistent());
}
/// destructor.
virtual ~SLUFactorRational();
/// clone function for polymorphism
inline virtual SLinSolverRational* clone() const
{
return new SLUFactorRational(*this);
}
///@}
private:
//------------------------------------
/**@name Private helpers */
///@{
/// used to implement the assignment operator
void assign(const SLUFactorRational& old);
///@}
};
} // namespace soplex
#include "slufactor_rational.hpp"
#endif // _SLUFACTOR_RATIONAL_H_