Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
InternalCuddAdd.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
15
16#ifdef STORM_HAVE_CUDD
17// Include the C++-interface of CUDD.
18#include "cuddObj.hh"
19#endif
20
21namespace storm {
22namespace storage {
23template<typename T>
24class SparseMatrix;
25
26class BitVector;
27
28template<typename E, typename V>
29class MatrixEntry;
30} // namespace storage
31
32namespace dd {
33template<DdType LibraryType>
34class DdManager;
35
36template<DdType LibraryType>
38
39template<DdType LibraryType>
41
42template<DdType LibraryType, typename ValueType>
43class AddIterator;
44
45namespace bisimulation {
46template<DdType LibraryType, typename ValueType>
48}
49
50template<typename ValueType>
51class InternalAdd<DdType::CUDD, ValueType> {
52 public:
53 friend class InternalBdd<DdType::CUDD>;
54
55 friend class bisimulation::InternalSignatureRefiner<DdType::CUDD, ValueType>;
56
57#ifdef STORM_HAVE_CUDD
64 InternalAdd(InternalDdManager<DdType::CUDD> const* ddManager, cudd::ADD cuddAdd);
65#endif
66
67 // Instantiate all copy/move constructors/assignments with the default implementation.
68 InternalAdd() = default;
69 InternalAdd(InternalAdd<DdType::CUDD, ValueType> const& other) = default;
70 InternalAdd& operator=(InternalAdd<DdType::CUDD, ValueType> const& other) = default;
71 InternalAdd(InternalAdd<DdType::CUDD, ValueType>&& other) = default;
72 InternalAdd& operator=(InternalAdd<DdType::CUDD, ValueType>&& other) = default;
73 virtual ~InternalAdd() = default;
74
81 bool operator==(InternalAdd<DdType::CUDD, ValueType> const& other) const;
82
89 bool operator!=(InternalAdd<DdType::CUDD, ValueType> const& other) const;
90
97 InternalAdd<DdType::CUDD, ValueType> operator+(InternalAdd<DdType::CUDD, ValueType> const& other) const;
98
105 InternalAdd<DdType::CUDD, ValueType>& operator+=(InternalAdd<DdType::CUDD, ValueType> const& other);
106
113 InternalAdd<DdType::CUDD, ValueType> operator*(InternalAdd<DdType::CUDD, ValueType> const& other) const;
114
121 InternalAdd<DdType::CUDD, ValueType>& operator*=(InternalAdd<DdType::CUDD, ValueType> const& other);
122
129 InternalAdd<DdType::CUDD, ValueType> operator-(InternalAdd<DdType::CUDD, ValueType> const& other) const;
130
137 InternalAdd<DdType::CUDD, ValueType>& operator-=(InternalAdd<DdType::CUDD, ValueType> const& other);
138
145 InternalAdd<DdType::CUDD, ValueType> operator/(InternalAdd<DdType::CUDD, ValueType> const& other) const;
146
153 InternalAdd<DdType::CUDD, ValueType>& operator/=(InternalAdd<DdType::CUDD, ValueType> const& other);
154
161 InternalBdd<DdType::CUDD> equals(InternalAdd<DdType::CUDD, ValueType> const& other) const;
162
169 InternalBdd<DdType::CUDD> notEquals(InternalAdd<DdType::CUDD, ValueType> const& other) const;
170
178 InternalBdd<DdType::CUDD> less(InternalAdd<DdType::CUDD, ValueType> const& other) const;
179
187 InternalBdd<DdType::CUDD> lessOrEqual(InternalAdd<DdType::CUDD, ValueType> const& other) const;
188
196 InternalBdd<DdType::CUDD> greater(InternalAdd<DdType::CUDD, ValueType> const& other) const;
197
205 InternalBdd<DdType::CUDD> greaterOrEqual(InternalAdd<DdType::CUDD, ValueType> const& other) const;
206
213 InternalAdd<DdType::CUDD, ValueType> pow(InternalAdd<DdType::CUDD, ValueType> const& other) const;
214
221 InternalAdd<DdType::CUDD, ValueType> mod(InternalAdd<DdType::CUDD, ValueType> const& other) const;
222
230 InternalAdd<DdType::CUDD, ValueType> logxy(InternalAdd<DdType::CUDD, ValueType> const& other) const;
231
237 InternalAdd<DdType::CUDD, ValueType> floor() const;
238
244 InternalAdd<DdType::CUDD, ValueType> ceil() const;
245
251 InternalAdd<DdType::CUDD, storm::RationalNumber> sharpenKwekMehlhorn(size_t precision) const;
252
259 InternalAdd<DdType::CUDD, ValueType> minimum(InternalAdd<DdType::CUDD, ValueType> const& other) const;
260
267 InternalAdd<DdType::CUDD, ValueType> maximum(InternalAdd<DdType::CUDD, ValueType> const& other) const;
268
274 template<typename TargetValueType>
275 typename std::enable_if<std::is_same<ValueType, TargetValueType>::value, InternalAdd<DdType::CUDD, TargetValueType>>::type toValueType() const;
276 template<typename TargetValueType>
277 typename std::enable_if<!std::is_same<ValueType, TargetValueType>::value, InternalAdd<DdType::CUDD, TargetValueType>>::type toValueType() const;
278
284 InternalAdd<DdType::CUDD, ValueType> sumAbstract(InternalBdd<DdType::CUDD> const& cube) const;
285
291 InternalAdd<DdType::CUDD, ValueType> minAbstract(InternalBdd<DdType::CUDD> const& cube) const;
292
298 InternalBdd<DdType::CUDD> minAbstractRepresentative(InternalBdd<DdType::CUDD> const& cube) const;
299
305 InternalAdd<DdType::CUDD, ValueType> maxAbstract(InternalBdd<DdType::CUDD> const& cube) const;
306
312 InternalBdd<DdType::CUDD> maxAbstractRepresentative(InternalBdd<DdType::CUDD> const& cube) const;
313
323 bool equalModuloPrecision(InternalAdd<DdType::CUDD, ValueType> const& other, ValueType const& precision, bool relative = true) const;
324
333 InternalAdd<DdType::CUDD, ValueType> swapVariables(std::vector<InternalBdd<DdType::CUDD>> const& from,
334 std::vector<InternalBdd<DdType::CUDD>> const& to) const;
335
344 InternalAdd<DdType::CUDD, ValueType> permuteVariables(std::vector<InternalBdd<DdType::CUDD>> const& from,
345 std::vector<InternalBdd<DdType::CUDD>> const& to) const;
346
355 InternalAdd<DdType::CUDD, ValueType> multiplyMatrix(InternalAdd<DdType::CUDD, ValueType> const& otherMatrix,
356 std::vector<InternalBdd<DdType::CUDD>> const& summationDdVariables) const;
357
366 InternalAdd<DdType::CUDD, ValueType> multiplyMatrix(InternalBdd<DdType::CUDD> const& otherMatrix,
367 std::vector<InternalBdd<DdType::CUDD>> const& summationDdVariables) const;
368
376 InternalBdd<DdType::CUDD> greater(ValueType const& value) const;
377
385 InternalBdd<DdType::CUDD> greaterOrEqual(ValueType const& value) const;
386
394 InternalBdd<DdType::CUDD> less(ValueType const& value) const;
395
403 InternalBdd<DdType::CUDD> lessOrEqual(ValueType const& value) const;
404
411 InternalBdd<DdType::CUDD> notZero() const;
412
421 InternalAdd<DdType::CUDD, ValueType> constrain(InternalAdd<DdType::CUDD, ValueType> const& constraint) const;
422
431 InternalAdd<DdType::CUDD, ValueType> restrict(InternalAdd<DdType::CUDD, ValueType> const& constraint) const;
432
438 InternalBdd<DdType::CUDD> getSupport() const;
439
446 uint_fast64_t getNonZeroCount(uint_fast64_t numberOfDdVariables) const;
447
453 virtual uint_fast64_t getLeafCount() const;
454
460 virtual uint_fast64_t getNodeCount() const;
461
467 ValueType getMin() const;
468
474 ValueType getMax() const;
475
481 ValueType getValue() const;
482
488 bool isOne() const;
489
495 bool isZero() const;
496
502 bool isConstant() const;
503
509 uint_fast64_t getIndex() const;
510
516 uint_fast64_t getLevel() const;
517
524 void exportToDot(std::string const& filename, std::vector<std::string> const& ddVariableNamesAsStrings, bool showVariablesIfPossible = true) const;
525
531 void exportToText(std::string const& filename) const;
543 AddIterator<DdType::CUDD, ValueType> begin(DdManager<DdType::CUDD> const& fullDdManager, InternalBdd<DdType::CUDD> const& variableCube,
544 uint_fast64_t numberOfDdVariables, std::set<storm::expressions::Variable> const& metaVariables,
545 bool enumerateDontCareMetaVariables = true) const;
546
553 AddIterator<DdType::CUDD, ValueType> end(DdManager<DdType::CUDD> const& fullDdManager) const;
554
565 void composeWithExplicitVector(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices, std::vector<ValueType>& targetVector,
566 std::function<ValueType(ValueType const&, ValueType const&)> const& function) const;
567
578 void forEach(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices,
579 std::function<void(uint64_t const&, ValueType const&)> const& function) const;
580
592 void composeWithExplicitVector(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices, std::vector<uint_fast64_t> const& offsets,
593 std::vector<ValueType>& targetVector, std::function<ValueType(ValueType const&, ValueType const&)> const& function) const;
594
601 std::vector<InternalAdd<DdType::CUDD, ValueType>> splitIntoGroups(std::vector<uint_fast64_t> const& ddGroupVariableIndices) const;
602
611 std::vector<uint64_t> decodeGroupLabels(std::vector<uint_fast64_t> const& ddGroupVariableIndices,
612 storm::storage::BitVector const& ddLabelVariableIndices) const;
613
623 std::vector<std::pair<InternalAdd<DdType::CUDD, ValueType>, InternalAdd<DdType::CUDD, ValueType>>> splitIntoGroups(
624 InternalAdd<DdType::CUDD, ValueType> vector, std::vector<uint_fast64_t> const& ddGroupVariableIndices) const;
625
635 std::vector<std::vector<InternalAdd<DdType::CUDD, ValueType>>> splitIntoGroups(std::vector<InternalAdd<DdType::CUDD, ValueType>> const& vectors,
636 std::vector<uint_fast64_t> const& ddGroupVariableIndices) const;
637
651 void toMatrixComponents(std::vector<uint_fast64_t> const& rowGroupIndices, std::vector<uint_fast64_t>& rowIndications,
652 std::vector<storm::storage::MatrixEntry<uint_fast64_t, ValueType>>& columnsAndValues, Odd const& rowOdd, Odd const& columnOdd,
653 std::vector<uint_fast64_t> const& ddRowVariableIndices, std::vector<uint_fast64_t> const& ddColumnVariableIndices,
654 bool writeValues) const;
655
664 static InternalAdd<DdType::CUDD, ValueType> fromVector(InternalDdManager<DdType::CUDD> const* ddManager, std::vector<ValueType> const& values,
665 storm::dd::Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices);
666
672 Odd createOdd(std::vector<uint_fast64_t> const& ddVariableIndices) const;
673
674 InternalDdManager<DdType::CUDD> const& getInternalDdManager() const;
675
676#ifdef STORM_HAVE_CUDD
682 cudd::ADD getCuddAdd() const;
683
689 DdNode* getCuddDdNode() const;
690#endif
691
695 std::string getStringId() const;
696
697 private:
698#ifdef STORM_HAVE_CUDD
711 void forEachRec(DdNode const* dd, uint_fast64_t currentLevel, uint_fast64_t maxLevel, uint_fast64_t currentOffset, Odd const& odd,
712 std::vector<uint_fast64_t> const& ddVariableIndices, std::function<void(uint64_t const&, ValueType const&)> const& function) const;
713
724 void splitIntoGroupsRec(DdNode* dd, std::vector<InternalAdd<DdType::CUDD, ValueType>>& groups, std::vector<uint_fast64_t> const& ddGroupVariableIndices,
725 uint_fast64_t currentLevel, uint_fast64_t maxLevel) const;
726
739 void decodeGroupLabelsRec(DdNode* dd, std::vector<uint64_t>& labels, std::vector<uint_fast64_t> const& ddGroupVariableIndices,
740 storm::storage::BitVector const& ddLabelVariableIndices, uint_fast64_t currentLevel, uint_fast64_t maxLevel,
741 uint64_t label) const;
742
754 void splitIntoGroupsRec(DdNode* dd1, DdNode* dd2,
755 std::vector<std::pair<InternalAdd<DdType::CUDD, ValueType>, InternalAdd<DdType::CUDD, ValueType>>>& groups,
756 std::vector<uint_fast64_t> const& ddGroupVariableIndices, uint_fast64_t currentLevel, uint_fast64_t maxLevel) const;
757
768 void splitIntoGroupsRec(std::vector<DdNode*> const& dds, std::vector<std::vector<InternalAdd<DdType::CUDD, ValueType>>>& groups,
769 std::vector<uint_fast64_t> const& ddGroupVariableIndices, uint_fast64_t currentLevel, uint_fast64_t maxLevel) const;
770
796 void toMatrixComponentsRec(DdNode const* dd, std::vector<uint_fast64_t> const& rowGroupOffsets, std::vector<uint_fast64_t>& rowIndications,
797 std::vector<storm::storage::MatrixEntry<uint_fast64_t, ValueType>>& columnsAndValues, Odd const& rowOdd, Odd const& columnOdd,
798 uint_fast64_t currentRowLevel, uint_fast64_t currentColumnLevel, uint_fast64_t maxLevel, uint_fast64_t currentRowOffset,
799 uint_fast64_t currentColumnOffset, std::vector<uint_fast64_t> const& ddRowVariableIndices,
800 std::vector<uint_fast64_t> const& ddColumnVariableIndices, bool writeValues) const;
801
814 static DdNode* fromVectorRec(::DdManager* manager, uint_fast64_t& currentOffset, uint_fast64_t currentLevel, uint_fast64_t maxLevel,
815 std::vector<ValueType> const& values, Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices);
816
829 static std::shared_ptr<Odd> createOddRec(DdNode* dd, cudd::Cudd const& manager, uint_fast64_t currentLevel, uint_fast64_t maxLevel,
830 std::vector<uint_fast64_t> const& ddVariableIndices,
831 std::vector<std::unordered_map<DdNode*, std::shared_ptr<Odd>>>& uniqueTableForLevels);
832
833 InternalDdManager<DdType::CUDD> const* ddManager;
834
835 cudd::ADD cuddAdd;
836#endif
837};
838} // namespace dd
839} // 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