Storm 1.13.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 "storm-config.h"
4
5#include <functional>
6#include <memory>
7#include <set>
8#include <unordered_map>
9
16
17#ifdef STORM_HAVE_CUDD
18// Include the C++-interface of CUDD.
19#include "cuddObj.hh"
20#endif
21
22namespace storm {
23namespace storage {
24class BitVector;
25}
26
27namespace dd {
28template<DdType LibraryType>
30
31template<DdType LibraryType, typename ValueType>
32class InternalAdd;
33
34class Odd;
35
36template<>
38 public:
39 template<DdType LibraryType, typename ValueType>
40 friend class InternalAdd;
41
42#ifdef STORM_HAVE_CUDD
50 InternalBdd(InternalDdManager<DdType::CUDD> const* ddManager, cudd::BDD cuddBdd);
51#endif
52
53 // Instantiate all copy/move constructors/assignments with the default implementation.
54 InternalBdd() = default;
55 InternalBdd(InternalBdd<DdType::CUDD> const& other) = default;
59
70 std::vector<uint_fast64_t> const& sortedDdVariableIndices,
71 std::function<bool(uint64_t)> const& filter);
72
79 bool operator==(InternalBdd<DdType::CUDD> const& other) const;
80
87 bool operator!=(InternalBdd<DdType::CUDD> const& other) const;
88
98 std::vector<InternalBdd<DdType::CUDD>> const& columnVariables) const;
99
109 std::vector<InternalBdd<DdType::CUDD>> const& columnVariables) const;
110
121 std::vector<InternalBdd<DdType::CUDD>> const& rowVariables,
122 std::vector<InternalBdd<DdType::CUDD>> const& columnVariables) const;
123
134
143 template<typename ValueType>
145
153
161
169
177
185
193
201
208
215
222
231
238
247 InternalBdd<DdType::CUDD> swapVariables(std::vector<InternalBdd<DdType::CUDD>> const& from, std::vector<InternalBdd<DdType::CUDD>> const& to) const;
248
257
267
277
284
291 uint_fast64_t getNonZeroCount(uint_fast64_t numberOfDdVariables) const;
292
298 uint_fast64_t getLeafCount() const;
299
305 uint_fast64_t getNodeCount() const;
306
312 bool isOne() const;
313
319 bool isZero() const;
320
326 uint_fast64_t getIndex() const;
327
333 uint_fast64_t getLevel() const;
334
341 void exportToDot(std::string const& filename, std::vector<std::string> const& ddVariableNamesAsStrings, bool showVariablesIfPossible = true) const;
342
348 void exportToText(std::string const& filename) const;
349
355 template<typename ValueType>
357
366 storm::storage::BitVector toVector(storm::dd::Odd const& rowOdd, std::vector<uint_fast64_t> const& ddVariableIndices) const;
367
375 std::pair<std::vector<storm::expressions::Expression>, std::unordered_map<uint_fast64_t, storm::expressions::Variable>> toExpression(
377
384 Odd createOdd(std::vector<uint_fast64_t> const& ddVariableIndices) const;
385
394 template<typename ValueType>
395 void filterExplicitVector(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices, std::vector<ValueType> const& sourceValues,
396 std::vector<ValueType>& targetValues) const;
397
406 void filterExplicitVector(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices, storm::storage::BitVector const& sourceValues,
407 storm::storage::BitVector& targetValues) const;
408
415 std::vector<InternalBdd<DdType::CUDD>> splitIntoGroups(std::vector<uint_fast64_t> const& ddGroupVariableIndices) const;
416
417 friend struct std::hash<storm::dd::InternalBdd<storm::dd::DdType::CUDD>>;
418
419#ifdef STORM_HAVE_CUDD
425 cudd::BDD getCuddBdd() const;
426
432 DdNode* getCuddDdNode() const;
433#endif
434
435 private:
436#ifdef STORM_HAVE_CUDD
449 static DdNode* fromVectorRec(::DdManager* manager, uint_fast64_t& currentOffset, uint_fast64_t currentLevel, uint_fast64_t maxLevel, Odd const& odd,
450 std::vector<uint_fast64_t> const& ddVariableIndices, std::function<bool(uint64_t)> const& filter);
451
465 void toVectorRec(DdNode const* dd, cudd::Cudd const& manager, storm::storage::BitVector& result, Odd const& rowOdd, bool complement,
466 uint_fast64_t currentRowLevel, uint_fast64_t maxLevel, uint_fast64_t currentRowOffset,
467 std::vector<uint_fast64_t> const& ddRowVariableIndices) const;
468
469 // Declare a hash functor that is used for the unique tables in the construction process of ODDs.
470 class HashFunctor {
471 public:
472 std::size_t operator()(std::pair<DdNode const*, bool> const& key) const;
473 };
474
487 static std::shared_ptr<Odd> createOddRec(DdNode const* dd, cudd::Cudd const& manager, uint_fast64_t currentLevel, uint_fast64_t maxLevel,
488 std::vector<uint_fast64_t> const& ddVariableIndices,
489 std::vector<std::unordered_map<DdNode const*, std::shared_ptr<Odd>>>& uniqueTableForLevels);
490
505 template<typename ValueType>
506 static void filterExplicitVectorRec(DdNode const* dd, cudd::Cudd const& manager, 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 std::vector<ValueType>& result, uint_fast64_t& currentIndex, std::vector<ValueType> const& values);
509
524 static void filterExplicitVectorRec(DdNode const* dd, cudd::Cudd const& manager, uint_fast64_t currentLevel, bool complement, uint_fast64_t maxLevel,
525 std::vector<uint_fast64_t> const& ddVariableIndices, uint_fast64_t currentOffset, storm::dd::Odd const& odd,
526 storm::storage::BitVector& result, uint_fast64_t& currentIndex, storm::storage::BitVector const& values);
527
546 static storm::expressions::Variable toExpressionRec(
547 DdNode const* dd, cudd::Cudd const& ddManager, storm::expressions::ExpressionManager& manager, std::vector<storm::expressions::Expression>& expressions,
548 std::unordered_map<uint_fast64_t, storm::expressions::Variable>& indexToVariableMap,
549 std::unordered_map<std::pair<uint_fast64_t, uint_fast64_t>, storm::expressions::Variable>& countIndexToVariablePair,
550 std::unordered_map<DdNode const*, uint_fast64_t>& nodeToCounterMap, std::vector<uint_fast64_t>& nextCounterForIndex);
551
552 void splitIntoGroupsRec(DdNode* dd, bool negated, std::vector<InternalBdd<DdType::CUDD>>& groups, std::vector<uint_fast64_t> const& ddGroupVariableIndices,
553 uint_fast64_t currentLevel, uint_fast64_t maxLevel) const;
554
555 InternalDdManager<DdType::CUDD> const* ddManager;
556
557 cudd::BDD cuddBdd;
558#endif
559};
560} // namespace dd
561} // namespace storm
562
563namespace std {
564template<>
565struct hash<storm::dd::InternalBdd<storm::dd::DdType::CUDD>> {
566#ifdef STORM_HAVE_CUDD
567 std::size_t operator()(storm::dd::InternalBdd<storm::dd::DdType::CUDD> const& key) const {
568 return reinterpret_cast<std::size_t>(key.cuddBdd.getNode());
569 }
570#else
572 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
573 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a "
574 "version of Storm with CUDD support.");
575 }
576#endif
577};
578} // 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:30
std::size_t operator()(storm::dd::InternalBdd< storm::dd::DdType::CUDD > const &) const