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-2017 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 "spxdefines.h"
27 #include "svector.h"
28 #include "ssvector.h"
29 #include "dsvector.h"
30 #include "dvector.h"
31 #include "didxset.h"
32 
33 namespace soplex
34 {
35 /**@brief Sparse Linear Solver virtual base class.
36  @ingroup Algo
37 
38  Class SLinSolver provides a class for solving sparse linear systems with
39  a matrix \f$A\f$ and arbitrary right-hand side vectors. For doing so, the
40  matrix must be first #load%ed to an #SLinSolver object as an array of
41  pointers to the \em column \ref SVector "SVectors" of this matrix.
42 */
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 SVector* 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 Real stability() const = 0;
97 
98  /// return estimate for the condition number based on the diagonal of U
99  virtual Real conditionEstimate(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 SVector& subst, const SSVector* 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, Vector and SSVector.
137  */
138  //@{
139  /// Solves \f$Ax=b\f$.
140  virtual void solveRight (Vector& x, const Vector& b) /* const */ = 0;
141  /// Solves \f$Ax=b\f$.
142  virtual void solveRight (SSVector& x, const SVector& b) /* const */ = 0;
143 
144  /** @brief Solves \f$Ax=b\f$.
145  Possibly sets up internal data structures suitable for an optimized
146  subsequent change() call with \f$b\f$ as entering column.
147  */
148  virtual void solveRight4update(SSVector& x, const SVector& b) = 0;
149 
150  /// Solves \f$Ax=b\f$ and \f$Ay=d\f$.
151  virtual void solve2right4update(SSVector& x,
152  Vector& y,
153  const SVector& b,
154  SSVector& d ) = 0;
155  /// sparse version of solving two systems of equations
156  virtual void solve2right4update(SSVector& x,
157  SSVector& y,
158  const SVector& b,
159  SSVector& d ) = 0;
160  /// Solves \f$Ax=b\f$, \f$Ay=d\f$ and \f$Az=e\f$.
161  virtual void solve3right4update(SSVector& x,
162  Vector& y,
163  Vector& z,
164  const SVector& b,
165  SSVector& d,
166  SSVector& e) = 0;
167  /// sparse version of solving three systems of equations
168  virtual void solve3right4update(SSVector& x,
169  SSVector& y,
170  SSVector& z,
171  const SVector& b,
172  SSVector& d,
173  SSVector& e) = 0;
174  /// solves \f$x^TA=b^T\f$.
175  virtual void solveLeft (Vector& x, const Vector& b) /* const */ = 0;
176  /// sparse version of solving one system of equations with transposed basis matrix
177  virtual void solveLeft (SSVector& x, const SVector& b) /* const */ = 0;
178  /// solves \f$x^TA=b^T\f$ and \f$x^TA=rhs2^T\f$ internally using \f$rhs2\f$.
179  virtual void solveLeft (SSVector& x,
180  Vector& two,
181  const SVector& b,
182  SSVector& rhs2) /* const */ = 0;
183  /// sparse version of solving two systems of equations with transposed basis matrix
184  virtual void solveLeft (SSVector& x,
185  SSVector& two,
186  const SVector& b,
187  SSVector& rhs2) /* const */ = 0;
188  /// solves \f$x^TA=b^T\f$, \f$y^TA=d^T\f$ and \f$z^TA=e^T\f$
189  virtual void solveLeft (SSVector& x, Vector& y, Vector& z,
190  const SVector& b, SSVector& d, SSVector& e) = 0;
191  /// sparse version of solving three systems of equations with transposed basis matrix
192  virtual void solveLeft (SSVector& x, SSVector& y, SSVector& z,
193  const SVector& b, SSVector& d, SSVector& e) = 0;
194  //@}
195 
196 
197  //---------------------------------------
198  /**@name Constructors / Destructors */
199  //@{
200  /// default constructor
202  : spxout(0)
203  {}
204  /// destructor
205  virtual ~SLinSolver()
206  {}
207  /// clone function for polymorphism
208  virtual SLinSolver* clone() const = 0;
209  //@}
210 
211  /// message handler
213 
214 
215 };
216 
217 } // namespace soplex
218 #endif // _SLINSOLVER_H_
virtual Real conditionEstimate(int type=0) const =0
return estimate for the condition number based on the diagonal of U
virtual Status change(int idx, const SVector &subst, const SSVector *eta=0)=0
Substitute column idx with subst.
virtual Status load(const SVector *vec[], int dim)=0
loads dim column vectors vec into the solver.
virtual void clear()=0
unloads any matrix.
SPxOut * spxout
message handler
Definition: slinsolver.h:212
virtual std::string statistics() const =0
returns statistical information in form of a string.
virtual void solveRight(Vector &x, const Vector &b)=0
Solves .
virtual int dim() const =0
returns dimension of loaded matrix.
Dymnamic index set.
virtual void solve3right4update(SSVector &x, Vector &y, Vector &z, const SVector &b, SSVector &d, SSVector &e)=0
Solves , and .
Sparse Linear Solver virtual base class.Class SLinSolver provides a class for solving sparse linear s...
Definition: slinsolver.h:43
virtual int getFactorCount() const =0
get number of factorizations
virtual Real stability() const =0
returns a stability number (0: singularity, 1: perfect stability).
virtual Status status() const =0
returns the Status of the SLinSolver.
double Real
Definition: spxdefines.h:215
virtual SLinSolver * clone() const =0
clone function for polymorphism
virtual void solveLeft(Vector &x, const Vector &b)=0
solves .
Dynamic vectors.
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.
Everything should be within this namespace.
virtual int memory() const =0
returns current memory consumption.
An error has occurred.
Definition: slinsolver.h:64
virtual const char * getName() const =0
returns the name of the SLinSolver.
Dynamic sparse vectors.
virtual ~SLinSolver()
destructor
Definition: slinsolver.h:205
SLinSolver()
default constructor
Definition: slinsolver.h:201
The loaded matrix is singular.
Definition: slinsolver.h:60
virtual void solve2right4update(SSVector &x, Vector &y, const SVector &b, SSVector &d)=0
Solves and .
Status
status flags of the SLinSolver class.
Definition: slinsolver.h:51
No matrix has yet been loaded.
Definition: slinsolver.h:62
virtual void solveRight4update(SSVector &x, const SVector &b)=0
Solves . Possibly sets up internal data structures suitable for an optimized subsequent change() call...