Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SymbolicEliminationLinearEquationSolver.cpp
Go to the documentation of this file.
2
5
6#include "storm/utility/dd.h"
7
9
10namespace storm {
11namespace solver {
12
13template<storm::dd::DdType DdType, typename ValueType>
17
18template<storm::dd::DdType DdType, typename ValueType>
20 storm::dd::Add<DdType, ValueType> const& A, storm::dd::Bdd<DdType> const& allRows, std::set<storm::expressions::Variable> const& rowMetaVariables,
21 std::set<storm::expressions::Variable> const& columnMetaVariables,
22 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs)
23 : SymbolicEliminationLinearEquationSolver(allRows, rowMetaVariables, columnMetaVariables, rowColumnMetaVariablePairs) {
24 this->setMatrix(A);
25}
26
27template<storm::dd::DdType DdType, typename ValueType>
29 storm::dd::Bdd<DdType> const& allRows, std::set<storm::expressions::Variable> const& rowMetaVariables,
30 std::set<storm::expressions::Variable> const& columnMetaVariables,
31 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs)
32 : SymbolicLinearEquationSolver<DdType, ValueType>(allRows, rowMetaVariables, columnMetaVariables, rowColumnMetaVariablePairs) {
34}
35
36template<storm::dd::DdType DdType, typename ValueType>
39 storm::dd::Add<DdType, ValueType> const& b) const {
41
42 // Build diagonal BDD over new meta variables.
43 storm::dd::Bdd<DdType> diagonal = storm::utility::dd::getRowColumnDiagonal(ddManager, this->rowColumnMetaVariablePairs);
44 diagonal &= this->getAllRows();
45 diagonal = diagonal.swapVariables(this->oldNewMetaVariablePairs);
46
47 storm::dd::Add<DdType, ValueType> rowsAdd = this->getAllRows().swapVariables(rowRowMetaVariablePairs).template toAdd<ValueType>();
48 storm::dd::Add<DdType, ValueType> diagonalAdd = diagonal.template toAdd<ValueType>();
49
50 // Move the matrix to the new meta variables.
51 storm::dd::Add<DdType, ValueType> matrix = this->A.swapVariables(oldNewMetaVariablePairs);
52
53 // Initialize solution over the new meta variables.
54 storm::dd::Add<DdType, ValueType> solution = b.swapVariables(oldNewMetaVariablePairs);
55
56 // As long as there are transitions, we eliminate them.
57 uint64_t iterations = 0;
58 while (!matrix.isZero()) {
59 // Determine inverse loop probabilies.
60 storm::dd::Add<DdType, ValueType> inverseLoopProbabilities = rowsAdd / (rowsAdd - (diagonalAdd * matrix).sumAbstract(newColumnVariables));
61
62 // Scale all transitions with the inverse loop probabilities.
63 matrix *= inverseLoopProbabilities;
64
65 solution *= inverseLoopProbabilities;
66
67 // Delete diagonal elements, i.e. remove self-loops.
68 matrix = diagonal.ite(ddManager.template getAddZero<ValueType>(), matrix);
69
70 // Update the one-step probabilities.
71 solution += (matrix * solution.swapVariables(newRowColumnMetaVariablePairs)).sumAbstract(newColumnVariables);
72
73 // Shortcut all transitions by eliminating one intermediate step.
74 matrix = matrix.multiplyMatrix(matrix.permuteVariables(shiftMetaVariablePairs), newColumnVariables);
75 matrix = matrix.swapVariables(columnHelperMetaVariablePairs);
76
77 ++iterations;
78 STORM_LOG_TRACE("Completed iteration " << iterations << " of elimination process.");
79 }
80
81 STORM_LOG_INFO("Elimination completed in " << iterations << " iterations.");
82
83 return solution.swapVariables(rowRowMetaVariablePairs);
84}
85
86template<storm::dd::DdType DdType, typename ValueType>
90
91template<storm::dd::DdType DdType, typename ValueType>
93 storm::dd::Bdd<DdType> const& allRows, std::set<storm::expressions::Variable> const& rowMetaVariables,
94 std::set<storm::expressions::Variable> const& columnMetaVariables,
95 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs) {
96 storm::dd::DdManager<DdType>& ddManager = allRows.getDdManager();
97
98 // Create triple-layered meta variables for all original meta variables. We will use them later in the elimination process.
99 for (auto const& metaVariablePair : this->rowColumnMetaVariablePairs) {
100 auto rowVariable = metaVariablePair.first;
101
102 storm::dd::DdMetaVariable<DdType> const& metaVariable = ddManager.getMetaVariable(rowVariable);
103
104 std::vector<storm::expressions::Variable> newMetaVariables;
105
106 // Find a suitable name for the temporary variable.
107 uint64_t counter = 0;
108 std::string newMetaVariableName = "tmp_" + metaVariable.getName();
109 while (ddManager.hasMetaVariable(newMetaVariableName + std::to_string(counter))) {
110 ++counter;
111 }
112
113 newMetaVariables = ddManager.cloneVariable(metaVariablePair.first, newMetaVariableName + std::to_string(counter), 3);
114
115 newRowVariables.insert(newMetaVariables[0]);
116 newColumnVariables.insert(newMetaVariables[1]);
117 helperVariables.insert(newMetaVariables[2]);
118
119 newRowColumnMetaVariablePairs.emplace_back(newMetaVariables[0], newMetaVariables[1]);
120 columnHelperMetaVariablePairs.emplace_back(newMetaVariables[1], newMetaVariables[2]);
121
122 rowRowMetaVariablePairs.emplace_back(metaVariablePair.first, newMetaVariables[0]);
123 columnColumnMetaVariablePairs.emplace_back(metaVariablePair.second, newMetaVariables[1]);
124
125 oldToNewMapping.emplace_back(std::move(newMetaVariables));
126 }
127
128 oldNewMetaVariablePairs = rowRowMetaVariablePairs;
129 for (auto const& entry : columnColumnMetaVariablePairs) {
130 oldNewMetaVariablePairs.emplace_back(entry.first, entry.second);
131 }
132
133 shiftMetaVariablePairs = newRowColumnMetaVariablePairs;
134 for (auto const& entry : columnHelperMetaVariablePairs) {
135 shiftMetaVariablePairs.emplace_back(entry.first, entry.second);
136 }
137}
138
139template<storm::dd::DdType DdType, typename ValueType>
141 storm::dd::Bdd<DdType> const& allRows, std::set<storm::expressions::Variable> const& rowMetaVariables,
142 std::set<storm::expressions::Variable> const& columnMetaVariables,
143 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs) {
144 // Call superclass function.
145 SymbolicLinearEquationSolver<DdType, ValueType>::setData(allRows, rowMetaVariables, columnMetaVariables, rowColumnMetaVariablePairs);
146
147 // Now create new variables as needed.
148 this->createInternalData(this->getAllRows(), this->rowMetaVariables, this->columnMetaVariables, this->rowColumnMetaVariablePairs);
149}
150
151template<storm::dd::DdType DdType, typename ValueType>
152std::unique_ptr<storm::solver::SymbolicLinearEquationSolver<DdType, ValueType>> SymbolicEliminationLinearEquationSolverFactory<DdType, ValueType>::create(
153 Environment const& env) const {
154 return std::make_unique<SymbolicEliminationLinearEquationSolver<DdType, ValueType>>();
155}
156
162
168
169} // namespace solver
170} // namespace storm
Add< LibraryType, ValueType > swapVariables(std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &metaVariablePairs) const
Swaps the given pairs of meta variables in the ADD.
Definition Add.cpp:292
bool isZero() const
Retrieves whether this ADD represents the constant zero function.
Definition Add.cpp:532
Add< LibraryType, ValueType > multiplyMatrix(Add< LibraryType, ValueType > const &otherMatrix, std::set< storm::expressions::Variable > const &summationMetaVariables) const
Multiplies the current ADD (representing a matrix) with the given matrix by summing over the given me...
Definition Add.cpp:372
Add< LibraryType, ValueType > permuteVariables(std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &metaVariablePairs) const
Permutes the given pairs of meta variables in the ADD.
Definition Add.cpp:337
Bdd< LibraryType > swapVariables(std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &metaVariablePairs) const
Swaps the given pairs of meta variables in the BDD.
Definition Bdd.cpp:302
Bdd< LibraryType > ite(Bdd< LibraryType > const &thenBdd, Bdd< LibraryType > const &elseBdd) const
Performs an if-then-else with the given operands, i.e.
Definition Bdd.cpp:113
DdManager< LibraryType > & getDdManager() const
Retrieves the manager that is responsible for this DD.
Definition Dd.cpp:39
storm::expressions::Variable getMetaVariable(std::string const &variableName) const
Retrieves the given meta variable by name.
bool hasMetaVariable(std::string const &variableName) const
Retrieves whether the given meta variable name is already in use.
std::vector< storm::expressions::Variable > cloneVariable(storm::expressions::Variable const &variable, std::string const &newVariableName, boost::optional< uint64_t > const &numberOfLayers=boost::none)
Clones the given meta variable and optionally changes the number of layers of the variable.
std::string const & getName() const
Retrieves the name of the meta variable.
virtual std::unique_ptr< storm::solver::SymbolicLinearEquationSolver< DdType, ValueType > > create(Environment const &env) const override
virtual void setData(storm::dd::Bdd< DdType > const &allRows, std::set< storm::expressions::Variable > const &rowMetaVariables, std::set< storm::expressions::Variable > const &columnMetaVariables, std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &rowColumnMetaVariablePairs) override
virtual LinearEquationSolverProblemFormat getEquationProblemFormat(Environment const &env) const override
Retrieves the format in which this solver expects to solve equations.
SymbolicEliminationLinearEquationSolver()
Constructs a symbolic linear equation solver.
virtual storm::dd::Add< DdType, ValueType > solveEquations(Environment const &env, storm::dd::Add< DdType, ValueType > const &x, storm::dd::Add< DdType, ValueType > const &b) const override
Solves the equation system A*x = b.
An interface that represents an abstract symbolic linear equation solver.
virtual void setData(storm::dd::Bdd< DdType > const &allRows, std::set< storm::expressions::Variable > const &rowMetaVariables, std::set< storm::expressions::Variable > const &columnMetaVariables, std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &rowColumnMetaVariablePairs)
std::set< storm::expressions::Variable > columnMetaVariables
std::set< storm::expressions::Variable > rowMetaVariables
std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > rowColumnMetaVariablePairs
void setMatrix(storm::dd::Add< DdType, ValueType > const &newA)
#define STORM_LOG_INFO(message)
Definition logging.h:29
#define STORM_LOG_TRACE(message)
Definition logging.h:17
storm::dd::Bdd< Type > getRowColumnDiagonal(storm::dd::DdManager< Type > const &ddManager, std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &rowColumnMetaVariablePairs)
Definition dd.cpp:91
LabParser.cpp.
Definition cli.cpp:18