Storm 1.11.1.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>
24class InternalDdManager;
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
54 static InternalBdd<storm::dd::DdType::Sylvan> fromVector(InternalDdManager<DdType::Sylvan> const* ddManager, Odd const& odd,
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
82 InternalBdd<DdType::Sylvan> relationalProduct(InternalBdd<DdType::Sylvan> const& relation, std::vector<InternalBdd<DdType::Sylvan>> const& rowVariables,
83 std::vector<InternalBdd<DdType::Sylvan>> const& columnVariables) const;
84
93 InternalBdd<DdType::Sylvan> inverseRelationalProduct(InternalBdd<DdType::Sylvan> const& relation,
94 std::vector<InternalBdd<DdType::Sylvan>> const& rowVariables,
95 std::vector<InternalBdd<DdType::Sylvan>> const& columnVariables) const;
96
106 InternalBdd<DdType::Sylvan> inverseRelationalProductWithExtendedRelation(InternalBdd<DdType::Sylvan> const& relation,
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
139 InternalBdd<DdType::Sylvan> operator||(InternalBdd<DdType::Sylvan> const& other) const;
140
148
155 InternalBdd<DdType::Sylvan> operator&&(InternalBdd<DdType::Sylvan> const& other) const;
156
164
172
179 InternalBdd<DdType::Sylvan> exclusiveOr(InternalBdd<DdType::Sylvan> const& other) const;
180
188
194 InternalBdd<DdType::Sylvan> operator!() const;
195
201 InternalBdd<DdType::Sylvan>& complement();
202
208 InternalBdd<DdType::Sylvan> existsAbstract(InternalBdd<DdType::Sylvan> const& cube) const;
209
217 InternalBdd<DdType::Sylvan> existsAbstractRepresentative(InternalBdd<DdType::Sylvan> const& cube) const;
218
224 InternalBdd<DdType::Sylvan> universalAbstract(InternalBdd<DdType::Sylvan> const& cube) const;
225
234 InternalBdd<DdType::Sylvan> swapVariables(std::vector<InternalBdd<DdType::Sylvan>> const& from, std::vector<InternalBdd<DdType::Sylvan>> const& to) const;
235
244
253 InternalBdd<DdType::Sylvan> constrain(InternalBdd<DdType::Sylvan> const& constraint) const;
254
263 InternalBdd<DdType::Sylvan> restrict(InternalBdd<DdType::Sylvan> const& constraint) const;
264
270 InternalBdd<DdType::Sylvan> getSupport() const;
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
550 std::size_t operator()(storm::dd::InternalBdd<storm::dd::DdType::Sylvan> const& key) const {
551 return static_cast<std::size_t>(key.sylvanBdd.GetBDD());
552 }
553#else
554 std::size_t operator()(storm::dd::InternalBdd<storm::dd::DdType::Sylvan> const&) const {
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(InternalBdd< DdType::Sylvan > const &other)=default
InternalBdd & operator=(InternalBdd< DdType::Sylvan > const &other)=default
InternalBdd(InternalBdd< DdType::Sylvan > &&other)=default
InternalBdd & operator=(InternalBdd< DdType::Sylvan > &&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