LinearSolver.h
Go to the documentation of this file.
1 /*
2  * LinearSolver.h
3  *
4  * Created on: 30.10.2014
5  * Author: Michael Wegner (michael.wegner@student.kit.edu)
6  */
7
8 #ifndef LINEARSOLVER_H_
9 #define LINEARSOLVER_H_
10
11 #include "../algebraic/Vector.h"
12 #include "../graph/Graph.h"
13 #include <limits>
14
15 namespace NetworKit {
16
17
19 struct SolverStatus {
20  count numIters; // number of iterations needed during solve phase
21  double residual; // absolute final residual
22  bool converged; // flag of conversion status
23 };
24
28 template<class Matrix>
29 class LinearSolver {
30 protected:
31  double tolerance;
32
33 public:
39  LinearSolver(const double tolerance) : tolerance(tolerance) {}
40  virtual ~LinearSolver() = default;
41
46  virtual void setup(const Matrix& matrix) = 0;
47
52  virtual void setup(const Graph& graph);
53
58  virtual void setupConnected(const Matrix& matrix) = 0;
59
64  virtual void setupConnected(const Graph& graph);
65
74  virtual SolverStatus solve(const Vector& rhs, Vector& result, count maxConvergenceTime = 5 * 60 * 1000, count maxIterations = std::numeric_limits<count>::max()) = 0;
75
86  virtual void parallelSolve(const std::vector<Vector>& rhs, std::vector<Vector>& results, count maxConvergenceTime = 5 * 60 * 1000, count maxIterations = std::numeric_limits<count>::max());
87 };
88
89 template<class Matrix>
90 void LinearSolver<Matrix>::setup(const Graph& graph) {
91  setup(Matrix::laplacianMatrix(graph));
92 }
93
94 template<class Matrix>
96  setupConnected(Matrix::laplacianMatrix(graph));
97 }
98
99 template<class Matrix>
100 void LinearSolver<Matrix>::parallelSolve(const std::vector<Vector>& rhs, std::vector<Vector>& results, count maxConvergenceTime, count maxIterations) {
101  for (index i = 0; i < rhs.size(); ++i) {
102  solve(rhs[i], results[i], maxConvergenceTime, maxIterations);
103  }
104 }
105
106 } /* namespace NetworKit */
107
108 #endif /* LINEARSOLVER_H_ */
bool converged
Definition: LinearSolver.h:22
uint64_t index
Typedefs.
Definition: Globals.h:20
count numIters
Definition: LinearSolver.h:20
LinearSolver(const double tolerance)
Construct an abstract solver with the given tolerance.
Definition: LinearSolver.h:39
virtual void setupConnected(const Matrix &matrix)=0
Sets the solver up for the specified matrix where the underlying graph has to be connected.
virtual void parallelSolve(const std::vector< Vector > &rhs, std::vector< Vector > &results, count maxConvergenceTime=5 *60 *1000, count maxIterations=std::numeric_limits< count >::max())
Abstract parallel solve function that computes the results for the matrix currently setup and the rig...
Definition: LinearSolver.h:100
Describes the status of a LinearSolver after the solver finished.
Definition: LinearSolver.h:19
virtual void setup(const Matrix &matrix)=0
Sets the solver up for the specified matrix.
uint64_t count
Definition: Globals.h:21
std::vector< std::vector< count > > Matrix
Definition: DynamicNMIDistance.h:16
Abstract base class for solvers that solve linear systems.
Definition: LinearSolver.h:29
double tolerance
Definition: LinearSolver.h:31
The Vector class represents a basic vector with double coefficients.
Definition: Vector.h:25
double residual
Definition: LinearSolver.h:21
A graph (with optional weights) and parallel iterator methods.
Definition: Graph.h:79
virtual SolverStatus solve(const Vector &rhs, Vector &result, count maxConvergenceTime=5 *60 *1000, count maxIterations=std::numeric_limits< count >::max())=0
Abstract solve function that computes result for the given right-hand side rhs and the matrix that ha...
virtual ~LinearSolver()=default