Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
InternalSylvanAdd.h
Go to the documentation of this file.
1#pragma once
2
3#include <set>
4#include <unordered_map>
5
6#include "storm-config.h"
14
15namespace storm {
16namespace storage {
17template<typename T>
18class SparseMatrix;
19
20class BitVector;
21
22template<typename E, typename V>
23class MatrixEntry;
24} // namespace storage
25
26namespace dd {
27template<DdType LibraryType>
28class DdManager;
29
30template<DdType LibraryType>
32
33template<DdType LibraryType>
34class InternalBdd;
35
36template<DdType LibraryType, typename ValueType>
37class AddIterator;
38
39template<typename ValueType>
40class InternalAdd<DdType::Sylvan, ValueType> {
41 public:
42 friend class AddIterator<DdType::Sylvan, ValueType>;
43 friend class InternalBdd<DdType::Sylvan>;
44
45#ifdef STORM_HAVE_SYLVAN
52 InternalAdd(InternalDdManager<DdType::Sylvan> const* ddManager, sylvan::Mtbdd const& sylvanMtbdd);
53#endif
54
55 // Instantiate all copy/move constructors/assignments with the default implementation.
57 InternalAdd(InternalAdd<DdType::Sylvan, ValueType> const& other) = default;
58 InternalAdd& operator=(InternalAdd<DdType::Sylvan, ValueType> const& other) = default;
59 InternalAdd(InternalAdd<DdType::Sylvan, ValueType>&& other) = default;
60 InternalAdd& operator=(InternalAdd<DdType::Sylvan, ValueType>&& other) = default;
61 virtual ~InternalAdd() = default;
62
69 bool operator==(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
70
77 bool operator!=(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
78
85 InternalAdd<DdType::Sylvan, ValueType> operator+(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
86
93 InternalAdd<DdType::Sylvan, ValueType>& operator+=(InternalAdd<DdType::Sylvan, ValueType> const& other);
94
101 InternalAdd<DdType::Sylvan, ValueType> operator*(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
102
109 InternalAdd<DdType::Sylvan, ValueType>& operator*=(InternalAdd<DdType::Sylvan, ValueType> const& other);
110
117 InternalAdd<DdType::Sylvan, ValueType> operator-(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
118
125 InternalAdd<DdType::Sylvan, ValueType>& operator-=(InternalAdd<DdType::Sylvan, ValueType> const& other);
126
133 InternalAdd<DdType::Sylvan, ValueType> operator/(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
134
141 InternalAdd<DdType::Sylvan, ValueType>& operator/=(InternalAdd<DdType::Sylvan, ValueType> const& other);
142
149 InternalBdd<DdType::Sylvan> equals(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
150
157 InternalBdd<DdType::Sylvan> notEquals(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
158
166 InternalBdd<DdType::Sylvan> less(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
167
175 InternalBdd<DdType::Sylvan> lessOrEqual(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
176
184 InternalBdd<DdType::Sylvan> greater(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
185
193 InternalBdd<DdType::Sylvan> greaterOrEqual(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
194
201 InternalAdd<DdType::Sylvan, ValueType> pow(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
202
209 InternalAdd<DdType::Sylvan, ValueType> mod(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
210
218 InternalAdd<DdType::Sylvan, ValueType> logxy(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
219
225 InternalAdd<DdType::Sylvan, ValueType> floor() const;
226
232 InternalAdd<DdType::Sylvan, ValueType> ceil() const;
233
239 InternalAdd<DdType::Sylvan, storm::RationalNumber> sharpenKwekMehlhorn(size_t precision) const;
240
247 InternalAdd<DdType::Sylvan, ValueType> minimum(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
248
255 InternalAdd<DdType::Sylvan, ValueType> maximum(InternalAdd<DdType::Sylvan, ValueType> const& other) const;
256
262 template<typename TargetValueType>
263 InternalAdd<DdType::Sylvan, TargetValueType> toValueType() const;
264
270 InternalAdd<DdType::Sylvan, ValueType> sumAbstract(InternalBdd<DdType::Sylvan> const& cube) const;
271
277 InternalAdd<DdType::Sylvan, ValueType> minAbstract(InternalBdd<DdType::Sylvan> const& cube) const;
278
284 InternalBdd<DdType::Sylvan> minAbstractRepresentative(InternalBdd<DdType::Sylvan> const& cube) const;
285
291 InternalAdd<DdType::Sylvan, ValueType> maxAbstract(InternalBdd<DdType::Sylvan> const& cube) const;
292
298 InternalBdd<DdType::Sylvan> maxAbstractRepresentative(InternalBdd<DdType::Sylvan> const& cube) const;
299
309 bool equalModuloPrecision(InternalAdd<DdType::Sylvan, ValueType> const& other, ValueType const& precision, bool relative = true) const;
310
319 InternalAdd<DdType::Sylvan, ValueType> swapVariables(std::vector<InternalBdd<DdType::Sylvan>> const& from,
320 std::vector<InternalBdd<DdType::Sylvan>> const& to) const;
321
330 InternalAdd<DdType::Sylvan, ValueType> permuteVariables(std::vector<InternalBdd<DdType::Sylvan>> const& from,
331 std::vector<InternalBdd<DdType::Sylvan>> const& to) const;
332
341 InternalAdd<DdType::Sylvan, ValueType> multiplyMatrix(InternalAdd<DdType::Sylvan, ValueType> const& otherMatrix,
342 std::vector<InternalBdd<DdType::Sylvan>> const& summationDdVariables) const;
343
352 InternalAdd<DdType::Sylvan, ValueType> multiplyMatrix(InternalBdd<DdType::Sylvan> const& otherMatrix,
353 std::vector<InternalBdd<DdType::Sylvan>> const& summationDdVariables) const;
354
362 InternalBdd<DdType::Sylvan> greater(ValueType const& value) const;
363
371 InternalBdd<DdType::Sylvan> greaterOrEqual(ValueType const& value) const;
372
380 InternalBdd<DdType::Sylvan> less(ValueType const& value) const;
381
389 InternalBdd<DdType::Sylvan> lessOrEqual(ValueType const& value) const;
390
397 InternalBdd<DdType::Sylvan> notZero() const;
398
407 InternalAdd<DdType::Sylvan, ValueType> constrain(InternalAdd<DdType::Sylvan, ValueType> const& constraint) const;
408
417 InternalAdd<DdType::Sylvan, ValueType> restrict(InternalAdd<DdType::Sylvan, ValueType> const& constraint) const;
418
424 InternalBdd<DdType::Sylvan> getSupport() const;
425
432 virtual uint_fast64_t getNonZeroCount(uint_fast64_t numberOfDdVariables) const;
433
439 virtual uint_fast64_t getLeafCount() const;
440
446 virtual uint_fast64_t getNodeCount() const;
447
453 ValueType getMin() const;
454
460 ValueType getMax() const;
461
467 ValueType getValue() const;
468
474 bool isOne() const;
475
481 bool isZero() const;
482
488 bool isConstant() const;
489
495 uint_fast64_t getIndex() const;
496
502 uint_fast64_t getLevel() const;
503
510 void exportToDot(std::string const& filename, std::vector<std::string> const& ddVariableNamesAsStrings, bool showVariablesIfPossible = true) const;
511
517 void exportToText(std::string const& filename) const;
518
530 AddIterator<DdType::Sylvan, ValueType> begin(DdManager<DdType::Sylvan> const& fullDdManager, InternalBdd<DdType::Sylvan> const& variableCube,
531 uint_fast64_t numberOfDdVariables, std::set<storm::expressions::Variable> const& metaVariables,
532 bool enumerateDontCareMetaVariables = true) const;
533
540 AddIterator<DdType::Sylvan, ValueType> end(DdManager<DdType::Sylvan> const& fullDdManager) const;
541
552 void composeWithExplicitVector(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices, std::vector<ValueType>& targetVector,
553 std::function<ValueType(ValueType const&, ValueType const&)> const& function) const;
554
566 void composeWithExplicitVector(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices, std::vector<uint_fast64_t> const& offsets,
567 std::vector<ValueType>& targetVector, std::function<ValueType(ValueType const&, ValueType const&)> const& function) const;
568
579 void forEach(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices,
580 std::function<void(uint64_t const&, ValueType const&)> const& function) const;
581
588 std::vector<InternalAdd<DdType::Sylvan, ValueType>> splitIntoGroups(std::vector<uint_fast64_t> const& ddGroupVariableIndices) const;
589
598 std::vector<uint64_t> decodeGroupLabels(std::vector<uint_fast64_t> const& ddGroupVariableIndices,
599 storm::storage::BitVector const& ddLabelVariableIndices) const;
600
610 std::vector<std::pair<InternalAdd<DdType::Sylvan, ValueType>, InternalAdd<DdType::Sylvan, ValueType>>> splitIntoGroups(
611 InternalAdd<DdType::Sylvan, ValueType> vector, std::vector<uint_fast64_t> const& ddGroupVariableIndices) const;
612
622 std::vector<std::vector<InternalAdd<DdType::Sylvan, ValueType>>> splitIntoGroups(std::vector<InternalAdd<DdType::Sylvan, ValueType>> const& vectors,
623 std::vector<uint_fast64_t> const& ddGroupVariableIndices) const;
624
638 void toMatrixComponents(std::vector<uint_fast64_t> const& rowGroupIndices, std::vector<uint_fast64_t>& rowIndications,
639 std::vector<storm::storage::MatrixEntry<uint_fast64_t, ValueType>>& columnsAndValues, Odd const& rowOdd, Odd const& columnOdd,
640 std::vector<uint_fast64_t> const& ddRowVariableIndices, std::vector<uint_fast64_t> const& ddColumnVariableIndices,
641 bool writeValues) const;
642
651 static InternalAdd<DdType::Sylvan, ValueType> fromVector(InternalDdManager<DdType::Sylvan> const* ddManager, std::vector<ValueType> const& values,
652 storm::dd::Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices);
653
659 Odd createOdd(std::vector<uint_fast64_t> const& ddVariableIndices) const;
660
661 InternalDdManager<DdType::Sylvan> const& getInternalDdManager() const;
662
663#ifdef STORM_HAVE_SYLVAN
669 sylvan::Mtbdd getSylvanMtbdd() const;
670
676 static ValueType getValue(MTBDD const& node);
677#endif
678
679 std::string getStringId() const;
680
681 private:
682#ifdef STORM_HAVE_SYLVAN
694 static std::shared_ptr<Odd> createOddRec(BDD dd, uint_fast64_t currentLevel, uint_fast64_t maxLevel, std::vector<uint_fast64_t> const& ddVariableIndices,
695 std::vector<std::unordered_map<BDD, std::shared_ptr<Odd>>>& uniqueTableForLevels);
696
709 void forEachRec(MTBDD dd, uint_fast64_t currentLevel, uint_fast64_t maxLevel, uint_fast64_t currentOffset, Odd const& odd,
710 std::vector<uint_fast64_t> const& ddVariableIndices, std::function<void(uint64_t const&, ValueType const&)> const& function) const;
711
724 void decodeGroupLabelsRec(MTBDD dd, std::vector<uint64_t>& labels, std::vector<uint_fast64_t> const& ddGroupVariableIndices,
725 storm::storage::BitVector const& ddLabelVariableIndices, uint_fast64_t currentLevel, uint_fast64_t maxLevel,
726 uint64_t label) const;
727
738 void splitIntoGroupsRec(MTBDD dd, bool negated, std::vector<InternalAdd<DdType::Sylvan, ValueType>>& groups,
739 std::vector<uint_fast64_t> const& ddGroupVariableIndices, uint_fast64_t currentLevel, uint_fast64_t maxLevel) const;
740
753 void splitIntoGroupsRec(MTBDD dd1, bool negated1, MTBDD dd2, bool negated2,
754 std::vector<std::pair<InternalAdd<DdType::Sylvan, ValueType>, InternalAdd<DdType::Sylvan, ValueType>>>& groups,
755 std::vector<uint_fast64_t> const& ddGroupVariableIndices, uint_fast64_t currentLevel, uint_fast64_t maxLevel) const;
756
767 void splitIntoGroupsRec(std::vector<MTBDD> const& dds, storm::storage::BitVector const& negatedDds,
768 std::vector<std::vector<InternalAdd<DdType::Sylvan, ValueType>>>& groups, std::vector<uint_fast64_t> const& ddGroupVariableIndices,
769 uint_fast64_t currentLevel, uint_fast64_t maxLevel) const;
770
782 static MTBDD fromVectorRec(uint_fast64_t& currentOffset, uint_fast64_t currentLevel, uint_fast64_t maxLevel, std::vector<ValueType> const& values,
783 Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices);
784
811 void toMatrixComponentsRec(MTBDD dd, bool negated, std::vector<uint_fast64_t> const& rowGroupOffsets, std::vector<uint_fast64_t>& rowIndications,
812 std::vector<storm::storage::MatrixEntry<uint_fast64_t, ValueType>>& columnsAndValues, Odd const& rowOdd, Odd const& columnOdd,
813 uint_fast64_t currentRowLevel, uint_fast64_t currentColumnLevel, uint_fast64_t maxLevel, uint_fast64_t currentRowOffset,
814 uint_fast64_t currentColumnOffset, std::vector<uint_fast64_t> const& ddRowVariableIndices,
815 std::vector<uint_fast64_t> const& ddColumnVariableIndices, bool writeValues) const;
816
822 static MTBDD getLeaf(double value);
823
829 static MTBDD getLeaf(uint_fast64_t value);
830
836 static MTBDD getLeaf(storm::RationalNumber const& value);
837
843 static MTBDD getLeaf(storm::RationalFunction const& value);
844
845 // The manager responsible for this MTBDD.
846 InternalDdManager<DdType::Sylvan> const* ddManager;
847
848 // The underlying sylvan MTBDD.
849 sylvan::Mtbdd sylvanMtbdd;
850#endif
851};
852} // namespace dd
853} // namespace storm
InternalAdd< DdType::Sylvan, double > toValueType() const
InternalBdd< DdType::CUDD > lessOrEqual(storm::RationalNumber const &value) const
InternalBdd< DdType::CUDD > greaterOrEqual(storm::RationalNumber const &value) const
bool equalModuloPrecision(InternalAdd< DdType::CUDD, storm::RationalNumber > const &, storm::RationalNumber const &, bool) const
InternalBdd< DdType::CUDD > less(storm::RationalNumber const &value) const
InternalBdd< DdType::CUDD > greater(storm::RationalNumber const &value) const