Storm 1.13.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
InternalSylvanBdd.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <memory>
5#include <unordered_map>
6#include <vector>
7
8#include "storm-config.h"
16
17namespace storm {
18namespace storage {
19class BitVector;
20}
21
22namespace dd {
23template<DdType LibraryType>
25
26class Odd;
27
28template<>
30 public:
31 template<DdType LibraryType, typename ValueType>
32 friend class InternalAdd;
33
34#ifdef STORM_HAVE_SYLVAN
35 InternalBdd(InternalDdManager<DdType::Sylvan> const* ddManager, sylvan::Bdd const& sylvanBdd);
36#endif
37
38 // Instantiate all copy/move constructors/assignments with the default implementation.
44
55 std::vector<uint_fast64_t> const& sortedDdVariableIndices,
56 std::function<bool(uint64_t)> const& filter);
57
64 bool operator==(InternalBdd<DdType::Sylvan> const& other) const;
65
72 bool operator!=(InternalBdd<DdType::Sylvan> const& other) const;
73
83 std::vector<InternalBdd<DdType::Sylvan>> const& columnVariables) const;
84
94 std::vector<InternalBdd<DdType::Sylvan>> const& rowVariables,
95 std::vector<InternalBdd<DdType::Sylvan>> const& columnVariables) const;
96
107 std::vector<InternalBdd<DdType::Sylvan>> const& rowVariables,
108 std::vector<InternalBdd<DdType::Sylvan>> const& columnVariables) const;
109
120
129 template<typename ValueType>
131 InternalAdd<DdType::Sylvan, ValueType> const& elseAdd) const;
132
140
148
156
164
172
180
188
195
202
209
218
225
234 InternalBdd<DdType::Sylvan> swapVariables(std::vector<InternalBdd<DdType::Sylvan>> const& from, std::vector<InternalBdd<DdType::Sylvan>> const& to) const;
235
244
254
264
271
278 uint_fast64_t getNonZeroCount(uint_fast64_t numberOfDdVariables) const;
279
285 uint_fast64_t getLeafCount() const;
286
292 uint_fast64_t getNodeCount() const;
293
299 bool isOne() const;
300
306 bool isZero() const;
307
313 uint_fast64_t getIndex() const;
314
320 uint_fast64_t getLevel() const;
321
328 void exportToDot(std::string const& filename, std::vector<std::string> const& ddVariableNamesAsStrings, bool showVariablesIfPossible = true) const;
329
335 void exportToText(std::string const& filename) const;
336
342 template<typename ValueType>
344
353 storm::storage::BitVector toVector(storm::dd::Odd const& rowOdd, std::vector<uint_fast64_t> const& ddVariableIndices) const;
354
362 std::pair<std::vector<storm::expressions::Expression>, std::unordered_map<uint_fast64_t, storm::expressions::Variable>> toExpression(
364
371 Odd createOdd(std::vector<uint_fast64_t> const& ddVariableIndices) const;
372
381 template<typename ValueType>
382 void filterExplicitVector(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices, std::vector<ValueType> const& sourceValues,
383 std::vector<ValueType>& targetValues) const;
384
393 void filterExplicitVector(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices, storm::storage::BitVector const& sourceValues,
394 storm::storage::BitVector& targetValues) const;
395
402 std::vector<InternalBdd<DdType::Sylvan>> splitIntoGroups(std::vector<uint_fast64_t> const& ddGroupVariableIndices) const;
403
404 friend struct std::hash<storm::dd::InternalBdd<storm::dd::DdType::Sylvan>>;
405
406#ifdef STORM_HAVE_SYLVAN
412 sylvan::Bdd& getSylvanBdd();
413
419 sylvan::Bdd const& getSylvanBdd() const;
420#endif
421
422 private:
423#ifdef STORM_HAVE_SYLVAN
435 static BDD fromVectorRec(uint_fast64_t& currentOffset, uint_fast64_t currentLevel, uint_fast64_t maxLevel, Odd const& odd,
436 std::vector<uint_fast64_t> const& ddVariableIndices, std::function<bool(uint64_t)> const& filter);
437
438 // Declare a hash functor that is used for the unique tables in the construction process of ODDs.
439 class HashFunctor {
440 public:
441 std::size_t operator()(std::pair<BDD, bool> const& key) const;
442 };
443
456 static std::shared_ptr<Odd> createOddRec(BDD dd, bool complement, uint_fast64_t currentLevel, uint_fast64_t maxLevel,
457 std::vector<uint_fast64_t> const& ddVariableIndices,
458 std::vector<std::unordered_map<std::pair<BDD, bool>, std::shared_ptr<Odd>, HashFunctor>>& uniqueTableForLevels);
459
472 void toVectorRec(BDD dd, storm::storage::BitVector& result, Odd const& rowOdd, bool complement, uint_fast64_t currentRowLevel, uint_fast64_t maxLevel,
473 uint_fast64_t currentRowOffset, std::vector<uint_fast64_t> const& ddRowVariableIndices) const;
474
488 template<typename ValueType>
489 static void filterExplicitVectorRec(BDD dd, uint_fast64_t currentLevel, bool complement, uint_fast64_t maxLevel,
490 std::vector<uint_fast64_t> const& ddVariableIndices, uint_fast64_t currentOffset, storm::dd::Odd const& odd,
491 std::vector<ValueType>& result, uint_fast64_t& currentIndex, std::vector<ValueType> const& values);
492
506 static void filterExplicitVectorRec(BDD dd, uint_fast64_t currentLevel, bool complement, uint_fast64_t maxLevel,
507 std::vector<uint_fast64_t> const& ddVariableIndices, uint_fast64_t currentOffset, storm::dd::Odd const& odd,
508 storm::storage::BitVector& result, uint_fast64_t& currentIndex, storm::storage::BitVector const& values);
509
527 static storm::expressions::Variable toExpressionRec(
528 BDD dd, storm::expressions::ExpressionManager& manager, std::vector<storm::expressions::Expression>& expressions,
529 std::unordered_map<uint_fast64_t, storm::expressions::Variable>& indexToVariableMap,
530 std::unordered_map<std::pair<uint_fast64_t, uint_fast64_t>, storm::expressions::Variable>& countIndexToVariablePair,
531 std::unordered_map<BDD, uint_fast64_t>& nodeToCounterMap, std::vector<uint_fast64_t>& nextCounterForIndex);
532
533 void splitIntoGroupsRec(BDD dd, std::vector<InternalBdd<DdType::Sylvan>>& groups, std::vector<uint_fast64_t> const& ddGroupVariableIndices,
534 uint_fast64_t currentLevel, uint_fast64_t maxLevel) const;
535
536 // The internal manager responsible for this BDD.
537 InternalDdManager<DdType::Sylvan> const* ddManager;
538
539 // The sylvan BDD.
540 sylvan::Bdd sylvanBdd;
541#endif
542};
543} // namespace dd
544} // namespace storm
545
546namespace std {
547template<>
548struct hash<storm::dd::InternalBdd<storm::dd::DdType::Sylvan>> {
549#ifdef STORM_HAVE_SYLVAN
551 return static_cast<std::size_t>(key.sylvanBdd.GetBDD());
552 }
553#else
555 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
556 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
557 "version of Storm with Sylvan support.");
558 }
559#endif
560};
561} // namespace std
InternalBdd< DdType::Sylvan > swapVariables(std::vector< InternalBdd< DdType::Sylvan > > const &from, std::vector< InternalBdd< DdType::Sylvan > > const &to) const
Swaps the given pairs of DD variables in the BDD.
InternalBdd< DdType::Sylvan > & operator|=(InternalBdd< DdType::Sylvan > const &other)
Performs a logical or of the current and the given BDD and assigns it to the current BDD.
InternalBdd< DdType::Sylvan > ite(InternalBdd< DdType::Sylvan > const &thenBdd, InternalBdd< DdType::Sylvan > const &elseBdd) const
Performs an if-then-else with the given operands, i.e.
InternalBdd< DdType::Sylvan > constrain(InternalBdd< DdType::Sylvan > const &constraint) const
Computes the constraint of the current BDD with the given constraint.
InternalBdd< DdType::Sylvan > operator||(InternalBdd< DdType::Sylvan > const &other) const
Performs a logical or of the current and the given BDD.
InternalAdd< DdType::Sylvan, ValueType > toAdd() const
Converts a BDD to an equivalent ADD.
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...
bool operator!=(InternalBdd< DdType::Sylvan > const &other) const
Retrieves whether the two BDDs represent different functions.
InternalBdd(InternalBdd< DdType::Sylvan > const &other)=default
InternalBdd< DdType::Sylvan > restrict(InternalBdd< DdType::Sylvan > const &constraint) const
Computes the restriction of the current BDD with the given constraint.
uint_fast64_t getNodeCount() const
Retrieves the number of nodes necessary to represent the DD.
InternalBdd< DdType::Sylvan > & operator&=(InternalBdd< DdType::Sylvan > const &other)
Performs a logical and of the current and the given BDD and assigns it to the current BDD.
InternalBdd< DdType::Sylvan > getSupport() const
Retrieves the support of the current BDD.
InternalBdd< DdType::Sylvan > relationalProduct(InternalBdd< DdType::Sylvan > const &relation, std::vector< InternalBdd< DdType::Sylvan > > const &rowVariables, std::vector< InternalBdd< DdType::Sylvan > > const &columnVariables) const
Computes the relational product of the current BDD and the given BDD representing a relation.
InternalBdd< DdType::Sylvan > exclusiveOr(InternalBdd< DdType::Sylvan > const &other) const
Performs a logical exclusive-or of the current and the given BDD.
uint_fast64_t getLevel() const
Retrieves the level of the topmost variable in the BDD.
void exportToDot(std::string const &filename, std::vector< std::string > const &ddVariableNamesAsStrings, bool showVariablesIfPossible=true) const
Exports the BDD to the given file in the dot format.
uint_fast64_t getIndex() const
Retrieves the index of the topmost variable in the BDD.
Odd createOdd(std::vector< uint_fast64_t > const &ddVariableIndices) const
Creates an ODD based on the current BDD.
InternalBdd< DdType::Sylvan > andExists(InternalBdd< DdType::Sylvan > const &other, InternalBdd< storm::dd::DdType::Sylvan > const &cube) const
Computes the logical and of the current and the given BDD and existentially abstracts from the given ...
bool isZero() const
Retrieves whether this DD represents the constant zero function.
InternalBdd< DdType::Sylvan > inverseRelationalProductWithExtendedRelation(InternalBdd< DdType::Sylvan > const &relation, std::vector< InternalBdd< DdType::Sylvan > > const &rowVariables, std::vector< InternalBdd< DdType::Sylvan > > const &columnVariables) const
Computes the inverse relational product of the current BDD and the given BDD representing a relation ...
InternalBdd< DdType::Sylvan > operator!() const
Logically inverts the current BDD.
InternalBdd & operator=(InternalBdd< DdType::Sylvan > const &other)=default
InternalBdd< DdType::Sylvan > operator&&(InternalBdd< DdType::Sylvan > const &other) const
Performs a logical and of the current and the given BDD.
std::vector< InternalBdd< DdType::Sylvan > > splitIntoGroups(std::vector< uint_fast64_t > const &ddGroupVariableIndices) const
Splits the BDD into several BDDs that differ in the encoding of the given group variables (given via ...
uint_fast64_t getLeafCount() const
Retrieves the number of leaves of the DD.
InternalBdd< DdType::Sylvan > implies(InternalBdd< DdType::Sylvan > const &other) const
Performs a logical implication of the current and the given BDD.
storm::storage::BitVector toVector(storm::dd::Odd const &rowOdd, std::vector< uint_fast64_t > const &ddVariableIndices) const
Converts the BDD to a bit vector.
InternalBdd< DdType::Sylvan > universalAbstract(InternalBdd< DdType::Sylvan > const &cube) const
Universally abstracts from the given cube.
bool operator==(InternalBdd< DdType::Sylvan > const &other) const
Retrieves whether the two BDDs represent the same function.
InternalBdd(InternalBdd< DdType::Sylvan > &&other)=default
bool isOne() const
Retrieves whether this DD represents the constant one function.
InternalBdd< DdType::Sylvan > inverseRelationalProduct(InternalBdd< DdType::Sylvan > const &relation, std::vector< InternalBdd< DdType::Sylvan > > const &rowVariables, std::vector< InternalBdd< DdType::Sylvan > > const &columnVariables) const
Computes the inverse relational product of the current BDD and the given BDD representing a relation.
InternalBdd< DdType::Sylvan > & complement()
Logically complements the current BDD.
InternalBdd< DdType::Sylvan > iff(InternalBdd< DdType::Sylvan > const &other) const
Performs a logical iff of the current and the given BDD.
void filterExplicitVector(Odd const &odd, std::vector< uint_fast64_t > const &ddVariableIndices, std::vector< ValueType > const &sourceValues, std::vector< ValueType > &targetValues) const
Uses the current BDD to filter values from the explicit vector.
InternalBdd & operator=(InternalBdd< DdType::Sylvan > &&other)=default
InternalBdd< DdType::Sylvan > existsAbstract(InternalBdd< DdType::Sylvan > const &cube) const
Existentially abstracts from the given cube.
void exportToText(std::string const &filename) const
Exports the DD to the given file in a textual format as specified in Sylvan.
InternalBdd< DdType::Sylvan > existsAbstractRepresentative(InternalBdd< DdType::Sylvan > const &cube) const
Similar to existsAbstract, but does not abstract but rather picks a valuation for the variables of th...
uint_fast64_t getNonZeroCount(uint_fast64_t numberOfDdVariables) const
Retrieves the number of encodings that are mapped to a non-zero value.
static InternalBdd< storm::dd::DdType::Sylvan > fromVector(InternalDdManager< DdType::Sylvan > const *ddManager, Odd const &odd, std::vector< uint_fast64_t > const &sortedDdVariableIndices, std::function< bool(uint64_t)> const &filter)
Builds a BDD representing the values that make the given filter function evaluate to true.
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
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
std::size_t operator()(storm::dd::InternalBdd< storm::dd::DdType::Sylvan > const &) const