Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Bdd.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4
11
12namespace storm {
13namespace logic {
14enum class ComparisonType;
15}
16
17namespace dd {
18template<DdType LibraryType, typename ValueType>
19class Add;
20
21class Odd;
22
23template<DdType LibraryType>
24class Bdd : public Dd<LibraryType> {
25 public:
26 friend class DdManager<LibraryType>;
27
28 template<DdType LibraryTypePrime, typename ValueTypePrime>
29 friend class Add;
30
38 Bdd(DdManager<LibraryType> const& ddManager, InternalBdd<LibraryType> const& internalBdd,
39 std::set<storm::expressions::Variable> const& containedMetaVariables = std::set<storm::expressions::Variable>());
40
41 // Instantiate all copy/move constructors/assignments with the default implementation.
42 Bdd() = default;
43 Bdd(Bdd<LibraryType> const& other) = default;
44 Bdd& operator=(Bdd<LibraryType> const& other) = default;
45 Bdd(Bdd<LibraryType>&& other) = default;
46 Bdd& operator=(Bdd<LibraryType>&& other) = default;
47
56 static Bdd<LibraryType> getEncoding(DdManager<LibraryType> const& ddManager, uint64_t targetOffset, storm::dd::Odd const& odd,
57 std::set<storm::expressions::Variable> const& metaVariables);
58
67 static Bdd<LibraryType> fromVector(DdManager<LibraryType> const& ddManager, storm::storage::BitVector const& truthValues, storm::dd::Odd const& odd,
68 std::set<storm::expressions::Variable> const& metaVariables);
69
80 template<typename ValueType>
81 static Bdd<LibraryType> fromVector(DdManager<LibraryType> const& ddManager, std::vector<ValueType> const& explicitValues, storm::dd::Odd const& odd,
82 std::set<storm::expressions::Variable> const& metaVariables, storm::logic::ComparisonType comparisonType,
83 ValueType value);
84
91 bool operator==(Bdd<LibraryType> const& other) const;
92
99 bool operator!=(Bdd<LibraryType> const& other) const;
100
110 Bdd<LibraryType> ite(Bdd<LibraryType> const& thenBdd, Bdd<LibraryType> const& elseBdd) const;
111
120 template<typename ValueType>
122
129 Bdd<LibraryType> operator||(Bdd<LibraryType> const& other) const;
130
138
145 Bdd<LibraryType> operator&&(Bdd<LibraryType> const& other) const;
146
154
161 Bdd<LibraryType> iff(Bdd<LibraryType> const& other) const;
162
170
177 Bdd<LibraryType> implies(Bdd<LibraryType> const& other) const;
178
185
192
198 Bdd<LibraryType> existsAbstract(std::set<storm::expressions::Variable> const& metaVariables) const;
199
207 Bdd<LibraryType> existsAbstractRepresentative(std::set<storm::expressions::Variable> const& metaVariables) const;
208
214 Bdd<LibraryType> universalAbstract(std::set<storm::expressions::Variable> const& metaVariables) const;
215
224 Bdd<LibraryType> andExists(Bdd<LibraryType> const& other, std::set<storm::expressions::Variable> const& existentialVariables) const;
225
234 Bdd<LibraryType> constrain(Bdd<LibraryType> const& constraint) const;
235
244 Bdd<LibraryType> restrict(Bdd<LibraryType> const& constraint) const;
245
256 Bdd<LibraryType> relationalProduct(Bdd<LibraryType> const& relation, std::set<storm::expressions::Variable> const& rowMetaVariables,
257 std::set<storm::expressions::Variable> const& columnMetaVariables) const;
258
269 Bdd<LibraryType> inverseRelationalProduct(Bdd<LibraryType> const& relation, std::set<storm::expressions::Variable> const& rowMetaVariables,
270 std::set<storm::expressions::Variable> const& columnMetaVariables) const;
271
283 std::set<storm::expressions::Variable> const& rowMetaVariables,
284 std::set<storm::expressions::Variable> const& columnMetaVariables) const;
285
293 Bdd<LibraryType> swapVariables(std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& metaVariablePairs) const;
294
304 Bdd<LibraryType> renameVariables(std::set<storm::expressions::Variable> const& from, std::set<storm::expressions::Variable> const& to) const;
305
317 Bdd<LibraryType> renameVariablesAbstract(std::set<storm::expressions::Variable> const& from, std::set<storm::expressions::Variable> const& to) const;
318
330 Bdd<LibraryType> renameVariablesConcretize(std::set<storm::expressions::Variable> const& from, std::set<storm::expressions::Variable> const& to) const;
331
337 bool isOne() const;
338
344 bool isZero() const;
345
351 template<typename ValueType>
353
357 std::vector<Bdd<LibraryType>> split(std::set<storm::expressions::Variable> const& variables) const;
358
367
375 std::pair<std::vector<storm::expressions::Expression>, std::unordered_map<uint_fast64_t, storm::expressions::Variable>> toExpression(
377
378 virtual Bdd<LibraryType> getSupport() const override;
379
380 virtual uint_fast64_t getNonZeroCount() const override;
381
382 virtual uint_fast64_t getLeafCount() const override;
383
384 virtual uint_fast64_t getNodeCount() const override;
385
386 virtual uint_fast64_t getIndex() const override;
387
388 virtual uint_fast64_t getLevel() const override;
389
390 virtual void exportToDot(std::string const& filename, bool showVariablesIfPossible = true) const override;
391
392 virtual void exportToText(std::string const& filename) const override;
393
401 static Bdd<LibraryType> getCube(DdManager<LibraryType> const& manager, std::set<storm::expressions::Variable> const& metaVariables);
402
408 Odd createOdd() const;
409
417 template<typename ValueType>
418 std::vector<ValueType> filterExplicitVector(Odd const& odd, std::vector<ValueType> const& values) const;
419
428
433
434 friend struct std::hash<storm::dd::Bdd<LibraryType>>;
435
436 template<DdType LibraryTypePrime, typename ValueType>
437 friend struct FromVectorHelper;
438
439 private:
440 // The internal BDD that depends on the chosen library.
441 InternalBdd<LibraryType> internalBdd;
442};
443} // namespace dd
444} // namespace storm
445
446namespace std {
447template<storm::dd::DdType LibraryType>
448struct hash<storm::dd::Bdd<LibraryType>> {
449 std::size_t operator()(storm::dd::Bdd<LibraryType> const& key) const {
450 return std::hash<storm::dd::InternalBdd<LibraryType>>().operator()(key.internalBdd);
451 }
452};
453} // namespace std
Bdd< LibraryType > renameVariablesAbstract(std::set< storm::expressions::Variable > const &from, std::set< storm::expressions::Variable > const &to) const
Renames the given meta variables in the BDD.
Definition Bdd.cpp:371
virtual uint_fast64_t getLevel() const override
Retrieves the level of the topmost variable in the DD.
Definition Bdd.cpp:531
static Bdd< LibraryType > fromVector(DdManager< LibraryType > const &ddManager, storm::storage::BitVector const &truthValues, storm::dd::Odd const &odd, std::set< storm::expressions::Variable > const &metaVariables)
Constructs a BDD representation of all encodings whose value is true in the given list of truth value...
Definition Bdd.cpp:79
Bdd< LibraryType > existsAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Existentially abstracts from the given meta variables.
Definition Bdd.cpp:172
Bdd< LibraryType > inverseRelationalProduct(Bdd< LibraryType > const &relation, std::set< storm::expressions::Variable > const &rowMetaVariables, std::set< storm::expressions::Variable > const &columnMetaVariables) const
Computes the inverse relational product of the current BDD and the given BDD representing a relation.
Definition Bdd.cpp:240
bool isZero() const
Retrieves whether this DD represents the constant zero function.
Definition Bdd.cpp:541
virtual uint_fast64_t getNonZeroCount() const override
Retrieves the number of encodings that are mapped to a non-zero value.
Definition Bdd.cpp:507
bool operator!=(Bdd< LibraryType > const &other) const
Retrieves whether the two BDDs represent different functions.
Definition Bdd.cpp:102
virtual uint_fast64_t getIndex() const override
Retrieves the index of the topmost variable in the DD.
Definition Bdd.cpp:526
Bdd< LibraryType > & operator&=(Bdd< LibraryType > const &other)
Performs a logical and of the current and the given BDD and assigns it to the current BDD.
Definition Bdd.cpp:139
std::pair< std::vector< storm::expressions::Expression >, std::unordered_map< uint_fast64_t, storm::expressions::Variable > > toExpression(storm::expressions::ExpressionManager &manager) const
Translates the function the BDD is representing to a set of expressions that characterize the functio...
Definition Bdd.cpp:496
Bdd< LibraryType > andExists(Bdd< LibraryType > const &other, std::set< storm::expressions::Variable > const &existentialVariables) const
Computes the logical and of the current and the given BDD and existentially abstracts from the given ...
Definition Bdd.cpp:190
static Bdd< LibraryType > getEncoding(DdManager< LibraryType > const &ddManager, uint64_t targetOffset, storm::dd::Odd const &odd, std::set< storm::expressions::Variable > const &metaVariables)
Constructs the BDD representation of the encoding with the given offset.
Definition Bdd.cpp:88
virtual uint_fast64_t getNodeCount() const override
Retrieves the number of nodes necessary to represent the DD.
Definition Bdd.cpp:521
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 & operator=(Bdd< LibraryType > &&other)=default
Bdd & operator=(Bdd< LibraryType > const &other)=default
Bdd< LibraryType > & complement()
Logically complements the current BDD.
Definition Bdd.cpp:166
Odd createOdd() const
Creates an ODD based on the current BDD.
Definition Bdd.cpp:565
Bdd< LibraryType > operator&&(Bdd< LibraryType > const &other) const
Performs a logical and of the current and the given BDD.
Definition Bdd.cpp:134
storm::storage::BitVector toVector(storm::dd::Odd const &rowOdd) const
Converts the BDD to a bit vector.
Definition Bdd.cpp:491
Bdd< LibraryType > existsAbstractRepresentative(std::set< storm::expressions::Variable > const &metaVariables) const
Similar to existsAbstract, but does not abstract from the variables but rather picks a valuation of e...
Definition Bdd.cpp:178
static Bdd< LibraryType > getCube(DdManager< LibraryType > const &manager, std::set< storm::expressions::Variable > const &metaVariables)
Retrieves the cube of all given meta variables.
Definition Bdd.cpp:556
Bdd< LibraryType > universalAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Universally abstracts from the given meta variables.
Definition Bdd.cpp:184
virtual Bdd< LibraryType > getSupport() const override
Retrieves the support of the current DD.
Definition Bdd.cpp:502
Bdd< LibraryType > constrain(Bdd< LibraryType > const &constraint) const
Computes the constraint of the current BDD with the given constraint.
Definition Bdd.cpp:204
Bdd< LibraryType > & operator|=(Bdd< LibraryType > const &other)
Performs a logical or of the current and the given BDD and assigns it to the current BDD.
Definition Bdd.cpp:127
std::vector< Bdd< LibraryType > > split(std::set< storm::expressions::Variable > const &variables) const
Splits the BDD along the given variables (must be at the top).
Definition Bdd.cpp:467
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
Bdd< LibraryType > operator!() const
Logically inverts the current BDD.
Definition Bdd.cpp:161
Add< LibraryType, ValueType > toAdd() const
Converts a BDD to an equivalent ADD.
Definition Bdd.cpp:462
Bdd< LibraryType > iff(Bdd< LibraryType > const &other) const
Performs a logical iff of the current and the given BDD.
Definition Bdd.cpp:146
virtual void exportToDot(std::string const &filename, bool showVariablesIfPossible=true) const override
Exports the DD to the given file in the dot format.
Definition Bdd.cpp:546
Bdd< LibraryType > renameVariables(std::set< storm::expressions::Variable > const &from, std::set< storm::expressions::Variable > const &to) const
Renames the given meta variables in the BDD.
Definition Bdd.cpp:341
Bdd< LibraryType > inverseRelationalProductWithExtendedRelation(Bdd< LibraryType > const &relation, std::set< storm::expressions::Variable > const &rowMetaVariables, std::set< storm::expressions::Variable > const &columnMetaVariables) const
Computes the inverse relational product of the current BDD and the given BDD representing a relation ...
Definition Bdd.cpp:267
bool isOne() const
Retrieves whether this DD represents the constant one function.
Definition Bdd.cpp:536
Bdd()=default
Bdd< LibraryType > exclusiveOr(Bdd< LibraryType > const &other) const
Performs a logical exclusive-or of the current and the given BDD.
Definition Bdd.cpp:151
Bdd< LibraryType > relationalProduct(Bdd< LibraryType > const &relation, std::set< storm::expressions::Variable > const &rowMetaVariables, std::set< storm::expressions::Variable > const &columnMetaVariables) const
Computes the relational product of the current BDD and the given BDD representing a relation.
Definition Bdd.cpp:214
virtual void exportToText(std::string const &filename) const override
Exports the DD to the given file in the dot format.
Definition Bdd.cpp:551
Bdd(Bdd< LibraryType > &&other)=default
Bdd< LibraryType > restrict(Bdd< LibraryType > const &constraint) const
Computes the restriction of the current BDD with the given constraint.
Definition Bdd.cpp:209
Bdd< LibraryType > implies(Bdd< LibraryType > const &other) const
Performs a logical implication of the current and the given BDD.
Definition Bdd.cpp:156
Bdd(Bdd< LibraryType > const &other)=default
Bdd< LibraryType > renameVariablesConcretize(std::set< storm::expressions::Variable > const &from, std::set< storm::expressions::Variable > const &to) const
Renames the given meta variables in the BDD.
Definition Bdd.cpp:416
InternalBdd< LibraryType > const & getInternalBdd() const
Retrieves the internal BDD.
Definition Bdd.cpp:570
std::vector< ValueType > filterExplicitVector(Odd const &odd, std::vector< ValueType > const &values) const
Filters the given explicit vector using the symbolic representation of which values to select.
Definition Bdd.cpp:576
bool operator==(Bdd< LibraryType > const &other) const
Retrieves whether the two BDDs represent the same function.
Definition Bdd.cpp:97
Bdd< LibraryType > operator||(Bdd< LibraryType > const &other) const
Performs a logical or of the current and the given BDD.
Definition Bdd.cpp:122
virtual uint_fast64_t getLeafCount() const override
Retrieves the number of leaves of the DD.
Definition Bdd.cpp:516
This class is responsible for managing a set of typed variables and all expressions using these varia...
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16