Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
EliminationLinearEquationSolver.cpp
Go to the documentation of this file.
2
3#include <numeric>
4
7
10
11#include "storm/utility/graph.h"
15
16namespace storm {
17namespace solver {
18
19using namespace stateelimination;
21
22template<typename ValueType>
26
27template<typename ValueType>
31
32template<typename ValueType>
36
37template<typename ValueType>
39 this->A = &A;
40 localA.reset();
41 this->clearCache();
42}
43
44template<typename ValueType>
46 localA = std::make_unique<storm::storage::SparseMatrix<ValueType>>(std::move(A));
47 this->A = localA.get();
48 this->clearCache();
49}
50
51template<typename ValueType>
53 std::vector<ValueType> const& b) const {
54 // FIXME: This solver will not work for all input systems. More concretely, the current implementation will
55 // not work for systems that have a 1 on the diagonal. This is not a restriction of this technique in general
56 // but arbitrary matrices require pivoting, which is not currently implemented.
57
58 STORM_LOG_INFO("Solving linear equation system (" << x.size() << " rows) with elimination");
59
60 storm::storage::SparseMatrix<ValueType> const& transitionMatrix = localA ? *localA : *A;
61 storm::storage::SparseMatrix<ValueType> backwardTransitions = transitionMatrix.transpose();
62
63 // Initialize the solution to the right-hand side of the equation system.
64 x = b;
65
66 // Translate the matrix and its transpose into the flexible format.
67 storm::storage::FlexibleSparseMatrix<ValueType> flexibleMatrix(transitionMatrix, false);
68 storm::storage::FlexibleSparseMatrix<ValueType> flexibleBackwardTransitions(backwardTransitions, true);
69
70 boost::optional<std::vector<uint_fast64_t>> distanceBasedPriorities;
71
72 // TODO: get the order from the environment
75
77 // Since we have no initial states at this point, we determine a representative of every BSCC regarding
78 // the backward transitions, because this means that every row is reachable from this set of rows, which
79 // we require to make sure we cover every row.
80 storm::storage::BitVector initialRows = storm::utility::graph::getBsccCover(backwardTransitions);
81 distanceBasedPriorities = getDistanceBasedPriorities(transitionMatrix, backwardTransitions, initialRows, b,
83 }
84
85 std::shared_ptr<StatePriorityQueue> priorityQueue =
86 createStatePriorityQueue<ValueType>(distanceBasedPriorities, flexibleMatrix, flexibleBackwardTransitions, b, storm::storage::BitVector(x.size(), true));
87
88 // Create a state eliminator to perform the actual elimination.
89 PrioritizedStateEliminator<ValueType> eliminator(flexibleMatrix, flexibleBackwardTransitions, priorityQueue, x);
90
91 // Eliminate all states.
92 while (priorityQueue->hasNext()) {
93 auto state = priorityQueue->pop();
94 eliminator.eliminateState(state, false);
95 }
96
97 return true;
98}
99
100template<typename ValueType>
104
105template<typename ValueType>
107 return this->A->getRowCount();
108}
109
110template<typename ValueType>
111uint64_t EliminationLinearEquationSolver<ValueType>::getMatrixColumnCount() const {
112 return this->A->getColumnCount();
113}
114
115template<typename ValueType>
116std::unique_ptr<storm::solver::LinearEquationSolver<ValueType>> EliminationLinearEquationSolverFactory<ValueType>::create(Environment const& env) const {
117 return std::make_unique<storm::solver::EliminationLinearEquationSolver<ValueType>>();
118}
119
120template<typename ValueType>
121std::unique_ptr<LinearEquationSolverFactory<ValueType>> EliminationLinearEquationSolverFactory<ValueType>::clone() const {
122 return std::make_unique<EliminationLinearEquationSolverFactory<ValueType>>(*this);
123}
124
127
128#ifdef STORM_HAVE_CARL
129
132
135#endif
136} // namespace solver
137} // namespace storm
EliminationOrder
An enum that contains all available state elimination orders.
virtual std::unique_ptr< storm::solver::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.
A class that uses gaussian elimination to implement the LinearEquationSolver interface.
virtual LinearEquationSolverProblemFormat getEquationProblemFormat(Environment const &env) const override
Retrieves the format in which this solver expects to solve equations.
virtual void setMatrix(storm::storage::SparseMatrix< ValueType > const &A) override
virtual bool internalSolveEquations(Environment const &env, std::vector< ValueType > &x, std::vector< ValueType > const &b) const override
void eliminateState(storm::storage::sparse::state_type state, bool removeForwardTransitions)
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
The flexible sparse matrix is used during state elimination.
A class that holds a possibly non-square matrix in the compressed row storage format.
storm::storage::SparseMatrix< value_type > transpose(bool joinGroups=false, bool keepZeros=false) const
Transposes the matrix.
#define STORM_LOG_INFO(message)
Definition logging.h:29
SettingsType const & getModule()
Get module.
storm::storage::BitVector getBsccCover(storm::storage::SparseMatrix< T > const &transitionMatrix)
Retrieves a set of states that covers als BSCCs of the system in the sense that for every BSCC exactl...
Definition graph.cpp:129
bool eliminationOrderNeedsForwardDistances(storm::settings::modules::EliminationSettings::EliminationOrder const &order)
bool eliminationOrderNeedsDistances(storm::settings::modules::EliminationSettings::EliminationOrder const &order)
std::vector< uint_fast64_t > getDistanceBasedPriorities(storm::storage::SparseMatrix< ValueType > const &transitionMatrix, storm::storage::SparseMatrix< ValueType > const &transitionMatrixTransposed, storm::storage::BitVector const &initialStates, std::vector< ValueType > const &oneStepProbabilities, bool forward, bool reverse)
bool eliminationOrderNeedsReversedDistances(storm::settings::modules::EliminationSettings::EliminationOrder const &order)
LabParser.cpp.
Definition cli.cpp:18