Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SymbolicEliminationLinearEquationSolver.cpp
Go to the documentation of this file.
2
6#include "storm/utility/dd.h"
7
8namespace storm {
9namespace solver {
10
11template<storm::dd::DdType DdType, typename ValueType>
15
16template<storm::dd::DdType DdType, typename ValueType>
18 storm::dd::Add<DdType, ValueType> const& A, storm::dd::Bdd<DdType> const& allRows, std::set<storm::expressions::Variable> const& rowMetaVariables,
19 std::set<storm::expressions::Variable> const& columnMetaVariables,
20 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs)
21 : SymbolicEliminationLinearEquationSolver(allRows, rowMetaVariables, columnMetaVariables, rowColumnMetaVariablePairs) {
22 this->setMatrix(A);
23}
24
25template<storm::dd::DdType DdType, typename ValueType>
27 storm::dd::Bdd<DdType> const& allRows, std::set<storm::expressions::Variable> const& rowMetaVariables,
28 std::set<storm::expressions::Variable> const& columnMetaVariables,
29 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs)
30 : SymbolicLinearEquationSolver<DdType, ValueType>(allRows, rowMetaVariables, columnMetaVariables, rowColumnMetaVariablePairs) {
32}
33
34template<storm::dd::DdType DdType, typename ValueType>
37 storm::dd::Add<DdType, ValueType> const& b) const {
39
40 // Build diagonal BDD over new meta variables.
41 storm::dd::Bdd<DdType> diagonal = storm::utility::dd::getRowColumnDiagonal(ddManager, this->rowColumnMetaVariablePairs);
42 diagonal &= this->getAllRows();
43 diagonal = diagonal.swapVariables(this->oldNewMetaVariablePairs);
44
45 storm::dd::Add<DdType, ValueType> rowsAdd = this->getAllRows().swapVariables(rowRowMetaVariablePairs).template toAdd<ValueType>();
46 storm::dd::Add<DdType, ValueType> diagonalAdd = diagonal.template toAdd<ValueType>();
47
48 // Move the matrix to the new meta variables.
49 storm::dd::Add<DdType, ValueType> matrix = this->A.swapVariables(oldNewMetaVariablePairs);
50
51 // Initialize solution over the new meta variables.
52 storm::dd::Add<DdType, ValueType> solution = b.swapVariables(oldNewMetaVariablePairs);
53
54 // As long as there are transitions, we eliminate them.
55 uint64_t iterations = 0;
56 while (!matrix.isZero()) {
57 // Determine inverse loop probabilies.
58 storm::dd::Add<DdType, ValueType> inverseLoopProbabilities = rowsAdd / (rowsAdd - (diagonalAdd * matrix).sumAbstract(newColumnVariables));
59
60 // Scale all transitions with the inverse loop probabilities.
61 matrix *= inverseLoopProbabilities;
62
63 solution *= inverseLoopProbabilities;
64
65 // Delete diagonal elements, i.e. remove self-loops.
66 matrix = diagonal.ite(ddManager.template getAddZero<ValueType>(), matrix);
67
68 // Update the one-step probabilities.
69 solution += (matrix * solution.swapVariables(newRowColumnMetaVariablePairs)).sumAbstract(newColumnVariables);
70
71 // Shortcut all transitions by eliminating one intermediate step.
72 matrix = matrix.multiplyMatrix(matrix.permuteVariables(shiftMetaVariablePairs), newColumnVariables);
73 matrix = matrix.swapVariables(columnHelperMetaVariablePairs);
74
75 ++iterations;
76 STORM_LOG_TRACE("Completed iteration " << iterations << " of elimination process.");
77 }
78
79 STORM_LOG_INFO("Elimination completed in " << iterations << " iterations.");
80
81 return solution.swapVariables(rowRowMetaVariablePairs);
82}
83
84template<storm::dd::DdType DdType, typename ValueType>
88
89template<storm::dd::DdType DdType, typename ValueType>
91 storm::dd::Bdd<DdType> const& allRows, std::set<storm::expressions::Variable> const& rowMetaVariables,
92 std::set<storm::expressions::Variable> const& columnMetaVariables,
93 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs) {
94 storm::dd::DdManager<DdType>& ddManager = allRows.getDdManager();
95
96 // Create triple-layered meta variables for all original meta variables. We will use them later in the elimination process.
97 for (auto const& metaVariablePair : this->rowColumnMetaVariablePairs) {
98 auto rowVariable = metaVariablePair.first;
99
100 storm::dd::DdMetaVariable<DdType> const& metaVariable = ddManager.getMetaVariable(rowVariable);
101
102 std::vector<storm::expressions::Variable> newMetaVariables;
103
104 // Find a suitable name for the temporary variable.
105 uint64_t counter = 0;
106 std::string newMetaVariableName = "tmp_" + metaVariable.getName();
107 while (ddManager.hasMetaVariable(newMetaVariableName + std::to_string(counter))) {
108 ++counter;
109 }
110
111 newMetaVariables = ddManager.cloneVariable(metaVariablePair.first, newMetaVariableName + std::to_string(counter), 3);
112
113 newRowVariables.insert(newMetaVariables[0]);
114 newColumnVariables.insert(newMetaVariables[1]);
115 helperVariables.insert(newMetaVariables[2]);
116
117 newRowColumnMetaVariablePairs.emplace_back(newMetaVariables[0], newMetaVariables[1]);
118 columnHelperMetaVariablePairs.emplace_back(newMetaVariables[1], newMetaVariables[2]);
119
120 rowRowMetaVariablePairs.emplace_back(metaVariablePair.first, newMetaVariables[0]);
121 columnColumnMetaVariablePairs.emplace_back(metaVariablePair.second, newMetaVariables[1]);
122
123 oldToNewMapping.emplace_back(std::move(newMetaVariables));
124 }
125
126 oldNewMetaVariablePairs = rowRowMetaVariablePairs;
127 for (auto const& entry : columnColumnMetaVariablePairs) {
128 oldNewMetaVariablePairs.emplace_back(entry.first, entry.second);
129 }
130
131 shiftMetaVariablePairs = newRowColumnMetaVariablePairs;
132 for (auto const& entry : columnHelperMetaVariablePairs) {
133 shiftMetaVariablePairs.emplace_back(entry.first, entry.second);
134 }
135}
136
137template<storm::dd::DdType DdType, typename ValueType>
139 storm::dd::Bdd<DdType> const& allRows, std::set<storm::expressions::Variable> const& rowMetaVariables,
140 std::set<storm::expressions::Variable> const& columnMetaVariables,
141 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs) {
142 // Call superclass function.
143 SymbolicLinearEquationSolver<DdType, ValueType>::setData(allRows, rowMetaVariables, columnMetaVariables, rowColumnMetaVariablePairs);
144
145 // Now create new variables as needed.
146 this->createInternalData(this->getAllRows(), this->rowMetaVariables, this->columnMetaVariables, this->rowColumnMetaVariablePairs);
147}
148
149template<storm::dd::DdType DdType, typename ValueType>
150std::unique_ptr<storm::solver::SymbolicLinearEquationSolver<DdType, ValueType>> SymbolicEliminationLinearEquationSolverFactory<DdType, ValueType>::create(
151 Environment const& env) const {
152 return std::make_unique<SymbolicEliminationLinearEquationSolver<DdType, ValueType>>();
153}
154
160
166
167} // namespace solver
168} // 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:285
bool isZero() const
Retrieves whether this ADD represents the constant zero function.
Definition Add.cpp:525
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:365
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:330
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:296
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:107
DdManager< LibraryType > & getDdManager() const
Retrieves the manager that is responsible for this DD.
Definition Dd.cpp:38
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:24
#define STORM_LOG_TRACE(message)
Definition logging.h:12
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:88