Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
LinearEquationSolver.cpp
Go to the documentation of this file.
2
17
18namespace storm {
19namespace solver {
20
21template<typename ValueType>
23 // Intentionally left empty.
24}
25
26template<typename ValueType>
27bool LinearEquationSolver<ValueType>::solveEquations(Environment const& env, std::vector<ValueType>& x, std::vector<ValueType> const& b) const {
28 return this->internalSolveEquations(env, x, b);
29}
30
31template<typename ValueType>
35
36template<typename ValueType>
38 if (cachingEnabled && !value) {
39 // caching will be turned off. Hence we clear the cache at this point
40 clearCache();
41 }
42 cachingEnabled = value;
43}
44
45template<typename ValueType>
47 return cachingEnabled;
48}
49
50template<typename ValueType>
52 cachedRowVector.reset();
53}
54
55template<typename ValueType>
56std::unique_ptr<LinearEquationSolver<ValueType>> LinearEquationSolverFactory<ValueType>::create(Environment const& env,
57 storm::storage::SparseMatrix<ValueType> const& matrix) const {
58 std::unique_ptr<LinearEquationSolver<ValueType>> solver = this->create(env);
59 solver->setMatrix(matrix);
60 return solver;
61}
62
63template<typename ValueType>
64std::unique_ptr<LinearEquationSolver<ValueType>> LinearEquationSolverFactory<ValueType>::create(Environment const& env,
66 std::unique_ptr<LinearEquationSolver<ValueType>> solver = this->create(env);
67 solver->setMatrix(std::move(matrix));
68 return solver;
69}
70
71template<typename ValueType>
73 return this->create(env)->getEquationProblemFormat(env);
74}
75
76template<typename ValueType>
78 return this->create(env)->getRequirements(env);
79}
80
81template<typename ValueType>
85
86template<>
87std::unique_ptr<LinearEquationSolver<storm::RationalNumber>> GeneralLinearEquationSolverFactory<storm::RationalNumber>::create(Environment const& env) const {
88 EquationSolverType type = env.solver().getLinearEquationSolverType();
89
90 // Adjust the solver type if it is not supported by this value type
91 if (type != EquationSolverType::Eigen && type != EquationSolverType::Topological && type != EquationSolverType::Acyclic &&
92 (env.solver().isLinearEquationSolverTypeSetFromDefaultValue() || type == EquationSolverType::Gmmxx)) {
93 STORM_LOG_INFO("Selecting '" + toString(EquationSolverType::Eigen) + "' as the linear equation solver since the previously selected one ("
94 << toString(type) << ") does not support exact computations.");
95 type = EquationSolverType::Eigen;
96 }
97
98 switch (type) {
99 case EquationSolverType::Native:
100 return std::make_unique<NativeLinearEquationSolver<storm::RationalNumber>>();
101 case EquationSolverType::Eigen:
102 return std::make_unique<EigenLinearEquationSolver<storm::RationalNumber>>();
103 case EquationSolverType::Elimination:
104 return std::make_unique<EliminationLinearEquationSolver<storm::RationalNumber>>();
105 case EquationSolverType::Topological:
106 return std::make_unique<TopologicalLinearEquationSolver<storm::RationalNumber>>();
107 case EquationSolverType::Acyclic:
108 return std::make_unique<AcyclicLinearEquationSolver<storm::RationalNumber>>();
109 default:
110 STORM_LOG_THROW(false, storm::exceptions::InvalidEnvironmentException, "Unknown solver type.");
111 return nullptr;
112 }
113}
114
115template<>
116std::unique_ptr<LinearEquationSolver<storm::RationalFunction>> GeneralLinearEquationSolverFactory<storm::RationalFunction>::create(
117 Environment const& env) const {
118 EquationSolverType type = env.solver().getLinearEquationSolverType();
119
120 // Adjust the solver type if it is not supported by this value type
121 if (type == EquationSolverType::Gmmxx || type == EquationSolverType::Native) {
123 STORM_LOG_INFO("Selecting '" + toString(EquationSolverType::Eigen) + "' as the linear equation solver since the previously selected one ("
124 << toString(type) << ") does not support parametric computations.");
125 } else {
126 // Be more verbose if the user set the solver explicitly
127 STORM_LOG_WARN("The selected linear equation solver (" << toString(type) << ") does not support parametric computations. Falling back to "
128 << toString(EquationSolverType::Eigen) << ".");
129 }
130 type = EquationSolverType::Eigen;
131 }
132
133 switch (type) {
134 case EquationSolverType::Eigen:
135 return std::make_unique<EigenLinearEquationSolver<storm::RationalFunction>>();
136 case EquationSolverType::Elimination:
137 return std::make_unique<EliminationLinearEquationSolver<storm::RationalFunction>>();
138 case EquationSolverType::Topological:
139 return std::make_unique<TopologicalLinearEquationSolver<storm::RationalFunction>>();
140 case EquationSolverType::Acyclic:
141 return std::make_unique<AcyclicLinearEquationSolver<storm::RationalFunction>>();
142 default:
143 STORM_LOG_THROW(false, storm::exceptions::InvalidEnvironmentException, "Unknown solver type.");
144 return nullptr;
145 }
146}
147
148template<typename ValueType>
149std::unique_ptr<LinearEquationSolver<ValueType>> GeneralLinearEquationSolverFactory<ValueType>::create(Environment const& env) const {
150 EquationSolverType type = env.solver().getLinearEquationSolverType();
151
152 if constexpr (std::is_same_v<ValueType, storm::Interval>) {
153 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "We have not implemented interval-based linear equation solvers");
154 }
155
156 // Adjust the solver type if none was specified and we want sound/exact computations
157 if (env.solver().isForceExact() && type != EquationSolverType::Native && type != EquationSolverType::Eigen && type != EquationSolverType::Elimination &&
158 type != EquationSolverType::Topological && type != EquationSolverType::Acyclic) {
160 type = EquationSolverType::Eigen;
162 "Selecting '" + toString(type) +
163 "' as the linear equation solver to guarantee exact results. If you want to override this, please explicitly specify a different solver.");
164 } else {
165 STORM_LOG_WARN("The selected solver does not yield exact results.");
166 }
167 } else if (env.solver().isForceSoundness() && type != EquationSolverType::Native && type != EquationSolverType::Eigen &&
168 type != EquationSolverType::Elimination && type != EquationSolverType::Topological && type != EquationSolverType::Acyclic) {
170 type = EquationSolverType::Native;
172 "Selecting '" + toString(type) +
173 "' as the linear equation solver to guarantee sound results. If you want to override this, please explicitly specify a different solver.");
174 } else {
175 STORM_LOG_WARN("The selected solver does not yield sound results.");
176 }
177 }
178
179 switch (type) {
180 case EquationSolverType::Gmmxx:
181 return std::make_unique<GmmxxLinearEquationSolver<ValueType>>();
182 case EquationSolverType::Native:
183 return std::make_unique<NativeLinearEquationSolver<ValueType>>();
184 case EquationSolverType::Eigen:
185 return std::make_unique<EigenLinearEquationSolver<ValueType>>();
186 case EquationSolverType::Elimination:
187 return std::make_unique<EliminationLinearEquationSolver<ValueType>>();
188 case EquationSolverType::Topological:
189 return std::make_unique<TopologicalLinearEquationSolver<ValueType>>();
190 case EquationSolverType::Acyclic:
191 return std::make_unique<AcyclicLinearEquationSolver<ValueType>>();
192 default:
193 STORM_LOG_THROW(false, storm::exceptions::InvalidEnvironmentException, "Unknown solver type.");
194 return nullptr;
195 }
196}
197
198template<typename ValueType>
199std::unique_ptr<LinearEquationSolverFactory<ValueType>> GeneralLinearEquationSolverFactory<ValueType>::clone() const {
200 return std::make_unique<GeneralLinearEquationSolverFactory<ValueType>>(*this);
201}
202
203template class LinearEquationSolver<double>;
206
210
214
215} // namespace solver
216} // namespace storm
SolverEnvironment & solver()
storm::solver::EquationSolverType const & getLinearEquationSolverType() const
bool isLinearEquationSolverTypeSetFromDefaultValue() const
virtual std::unique_ptr< LinearEquationSolver< ValueType > > create(Environment const &env) const override
Creates an equation solver with the current settings, but without a matrix.
virtual std::unique_ptr< LinearEquationSolverFactory< ValueType > > clone() const override
Creates a copy of this factory.
std::unique_ptr< LinearEquationSolver< ValueType > > create(Environment const &env, storm::storage::SparseMatrix< ValueType > const &matrix) const
Creates a new linear equation solver instance with the given matrix.
LinearEquationSolverRequirements getRequirements(Environment const &env) const
Retrieves the requirements of the solver if it was created with the current settings.
virtual LinearEquationSolverProblemFormat getEquationProblemFormat(Environment const &env) const
Retrieves the problem format that the solver expects if it was created with the current settings.
An interface that represents an abstract linear equation solver.
void setCachingEnabled(bool value) const
Sets whether some of the generated data during solver calls should be cached.
bool solveEquations(Environment const &env, std::vector< ValueType > &x, std::vector< ValueType > const &b) const
If the solver expects the equation system format, it solves Ax = b.
bool isCachingEnabled() const
Retrieves whether some of the generated data during solver calls should be cached.
virtual LinearEquationSolverRequirements getRequirements(Environment const &env) const
Retrieves the requirements of the solver under the current settings.
A class that holds a possibly non-square matrix in the compressed row storage format.
#define STORM_LOG_INFO(message)
Definition logging.h:24
#define STORM_LOG_WARN(message)
Definition logging.h:25
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
std::string toString(GurobiSolverMethod const &method)
Yields a string representation of the GurobiSolverMethod.