Storm 1.11.1.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>
29class InternalDdManager;
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
69 static InternalBdd<storm::dd::DdType::CUDD> fromVector(InternalDdManager<DdType::CUDD> const* ddManager, Odd const& odd,
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
97 InternalBdd<DdType::CUDD> relationalProduct(InternalBdd<DdType::CUDD> const& relation, std::vector<InternalBdd<DdType::CUDD>> const& rowVariables,
98 std::vector<InternalBdd<DdType::CUDD>> const& columnVariables) const;
99
108 InternalBdd<DdType::CUDD> inverseRelationalProduct(InternalBdd<DdType::CUDD> const& relation, std::vector<InternalBdd<DdType::CUDD>> const& rowVariables,
109 std::vector<InternalBdd<DdType::CUDD>> const& columnVariables) const;
110
120 InternalBdd<DdType::CUDD> inverseRelationalProductWithExtendedRelation(InternalBdd<DdType::CUDD> const& relation,
121 std::vector<InternalBdd<DdType::CUDD>> const& rowVariables,
122 std::vector<InternalBdd<DdType::CUDD>> const& columnVariables) const;
123
133 InternalBdd<DdType::CUDD> ite(InternalBdd<DdType::CUDD> const& thenBdd, InternalBdd<DdType::CUDD> const& elseBdd) const;
134
143 template<typename ValueType>
145
152 InternalBdd<DdType::CUDD> operator||(InternalBdd<DdType::CUDD> const& other) const;
153
161
168 InternalBdd<DdType::CUDD> operator&&(InternalBdd<DdType::CUDD> const& other) const;
169
177
185
192 InternalBdd<DdType::CUDD> exclusiveOr(InternalBdd<DdType::CUDD> const& other) const;
193
200 InternalBdd<DdType::CUDD> implies(InternalBdd<DdType::CUDD> const& other) const;
201
207 InternalBdd<DdType::CUDD> operator!() const;
208
214 InternalBdd<DdType::CUDD>& complement();
215
221 InternalBdd<DdType::CUDD> existsAbstract(InternalBdd<DdType::CUDD> const& cube) const;
222
230 InternalBdd<DdType::CUDD> existsAbstractRepresentative(InternalBdd<DdType::CUDD> const& cube) const;
231
237 InternalBdd<DdType::CUDD> universalAbstract(InternalBdd<DdType::CUDD> const& cube) const;
238
247 InternalBdd<DdType::CUDD> swapVariables(std::vector<InternalBdd<DdType::CUDD>> const& from, std::vector<InternalBdd<DdType::CUDD>> const& to) const;
248
257
266 InternalBdd<DdType::CUDD> constrain(InternalBdd<DdType::CUDD> const& constraint) const;
267
276 InternalBdd<DdType::CUDD> restrict(InternalBdd<DdType::CUDD> const& constraint) const;
277
283 InternalBdd<DdType::CUDD> getSupport() const;
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
571 std::size_t operator()(storm::dd::InternalBdd<storm::dd::DdType::CUDD> const&) const {
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
InternalBdd(InternalBdd< DdType::CUDD > &&other)=default
InternalBdd & operator=(InternalBdd< DdType::CUDD > &&other)=default
InternalBdd(InternalBdd< DdType::CUDD > const &other)=default
InternalBdd & operator=(InternalBdd< DdType::CUDD > const &other)=default
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
storage::BitVector BitVector