Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
InternalCuddBdd.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <memory>
5#include <set>
6#include <unordered_map>
7
8#include "storm-config.h"
16
17namespace storm {
18namespace storage {
19class BitVector;
20}
21
22namespace dd {
23template<DdType LibraryType>
25
26template<DdType LibraryType, typename ValueType>
27class InternalAdd;
28
29class Odd;
30
31template<>
33 public:
34 template<DdType LibraryType, typename ValueType>
35 friend class InternalAdd;
36
37#ifdef STORM_HAVE_CUDD
45 InternalBdd(InternalDdManager<DdType::CUDD> const* ddManager, cudd::BDD cuddBdd);
46#endif
47
48 // Instantiate all copy/move constructors/assignments with the default implementation.
49 InternalBdd() = default;
50 InternalBdd(InternalBdd<DdType::CUDD> const& other) = default;
54
65 std::vector<uint_fast64_t> const& sortedDdVariableIndices,
66 std::function<bool(uint64_t)> const& filter);
67
74 bool operator==(InternalBdd<DdType::CUDD> const& other) const;
75
82 bool operator!=(InternalBdd<DdType::CUDD> const& other) const;
83
93 std::vector<InternalBdd<DdType::CUDD>> const& columnVariables) const;
94
104 std::vector<InternalBdd<DdType::CUDD>> const& columnVariables) const;
105
116 std::vector<InternalBdd<DdType::CUDD>> const& rowVariables,
117 std::vector<InternalBdd<DdType::CUDD>> const& columnVariables) const;
118
129
138 template<typename ValueType>
140
148
156
164
172
180
188
196
203
210
217
226
233
242 InternalBdd<DdType::CUDD> swapVariables(std::vector<InternalBdd<DdType::CUDD>> const& from, std::vector<InternalBdd<DdType::CUDD>> const& to) const;
243
252
262
272
279
286 uint_fast64_t getNonZeroCount(uint_fast64_t numberOfDdVariables) const;
287
293 uint_fast64_t getLeafCount() const;
294
300 uint_fast64_t getNodeCount() const;
301
307 bool isOne() const;
308
314 bool isZero() const;
315
321 uint_fast64_t getIndex() const;
322
328 uint_fast64_t getLevel() const;
329
336 void exportToDot(std::string const& filename, std::vector<std::string> const& ddVariableNamesAsStrings, bool showVariablesIfPossible = true) const;
337
343 void exportToText(std::string const& filename) const;
344
350 template<typename ValueType>
352
361 storm::storage::BitVector toVector(storm::dd::Odd const& rowOdd, std::vector<uint_fast64_t> const& ddVariableIndices) const;
362
370 std::pair<std::vector<storm::expressions::Expression>, std::unordered_map<uint_fast64_t, storm::expressions::Variable>> toExpression(
372
379 Odd createOdd(std::vector<uint_fast64_t> const& ddVariableIndices) const;
380
389 template<typename ValueType>
390 void filterExplicitVector(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices, std::vector<ValueType> const& sourceValues,
391 std::vector<ValueType>& targetValues) const;
392
401 void filterExplicitVector(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices, storm::storage::BitVector const& sourceValues,
402 storm::storage::BitVector& targetValues) const;
403
410 std::vector<InternalBdd<DdType::CUDD>> splitIntoGroups(std::vector<uint_fast64_t> const& ddGroupVariableIndices) const;
411
412 friend struct std::hash<storm::dd::InternalBdd<storm::dd::DdType::CUDD>>;
413
414#ifdef STORM_HAVE_CUDD
420 cudd::BDD getCuddBdd() const;
421
427 DdNode* getCuddDdNode() const;
428#endif
429
430 private:
431#ifdef STORM_HAVE_CUDD
444 static DdNode* fromVectorRec(::DdManager* manager, uint_fast64_t& currentOffset, uint_fast64_t currentLevel, uint_fast64_t maxLevel, Odd const& odd,
445 std::vector<uint_fast64_t> const& ddVariableIndices, std::function<bool(uint64_t)> const& filter);
446
460 void toVectorRec(DdNode const* dd, cudd::Cudd const& manager, storm::storage::BitVector& result, Odd const& rowOdd, bool complement,
461 uint_fast64_t currentRowLevel, uint_fast64_t maxLevel, uint_fast64_t currentRowOffset,
462 std::vector<uint_fast64_t> const& ddRowVariableIndices) const;
463
464 // Declare a hash functor that is used for the unique tables in the construction process of ODDs.
465 class HashFunctor {
466 public:
467 std::size_t operator()(std::pair<DdNode const*, bool> const& key) const;
468 };
469
482 static std::shared_ptr<Odd> createOddRec(DdNode const* dd, cudd::Cudd const& manager, uint_fast64_t currentLevel, uint_fast64_t maxLevel,
483 std::vector<uint_fast64_t> const& ddVariableIndices,
484 std::vector<std::unordered_map<DdNode const*, std::shared_ptr<Odd>>>& uniqueTableForLevels);
485
500 template<typename ValueType>
501 static void filterExplicitVectorRec(DdNode const* dd, cudd::Cudd const& manager, uint_fast64_t currentLevel, bool complement, uint_fast64_t maxLevel,
502 std::vector<uint_fast64_t> const& ddVariableIndices, uint_fast64_t currentOffset, storm::dd::Odd const& odd,
503 std::vector<ValueType>& result, uint_fast64_t& currentIndex, std::vector<ValueType> const& values);
504
519 static void filterExplicitVectorRec(DdNode const* dd, cudd::Cudd const& manager, uint_fast64_t currentLevel, bool complement, uint_fast64_t maxLevel,
520 std::vector<uint_fast64_t> const& ddVariableIndices, uint_fast64_t currentOffset, storm::dd::Odd const& odd,
521 storm::storage::BitVector& result, uint_fast64_t& currentIndex, storm::storage::BitVector const& values);
522
541 static storm::expressions::Variable toExpressionRec(
542 DdNode const* dd, cudd::Cudd const& ddManager, storm::expressions::ExpressionManager& manager, std::vector<storm::expressions::Expression>& expressions,
543 std::unordered_map<uint_fast64_t, storm::expressions::Variable>& indexToVariableMap,
544 std::unordered_map<std::pair<uint_fast64_t, uint_fast64_t>, storm::expressions::Variable>& countIndexToVariablePair,
545 std::unordered_map<DdNode const*, uint_fast64_t>& nodeToCounterMap, std::vector<uint_fast64_t>& nextCounterForIndex);
546
547 void splitIntoGroupsRec(DdNode* dd, bool negated, std::vector<InternalBdd<DdType::CUDD>>& groups, std::vector<uint_fast64_t> const& ddGroupVariableIndices,
548 uint_fast64_t currentLevel, uint_fast64_t maxLevel) const;
549
550 InternalDdManager<DdType::CUDD> const* ddManager;
551
552 cudd::BDD cuddBdd;
553#endif
554};
555} // namespace dd
556} // namespace storm
557
558namespace std {
559template<>
560struct hash<storm::dd::InternalBdd<storm::dd::DdType::CUDD>> {
561#ifdef STORM_HAVE_CUDD
562 std::size_t operator()(storm::dd::InternalBdd<storm::dd::DdType::CUDD> const& key) const {
563 return reinterpret_cast<std::size_t>(key.cuddBdd.getNode());
564 }
565#else
567 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
568 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a "
569 "version of Storm with CUDD support.");
570 }
571#endif
572};
573} // namespace std
static InternalBdd< storm::dd::DdType::CUDD > fromVector(InternalDdManager< DdType::CUDD > const *ddManager, Odd const &odd, std::vector< uint_fast64_t > const &sortedDdVariableIndices, std::function< bool(uint64_t)> const &filter)
Builds a BDD representing the indices that make the given filter function evaluate to true.
uint_fast64_t getIndex() const
Retrieves the index of the topmost variable in the BDD.
InternalBdd< DdType::CUDD > exclusiveOr(InternalBdd< DdType::CUDD > const &other) const
Performs a logical exclusive-or 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.
uint_fast64_t getNodeCount() const
Retrieves the number of nodes necessary to represent the DD.
InternalBdd(InternalBdd< DdType::CUDD > &&other)=default
InternalBdd< DdType::CUDD > & operator|=(InternalBdd< DdType::CUDD > const &other)
Performs a logical or of the current and the given BDD and assigns it to the current BDD.
uint_fast64_t getLevel() const
Retrieves the level of the topmost variable in the BDD.
InternalBdd & operator=(InternalBdd< DdType::CUDD > &&other)=default
InternalBdd(InternalBdd< DdType::CUDD > const &other)=default
InternalBdd & operator=(InternalBdd< DdType::CUDD > const &other)=default
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.
std::vector< InternalBdd< DdType::CUDD > > 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 ...
InternalBdd< DdType::CUDD > swapVariables(std::vector< InternalBdd< DdType::CUDD > > const &from, std::vector< InternalBdd< DdType::CUDD > > const &to) const
Swaps the given pairs of DD variables in the BDD.
void exportToText(std::string const &filename) const
Exports the DD to the given file in a textual format as specified in Sylvan.
InternalBdd< DdType::CUDD > ite(InternalBdd< DdType::CUDD > const &thenBdd, InternalBdd< DdType::CUDD > const &elseBdd) const
Performs an if-then-else with the given operands, i.e.
InternalBdd< DdType::CUDD > operator&&(InternalBdd< DdType::CUDD > const &other) const
Performs a logical and of the current and the given BDD.
bool operator==(InternalBdd< DdType::CUDD > const &other) const
Retrieves whether the two BDDs represent the same function.
InternalBdd< DdType::CUDD > existsAbstract(InternalBdd< DdType::CUDD > const &cube) const
Existentially abstracts from the given cube.
InternalBdd< DdType::CUDD > inverseRelationalProductWithExtendedRelation(InternalBdd< DdType::CUDD > const &relation, std::vector< InternalBdd< DdType::CUDD > > const &rowVariables, std::vector< InternalBdd< DdType::CUDD > > const &columnVariables) const
Computes the inverse relational product of the current BDD and the given BDD representing a relation ...
InternalBdd< DdType::CUDD > & complement()
Logically complements the current BDD.
InternalBdd< DdType::CUDD > operator||(InternalBdd< DdType::CUDD > const &other) const
Performs a logical or 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::CUDD > implies(InternalBdd< DdType::CUDD > const &other) const
Performs a logical implication of the current and the given BDD.
bool isOne() const
Retrieves whether this DD represents the constant one function.
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...
InternalBdd< DdType::CUDD > restrict(InternalBdd< DdType::CUDD > const &constraint) const
Computes the restriction of the current BDD with the given constraint.
InternalBdd< DdType::CUDD > universalAbstract(InternalBdd< DdType::CUDD > const &cube) const
Universally abstracts from the given cube.
InternalBdd< DdType::CUDD > relationalProduct(InternalBdd< DdType::CUDD > const &relation, std::vector< InternalBdd< DdType::CUDD > > const &rowVariables, std::vector< InternalBdd< DdType::CUDD > > const &columnVariables) const
Computes the relational product of the current BDD and the given BDD representing a relation.
bool isZero() const
Retrieves whether this DD represents the constant zero function.
bool operator!=(InternalBdd< DdType::CUDD > const &other) const
Retrieves whether the two BDDs represent different functions.
InternalBdd< DdType::CUDD > inverseRelationalProduct(InternalBdd< DdType::CUDD > const &relation, std::vector< InternalBdd< DdType::CUDD > > const &rowVariables, std::vector< InternalBdd< DdType::CUDD > > const &columnVariables) const
Computes the inverse relational product of the current BDD and the given BDD representing a relation.
InternalAdd< DdType::CUDD, ValueType > toAdd() const
Converts a BDD to an equivalent ADD.
Odd createOdd(std::vector< uint_fast64_t > const &ddVariableIndices) const
Creates an ODD based on the current BDD.
uint_fast64_t getLeafCount() const
Retrieves the number of leaves of the DD.
InternalBdd< DdType::CUDD > getSupport() const
Retrieves the support of the current BDD.
InternalBdd< DdType::CUDD > constrain(InternalBdd< DdType::CUDD > const &constraint) const
Computes the constraint of the current BDD with the given constraint.
uint_fast64_t getNonZeroCount(uint_fast64_t numberOfDdVariables) const
Retrieves the number of encodings that are mapped to a non-zero value.
InternalBdd< DdType::CUDD > existsAbstractRepresentative(InternalBdd< DdType::CUDD > const &cube) const
Similar to existsAbstract, but does not abstract but rather picks a valuation for the variables of th...
InternalBdd< DdType::CUDD > operator!() const
Logically inverts the current BDD.
InternalBdd< DdType::CUDD > iff(InternalBdd< DdType::CUDD > const &other) const
Performs a logical iff of the current and the given BDD.
InternalBdd< DdType::CUDD > andExists(InternalBdd< DdType::CUDD > const &other, InternalBdd< storm::dd::DdType::CUDD > const &cube) const
Computes the logical and of the current and the given BDD and existentially abstracts from the given ...
InternalBdd< DdType::CUDD > & operator&=(InternalBdd< DdType::CUDD > const &other)
Performs a logical and of the current and the given BDD and assigns it to the current BDD.
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:39
std::size_t operator()(storm::dd::InternalBdd< storm::dd::DdType::CUDD > const &) const