Scippy

SoPlex

Sequential object-oriented simPlex

slinsolver.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the class library */
4 /* SoPlex --- the Sequential object-oriented simPlex. */
5 /* */
6 /* Copyright (C) 1996-2022 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SoPlex is distributed under the terms of the ZIB Academic Licence. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SoPlex; see the file COPYING. If not email to soplex@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file slinsolver.h
17  * @brief Sparse Linear Solver virtual base class.
18  */
19 #ifndef _SLINSOLVER_H_
20 #define _SLINSOLVER_H_
21 
22 
23 #include <assert.h>
24 #include <string.h>
25 
26 #include "soplex/spxdefines.h"
27 #include "soplex/svector.h"
28 #include "soplex/ssvector.h"
29 #include "soplex/dsvector.h"
30 #include "soplex/didxset.h"
31 
32 namespace soplex
33 {
34 /**@brief Sparse Linear Solver virtual base class.
35  @ingroup Algo
36 
37  Class SLinSolver provides a class for solving sparse linear systems with
38  a matrix \f$A\f$ and arbitrary right-hand side vectors. For doing so, the
39  matrix must be first #load%ed to an #SLinSolver object as an array of
40  pointers to the \em column \ref SVectorBase<R> "SVectors" of this matrix.
41 */
42 template <class R>
43 class SLinSolver
44 {
45 public:
46 
47  //---------------------------------------
48  /**@name Types */
49  ///@{
50  /// status flags of the SLinSolver class.
51  enum Status
52  {
53  /** The SLinSolver is ready for solving linear systems with the
54  loaded matrix */
55  OK = 0,
56  /** The loaded matrix allows only for instable solutions to be
57  computed */
58  INSTABLE = 1,
59  /// The loaded matrix is singular.
60  SINGULAR = 2,
61  /// No matrix has yet been loaded.
62  UNLOADED = 4,
63  /// An error has occurred.
64  ERROR = 8
65  };
66  ///@}
67 
68  //---------------------------------------
69  /**@name Miscellaneous */
70  ///@{
71  /// returns the name of the SLinSolver.
72  virtual const char* getName() const = 0;
73 
74  /// returns the Status of the SLinSolver.
75  virtual Status status() const = 0;
76 
77  /// unloads any matrix.
78  virtual void clear() = 0;
79 
80  /// returns current memory consumption.
81  virtual int memory() const = 0;
82 
83  /// returns dimension of loaded matrix.
84  virtual int dim() const = 0;
85 
86  /// loads \p dim column vectors \p vec into the solver.
87  /** Initializes SLinSolver for the solution of linear systems
88  with the matrix consisting of \p dim column vectors given in \p vec.
89  */
90  virtual Status load(const SVectorBase<R>* vec[], int dim) = 0;
91 
92  /// returns a stability number (0: singularity, 1: perfect stability).
93  /** Returns a stability parameter between 0 and 1, where 0 indicates
94  singularity, while 1 indicates perfect stability.
95  */
96  virtual R stability() const = 0;
97 
98  /// return estimate for the condition number based on the diagonal of U
99  virtual R matrixMetric(int type = 0) const = 0;
100 
101  /// returns statistical information in form of a string.
102  virtual std::string statistics() const = 0;
103 
104  /// Substitute column \p idx with \p subst.
105  /** The change method is used to modify the loaded matrix by substituting
106  column \p idx with the new vector \p subst. One may also pass the
107  optional parameter \p eta to the solution of #solveRight() if
108  readily availabble. This may improve on the performance of the update.
109  */
110  virtual Status change(int idx, const SVectorBase<R>& subst, const SSVectorBase<R>* eta = 0) = 0;
111 
112  /// consistency check.
113  virtual bool isConsistent() const = 0;
114 
115  /// get number of factorizations
116  virtual int getFactorCount() const = 0;
117  ///@}
118 
119 
120  /**@name Solving linear systems
121  For solving linear systems with an SLinSolver object, it must
122  have previously been loaded with the matrix to use.
123 
124  Two types of systems can be solved \f$A x = b\f$ and \f$x^T A = b^T\f$.
125  Method names related to the first and second type are solveRight() and
126  solveLeft(), respectively.
127 
128  The methods receive their right hand-side vector \f$b\f$ as a
129  \c const parameter, that will hence be unchanged after termination.
130 
131  Some methods are available with two parameters for right hand-side
132  vectors. Then two system are solved in one method invocation. This
133  should generally be faster than solving two systems seperately.
134 
135  The result vector(s) are allways given as the first parameter(s). Two
136  types of result vectors are supported, VectorBase<R> and SSVectorBase<R> .
137  */
138  ///@{
139  /// Solves \f$Ax=b\f$.
140  virtual void solveRight(VectorBase<R>& x, const VectorBase<R>& b) /* const */ = 0;
141  /// Solves \f$Ax=b\f$.
142  virtual void solveRight(SSVectorBase<R>& x, const SSVectorBase<R>& b) /* const */ = 0;
143  virtual void solveRight(SSVectorBase<R>& x, const SVectorBase<R>& b) /* const */ = 0;
144 
145  /** @brief Solves \f$Ax=b\f$.
146  Possibly sets up internal data structures suitable for an optimized
147  subsequent change() call with \f$b\f$ as entering column.
148  */
149  virtual void solveRight4update(SSVectorBase<R>& x, const SVectorBase<R>& b) = 0;
150 
151  /// Solves \f$Ax=b\f$ and \f$Ay=d\f$.
152  virtual void solve2right4update(SSVectorBase<R>& x,
153  VectorBase<R>& y,
154  const SVectorBase<R>& b,
155  SSVectorBase<R>& d) = 0;
156  /// sparse version of solving two systems of equations
157  virtual void solve2right4update(SSVectorBase<R>& x,
158  SSVectorBase<R>& y,
159  const SVectorBase<R>& b,
160  SSVectorBase<R>& d) = 0;
161  /// Solves \f$Ax=b\f$, \f$Ay=d\f$ and \f$Az=e\f$.
162  virtual void solve3right4update(SSVectorBase<R>& x,
163  VectorBase<R>& y,
164  VectorBase<R>& z,
165  const SVectorBase<R>& b,
166  SSVectorBase<R>& d,
167  SSVectorBase<R>& e) = 0;
168  /// sparse version of solving three systems of equations
169  virtual void solve3right4update(SSVectorBase<R>& x,
170  SSVectorBase<R>& y,
171  SSVectorBase<R>& z,
172  const SVectorBase<R>& b,
173  SSVectorBase<R>& d,
174  SSVectorBase<R>& e) = 0;
175  /// solves \f$x^TA=b^T\f$.
176  virtual void solveLeft(VectorBase<R>& x, const VectorBase<R>& b) /* const */ = 0;
177  virtual void solveLeft(SSVectorBase<R>& x, const SSVectorBase<R>& b) /* const */ = 0;
178  /// sparse version of solving one system of equations with transposed basis matrix
179  virtual void solveLeft(SSVectorBase<R>& x, const SVectorBase<R>& b) /* const */ = 0;
180  /// solves \f$x^TA=b^T\f$ and \f$x^TA=rhs2^T\f$ internally using \f$rhs2\f$.
181  virtual void solveLeft(SSVectorBase<R>& x,
182  VectorBase<R>& two,
183  const SVectorBase<R>& b,
184  SSVectorBase<R>& rhs2) /* const */ = 0;
185  /// sparse version of solving two systems of equations with transposed basis matrix
186  virtual void solveLeft(SSVectorBase<R>& x,
187  SSVectorBase<R>& two,
188  const SVectorBase<R>& b,
189  SSVectorBase<R>& rhs2) /* const */ = 0;
190  /// solves \f$x^TA=b^T\f$, \f$y^TA=d^T\f$ and \f$z^TA=e^T\f$
191  virtual void solveLeft(SSVectorBase<R>& x, VectorBase<R>& y, VectorBase<R>& z,
192  const SVectorBase<R>& b, SSVectorBase<R>& d, SSVectorBase<R>& e) = 0;
193  /// sparse version of solving three systems of equations with transposed basis matrix
195  const SVectorBase<R>& b, SSVectorBase<R>& d, SSVectorBase<R>& e) = 0;
196  ///@}
197 
198 
199  //---------------------------------------
200  /**@name Constructors / Destructors */
201  ///@{
202  /// default constructor
204  : spxout(0)
205  {}
206  /// destructor
207  virtual ~SLinSolver()
208  {}
209  /// clone function for polymorphism
210  virtual SLinSolver<R>* clone() const = 0;
211  ///@}
212 
213  /// message handler
215 
216 
217 };
218 
219 } // namespace soplex
220 #endif // _SLINSOLVER_H_
virtual void solveRight(VectorBase< R > &x, const VectorBase< R > &b)=0
Solves .
virtual void clear()=0
unloads any matrix.
SPxOut * spxout
message handler
Definition: slinsolver.h:214
Dense vector.Class VectorBase provides dense linear algebra vectors. Internally, VectorBase wraps std...
Definition: dsvectorbase.h:28
virtual std::string statistics() const =0
returns statistical information in form of a string.
virtual SLinSolver< R > * clone() const =0
clone function for polymorphism
virtual int dim() const =0
returns dimension of loaded matrix.
Dymnamic index set.
virtual void solveRight4update(SSVectorBase< R > &x, const SVectorBase< R > &b)=0
Solves . Possibly sets up internal data structures suitable for an optimized subsequent change() call...
virtual R stability() const =0
returns a stability number (0: singularity, 1: perfect stability).
virtual R matrixMetric(int type=0) const =0
return estimate for the condition number based on the diagonal of U
Sparse Linear Solver virtual base class.Class SLinSolver provides a class for solving sparse linear s...
Definition: dsvectorbase.h:30
virtual Status load(const SVectorBase< R > *vec[], int dim)=0
loads dim column vectors vec into the solver.
Semi sparse vector.This class implements semi-sparse vectors. Such are VectorBases where the indices ...
Definition: dsvectorbase.h:29
virtual int getFactorCount() const =0
get number of factorizations
virtual Status status() const =0
returns the Status of the SLinSolver.
Wrapper for several output streams. A verbosity level is used to decide which stream to use and wheth...
Definition: spxout.h:63
Sparse vectors.
Semi sparse vector.
virtual bool isConsistent() const =0
consistency check.
Debugging, floating point type and parameter definitions.
virtual Status change(int idx, const SVectorBase< R > &subst, const SSVectorBase< R > *eta=0)=0
Substitute column idx with subst.
Everything should be within this namespace.
virtual int memory() const =0
returns current memory consumption.
An error has occurred.
Definition: slinsolver.h:64
virtual void solveLeft(VectorBase< R > &x, const VectorBase< R > &b)=0
solves .
virtual const char * getName() const =0
returns the name of the SLinSolver.
Dynamic sparse vectors.
virtual ~SLinSolver()
destructor
Definition: slinsolver.h:207
SLinSolver()
default constructor
Definition: slinsolver.h:203
virtual void solve2right4update(SSVectorBase< R > &x, VectorBase< R > &y, const SVectorBase< R > &b, SSVectorBase< R > &d)=0
Solves and .
Sparse vectors.Class SVectorBase provides packed sparse vectors. Such are a sparse vectors...
Definition: ssvectorbase.h:34
The loaded matrix is singular.
Definition: slinsolver.h:60
Status
status flags of the SLinSolver class.
Definition: slinsolver.h:51
No matrix has yet been loaded.
Definition: slinsolver.h:62
virtual void solve3right4update(SSVectorBase< R > &x, VectorBase< R > &y, VectorBase< R > &z, const SVectorBase< R > &b, SSVectorBase< R > &d, SSVectorBase< R > &e)=0
Solves , and .