Storm 1.14.0.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
11#include "storm/adapters/cudd.h"
16
17namespace storm {
18namespace storage {
19template<typename T>
20class SparseMatrix;
21
22class BitVector;
23
24template<typename E, typename V>
25class MatrixEntry;
26} // namespace storage
27
28namespace dd {
29template<DdType LibraryType>
30class DdManager;
31
32template<DdType LibraryType>
34
35template<DdType LibraryType>
37
38template<DdType LibraryType, typename ValueType>
39class AddIterator;
40
41namespace bisimulation {
42template<DdType LibraryType, typename ValueType>
44}
45
46template<typename ValueType>
47class InternalAdd<DdType::CUDD, ValueType> {
48 public:
49 friend class InternalBdd<DdType::CUDD>;
50
51 friend class bisimulation::InternalSignatureRefiner<DdType::CUDD, ValueType>;
52
53#ifdef STORM_HAVE_CUDD
60 InternalAdd(InternalDdManager<DdType::CUDD> const* ddManager, cudd::ADD cuddAdd);
61#endif
62
63 // Instantiate all copy/move constructors/assignments with the default implementation.
64 InternalAdd() = default;
65 InternalAdd(InternalAdd<DdType::CUDD, ValueType> const& other) = default;
66 InternalAdd& operator=(InternalAdd<DdType::CUDD, ValueType> const& other) = default;
67 InternalAdd(InternalAdd<DdType::CUDD, ValueType>&& other) = default;
68 InternalAdd& operator=(InternalAdd<DdType::CUDD, ValueType>&& other) = default;
69 virtual ~InternalAdd() = default;
70
77 bool operator==(InternalAdd<DdType::CUDD, ValueType> const& other) const;
78
85 bool operator!=(InternalAdd<DdType::CUDD, ValueType> const& other) const;
86
93 InternalAdd<DdType::CUDD, ValueType> operator+(InternalAdd<DdType::CUDD, ValueType> const& other) const;
94
101 InternalAdd<DdType::CUDD, ValueType>& operator+=(InternalAdd<DdType::CUDD, ValueType> const& other);
102
109 InternalAdd<DdType::CUDD, ValueType> operator*(InternalAdd<DdType::CUDD, ValueType> const& other) const;
110
117 InternalAdd<DdType::CUDD, ValueType>& operator*=(InternalAdd<DdType::CUDD, ValueType> const& other);
118
125 InternalAdd<DdType::CUDD, ValueType> operator-(InternalAdd<DdType::CUDD, ValueType> const& other) const;
126
133 InternalAdd<DdType::CUDD, ValueType>& operator-=(InternalAdd<DdType::CUDD, ValueType> const& other);
134
141 InternalAdd<DdType::CUDD, ValueType> operator/(InternalAdd<DdType::CUDD, ValueType> const& other) const;
142
149 InternalAdd<DdType::CUDD, ValueType>& operator/=(InternalAdd<DdType::CUDD, ValueType> const& other);
150
157 InternalBdd<DdType::CUDD> equals(InternalAdd<DdType::CUDD, ValueType> const& other) const;
158
165 InternalBdd<DdType::CUDD> notEquals(InternalAdd<DdType::CUDD, ValueType> const& other) const;
166
174 InternalBdd<DdType::CUDD> less(InternalAdd<DdType::CUDD, ValueType> const& other) const;
175
183 InternalBdd<DdType::CUDD> lessOrEqual(InternalAdd<DdType::CUDD, ValueType> const& other) const;
184
192 InternalBdd<DdType::CUDD> greater(InternalAdd<DdType::CUDD, ValueType> const& other) const;
193
201 InternalBdd<DdType::CUDD> greaterOrEqual(InternalAdd<DdType::CUDD, ValueType> const& other) const;
202
209 InternalAdd<DdType::CUDD, ValueType> pow(InternalAdd<DdType::CUDD, ValueType> const& other) const;
210
217 InternalAdd<DdType::CUDD, ValueType> mod(InternalAdd<DdType::CUDD, ValueType> const& other) const;
218
226 InternalAdd<DdType::CUDD, ValueType> logxy(InternalAdd<DdType::CUDD, ValueType> const& other) const;
227
233 InternalAdd<DdType::CUDD, ValueType> floor() const;
234
240 InternalAdd<DdType::CUDD, ValueType> ceil() const;
241
247 InternalAdd<DdType::CUDD, storm::RationalNumber> sharpenKwekMehlhorn(size_t precision) const;
248
255 InternalAdd<DdType::CUDD, ValueType> minimum(InternalAdd<DdType::CUDD, ValueType> const& other) const;
256
263 InternalAdd<DdType::CUDD, ValueType> maximum(InternalAdd<DdType::CUDD, ValueType> const& other) const;
264
270 template<typename TargetValueType>
271 typename std::enable_if<std::is_same<ValueType, TargetValueType>::value, InternalAdd<DdType::CUDD, TargetValueType>>::type toValueType() const;
272 template<typename TargetValueType>
273 typename std::enable_if<!std::is_same<ValueType, TargetValueType>::value, InternalAdd<DdType::CUDD, TargetValueType>>::type toValueType() const;
274
280 InternalAdd<DdType::CUDD, ValueType> sumAbstract(InternalBdd<DdType::CUDD> const& cube) const;
281
287 InternalAdd<DdType::CUDD, ValueType> minAbstract(InternalBdd<DdType::CUDD> const& cube) const;
288
294 InternalBdd<DdType::CUDD> minAbstractRepresentative(InternalBdd<DdType::CUDD> const& cube) const;
295
301 InternalAdd<DdType::CUDD, ValueType> maxAbstract(InternalBdd<DdType::CUDD> const& cube) const;
302
308 InternalBdd<DdType::CUDD> maxAbstractRepresentative(InternalBdd<DdType::CUDD> const& cube) const;
309
319 bool equalModuloPrecision(InternalAdd<DdType::CUDD, ValueType> const& other, ValueType const& precision, bool relative = true) const;
320
329 InternalAdd<DdType::CUDD, ValueType> swapVariables(std::vector<InternalBdd<DdType::CUDD>> const& from,
330 std::vector<InternalBdd<DdType::CUDD>> const& to) const;
331
340 InternalAdd<DdType::CUDD, ValueType> permuteVariables(std::vector<InternalBdd<DdType::CUDD>> const& from,
341 std::vector<InternalBdd<DdType::CUDD>> const& to) const;
342
351 InternalAdd<DdType::CUDD, ValueType> multiplyMatrix(InternalAdd<DdType::CUDD, ValueType> const& otherMatrix,
352 std::vector<InternalBdd<DdType::CUDD>> const& summationDdVariables) const;
353
362 InternalAdd<DdType::CUDD, ValueType> multiplyMatrix(InternalBdd<DdType::CUDD> const& otherMatrix,
363 std::vector<InternalBdd<DdType::CUDD>> const& summationDdVariables) const;
364
372 InternalBdd<DdType::CUDD> greater(ValueType const& value) const;
373
381 InternalBdd<DdType::CUDD> greaterOrEqual(ValueType const& value) const;
382
390 InternalBdd<DdType::CUDD> less(ValueType const& value) const;
391
399 InternalBdd<DdType::CUDD> lessOrEqual(ValueType const& value) const;
400
407 InternalBdd<DdType::CUDD> notZero() const;
408
417 InternalAdd<DdType::CUDD, ValueType> constrain(InternalAdd<DdType::CUDD, ValueType> const& constraint) const;
418
427 InternalAdd<DdType::CUDD, ValueType> restrict(InternalAdd<DdType::CUDD, ValueType> const& constraint) const;
428
434 InternalBdd<DdType::CUDD> getSupport() const;
435
442 uint_fast64_t getNonZeroCount(uint_fast64_t numberOfDdVariables) const;
443
449 virtual uint_fast64_t getLeafCount() const;
450
456 virtual uint_fast64_t getNodeCount() const;
457
463 ValueType getMin() const;
464
470 ValueType getMax() const;
471
477 ValueType getValue() const;
478
484 bool isOne() const;
485
491 bool isZero() const;
492
498 bool isConstant() const;
499
505 uint_fast64_t getIndex() const;
506
512 uint_fast64_t getLevel() const;
513
520 void exportToDot(std::string const& filename, std::vector<std::string> const& ddVariableNamesAsStrings, bool showVariablesIfPossible = true) const;
521
527 void exportToText(std::string const& filename) const;
539 AddIterator<DdType::CUDD, ValueType> begin(DdManager<DdType::CUDD> const& fullDdManager, InternalBdd<DdType::CUDD> const& variableCube,
540 uint_fast64_t numberOfDdVariables, std::set<storm::expressions::Variable> const& metaVariables,
541 bool enumerateDontCareMetaVariables = true) const;
542
549 AddIterator<DdType::CUDD, ValueType> end(DdManager<DdType::CUDD> const& fullDdManager) const;
550
561 void composeWithExplicitVector(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices, std::vector<ValueType>& targetVector,
562 std::function<ValueType(ValueType const&, ValueType const&)> const& function) const;
563
574 void forEach(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices,
575 std::function<void(uint64_t const&, ValueType const&)> const& function) const;
576
588 void composeWithExplicitVector(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices, std::vector<uint_fast64_t> const& offsets,
589 std::vector<ValueType>& targetVector, std::function<ValueType(ValueType const&, ValueType const&)> const& function) const;
590
597 std::vector<InternalAdd<DdType::CUDD, ValueType>> splitIntoGroups(std::vector<uint_fast64_t> const& ddGroupVariableIndices) const;
598
607 std::vector<uint64_t> decodeGroupLabels(std::vector<uint_fast64_t> const& ddGroupVariableIndices,
608 storm::storage::BitVector const& ddLabelVariableIndices) const;
609
619 std::vector<std::pair<InternalAdd<DdType::CUDD, ValueType>, InternalAdd<DdType::CUDD, ValueType>>> splitIntoGroups(
620 InternalAdd<DdType::CUDD, ValueType> vector, std::vector<uint_fast64_t> const& ddGroupVariableIndices) const;
621
631 std::vector<std::vector<InternalAdd<DdType::CUDD, ValueType>>> splitIntoGroups(std::vector<InternalAdd<DdType::CUDD, ValueType>> const& vectors,
632 std::vector<uint_fast64_t> const& ddGroupVariableIndices) const;
633
647 void toMatrixComponents(std::vector<uint_fast64_t> const& rowGroupIndices, std::vector<uint_fast64_t>& rowIndications,
648 std::vector<storm::storage::MatrixEntry<uint_fast64_t, ValueType>>& columnsAndValues, Odd const& rowOdd, Odd const& columnOdd,
649 std::vector<uint_fast64_t> const& ddRowVariableIndices, std::vector<uint_fast64_t> const& ddColumnVariableIndices,
650 bool writeValues) const;
651
660 static InternalAdd<DdType::CUDD, ValueType> fromVector(InternalDdManager<DdType::CUDD> const* ddManager, std::vector<ValueType> const& values,
661 storm::dd::Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices);
662
668 Odd createOdd(std::vector<uint_fast64_t> const& ddVariableIndices) const;
669
670 InternalDdManager<DdType::CUDD> const& getInternalDdManager() const;
671
672#ifdef STORM_HAVE_CUDD
678 cudd::ADD getCuddAdd() const;
679
685 DdNode* getCuddDdNode() const;
686#endif
687
691 std::string getStringId() const;
692
693 private:
694#ifdef STORM_HAVE_CUDD
707 void forEachRec(DdNode const* dd, uint_fast64_t currentLevel, uint_fast64_t maxLevel, uint_fast64_t currentOffset, Odd const& odd,
708 std::vector<uint_fast64_t> const& ddVariableIndices, std::function<void(uint64_t const&, ValueType const&)> const& function) const;
709
720 void splitIntoGroupsRec(DdNode* dd, std::vector<InternalAdd<DdType::CUDD, ValueType>>& groups, std::vector<uint_fast64_t> const& ddGroupVariableIndices,
721 uint_fast64_t currentLevel, uint_fast64_t maxLevel) const;
722
735 void decodeGroupLabelsRec(DdNode* dd, std::vector<uint64_t>& labels, std::vector<uint_fast64_t> const& ddGroupVariableIndices,
736 storm::storage::BitVector const& ddLabelVariableIndices, uint_fast64_t currentLevel, uint_fast64_t maxLevel,
737 uint64_t label) const;
738
750 void splitIntoGroupsRec(DdNode* dd1, DdNode* dd2,
751 std::vector<std::pair<InternalAdd<DdType::CUDD, ValueType>, InternalAdd<DdType::CUDD, ValueType>>>& groups,
752 std::vector<uint_fast64_t> const& ddGroupVariableIndices, uint_fast64_t currentLevel, uint_fast64_t maxLevel) const;
753
764 void splitIntoGroupsRec(std::vector<DdNode*> const& dds, std::vector<std::vector<InternalAdd<DdType::CUDD, ValueType>>>& groups,
765 std::vector<uint_fast64_t> const& ddGroupVariableIndices, uint_fast64_t currentLevel, uint_fast64_t maxLevel) const;
766
792 void toMatrixComponentsRec(DdNode const* dd, std::vector<uint_fast64_t> const& rowGroupOffsets, std::vector<uint_fast64_t>& rowIndications,
793 std::vector<storm::storage::MatrixEntry<uint_fast64_t, ValueType>>& columnsAndValues, Odd const& rowOdd, Odd const& columnOdd,
794 uint_fast64_t currentRowLevel, uint_fast64_t currentColumnLevel, uint_fast64_t maxLevel, uint_fast64_t currentRowOffset,
795 uint_fast64_t currentColumnOffset, std::vector<uint_fast64_t> const& ddRowVariableIndices,
796 std::vector<uint_fast64_t> const& ddColumnVariableIndices, bool writeValues) const;
797
810 static DdNode* fromVectorRec(::DdManager* manager, uint_fast64_t& currentOffset, uint_fast64_t currentLevel, uint_fast64_t maxLevel,
811 std::vector<ValueType> const& values, Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices);
812
825 static std::shared_ptr<Odd> createOddRec(DdNode* dd, cudd::Cudd const& manager, uint_fast64_t currentLevel, uint_fast64_t maxLevel,
826 std::vector<uint_fast64_t> const& ddVariableIndices,
827 std::vector<std::unordered_map<DdNode*, std::shared_ptr<Odd>>>& uniqueTableForLevels);
828
829 InternalDdManager<DdType::CUDD> const* ddManager;
830
831 cudd::ADD cuddAdd;
832#endif
833};
834} // namespace dd
835} // namespace storm
InternalBdd< DdType::CUDD > equals(InternalAdd< DdType::CUDD, ValueType > const &other) const
Retrieves the function that maps all evaluations to one that have identical function values.
std::string getStringId() const
Retrieves a string representation of an ID for thid ADD.
uint_fast64_t getIndex() const
Retrieves the index of the topmost variable in the ADD.
InternalBdd< DdType::CUDD > greater(InternalAdd< DdType::CUDD, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are gre...
AddIterator< DdType::CUDD, ValueType > end(DdManager< DdType::CUDD > const &fullDdManager) const
Retrieves an iterator that points past the end of the container.
InternalAdd< DdType::CUDD, ValueType > maximum(InternalAdd< DdType::CUDD, ValueType > const &other) const
Retrieves the function that maps all evaluations to the maximum of the function values of the two ADD...
InternalAdd< DdType::CUDD, ValueType > ceil() const
Retrieves the function that ceils all values in the current ADD.
InternalAdd< DdType::CUDD, ValueType > logxy(InternalAdd< DdType::CUDD, ValueType > const &other) const
Retrieves the function that represents the logarithm of the current ADD to the bases given by the sec...
AddIterator< DdType::CUDD, ValueType > begin(DdManager< DdType::CUDD > const &fullDdManager, InternalBdd< DdType::CUDD > const &variableCube, uint_fast64_t numberOfDdVariables, std::set< storm::expressions::Variable > const &metaVariables, bool enumerateDontCareMetaVariables=true) const
Retrieves an iterator that points to the first meta variable assignment with a non-zero function valu...
InternalBdd< DdType::CUDD > notZero() const
Computes a BDD that represents the function in which all assignments with a function value unequal to...
InternalAdd< DdType::CUDD, ValueType > mod(InternalAdd< DdType::CUDD, ValueType > const &other) const
Retrieves the function that represents the current ADD modulo the given ADD.
InternalBdd< DdType::CUDD > minAbstractRepresentative(InternalBdd< DdType::CUDD > const &cube) const
Min-abstracts from the given cube and returns a representative.
InternalAdd< DdType::CUDD, ValueType > minimum(InternalAdd< DdType::CUDD, ValueType > const &other) const
Retrieves the function that maps all evaluations to the minimum of the function values of the two ADD...
ValueType getMin() const
Retrieves the lowest function value of any encoding.
InternalAdd< DdType::CUDD, ValueType > pow(InternalAdd< DdType::CUDD, ValueType > const &other) const
Retrieves the function that represents the current ADD to the power of the given ADD.
void composeWithExplicitVector(Odd const &odd, std::vector< uint_fast64_t > const &ddVariableIndices, std::vector< ValueType > &targetVector, std::function< ValueType(ValueType const &, ValueType const &)> const &function) const
Composes the ADD with an explicit vector by performing a specified function between the entries of th...
InternalDdManager< DdType::CUDD > const & getInternalDdManager() const
bool equalModuloPrecision(InternalAdd< DdType::CUDD, ValueType > const &other, ValueType const &precision, bool relative=true) const
Checks whether the current and the given ADD represent the same function modulo some given precision.
InternalAdd< DdType::CUDD, storm::RationalNumber > sharpenKwekMehlhorn(size_t precision) const
Retrieves the function that sharpens all values in the current ADD with the Kwek-Mehlhorn algorithm.
Odd createOdd(std::vector< uint_fast64_t > const &ddVariableIndices) const
Creates an ODD based on the current ADD.
bool isConstant() const
Retrieves whether this ADD represents a constant function.
uint_fast64_t getLevel() const
Retrieves the level of the topmost variable in the ADD.
ValueType getValue() const
Retrieves the value of this ADD that is required to be a leaf.
InternalAdd< DdType::CUDD, ValueType > floor() const
Retrieves the function that floors all values in the current ADD.
InternalAdd< DdType::CUDD, ValueType > permuteVariables(std::vector< InternalBdd< DdType::CUDD > > const &from, std::vector< InternalBdd< DdType::CUDD > > const &to) const
Permutes the given pairs of DD variables in the ADD.
void exportToDot(std::string const &filename, std::vector< std::string > const &ddVariableNamesAsStrings, bool showVariablesIfPossible=true) const
Exports the DD to the given file in the dot format.
std::vector< uint64_t > decodeGroupLabels(std::vector< uint_fast64_t > const &ddGroupVariableIndices, storm::storage::BitVector const &ddLabelVariableIndices) const
Splits the ADD into several ADDs that differ in the encoding of the given group variables (given via ...
InternalBdd< DdType::CUDD > greaterOrEqual(InternalAdd< DdType::CUDD, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are gre...
InternalBdd< DdType::CUDD > lessOrEqual(InternalAdd< DdType::CUDD, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are les...
void exportToText(std::string const &filename) const
Exports the DD to the given file in a textual format as specified in Sylvan.
ValueType getMax() const
Retrieves the highest function value of any encoding.
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 > maxAbstractRepresentative(InternalBdd< DdType::CUDD > const &cube) const
Max-abstracts from the given cube and returns a representative.
InternalAdd< DdType::CUDD, ValueType > maxAbstract(InternalBdd< DdType::CUDD > const &cube) const
Max-abstracts from the given cube.
InternalBdd< DdType::CUDD > getSupport() const
Retrieves the support of the current ADD.
InternalAdd< DdType::CUDD, ValueType > sumAbstract(InternalBdd< DdType::CUDD > const &cube) const
Sum-abstracts from the given cube.
void toMatrixComponents(std::vector< uint_fast64_t > const &rowGroupIndices, std::vector< uint_fast64_t > &rowIndications, std::vector< storm::storage::MatrixEntry< uint_fast64_t, ValueType > > &columnsAndValues, Odd const &rowOdd, Odd const &columnOdd, std::vector< uint_fast64_t > const &ddRowVariableIndices, std::vector< uint_fast64_t > const &ddColumnVariableIndices, bool writeValues) const
Translates the ADD into the components needed for constructing a matrix.
InternalAdd< DdType::CUDD, ValueType > constrain(InternalAdd< DdType::CUDD, ValueType > const &constraint) const
Computes the constraint of the current ADD with the given constraint.
std::enable_if< std::is_same< ValueType, TargetValueType >::value, InternalAdd< DdType::CUDD, TargetValueType > >::type toValueType() const
Replaces the leaves in this MTBDD with the converted values in the target value type.
bool isZero() const
Retrieves whether this ADD represents the constant zero function.
std::vector< InternalAdd< DdType::CUDD, ValueType > > splitIntoGroups(std::vector< uint_fast64_t > const &ddGroupVariableIndices) const
Splits the ADD into several ADDs that differ in the encoding of the given group variables (given via ...
InternalAdd< DdType::CUDD, ValueType > minAbstract(InternalBdd< DdType::CUDD > const &cube) const
Min-abstracts from the given cube.
static InternalAdd< DdType::CUDD, ValueType > fromVector(InternalDdManager< DdType::CUDD > const *ddManager, std::vector< ValueType > const &values, storm::dd::Odd const &odd, std::vector< uint_fast64_t > const &ddVariableIndices)
Creates an ADD from the given explicit vector.
InternalAdd< DdType::CUDD, ValueType > 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 ADD.
virtual uint_fast64_t getLeafCount() const
Retrieves the number of leaves of the ADD.
InternalAdd< DdType::CUDD, ValueType > restrict(InternalAdd< DdType::CUDD, ValueType > const &constraint) const
Computes the restriction of the current ADD with the given constraint.
bool isOne() const
Retrieves whether this ADD represents the constant one function.
InternalBdd< DdType::CUDD > less(InternalAdd< DdType::CUDD, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are les...
void forEach(Odd const &odd, std::vector< uint_fast64_t > const &ddVariableIndices, std::function< void(uint64_t const &, ValueType const &)> const &function) const
Composes the ADD with an explicit vector by performing a specified function between the entries of th...
virtual uint_fast64_t getNodeCount() const
Retrieves the number of nodes necessary to represent the DD.
InternalAdd< DdType::CUDD, ValueType > multiplyMatrix(InternalAdd< DdType::CUDD, ValueType > const &otherMatrix, std::vector< InternalBdd< DdType::CUDD > > const &summationDdVariables) const
Multiplies the current ADD (representing a matrix) with the given matrix by summing over the given me...
InternalBdd< DdType::CUDD > notEquals(InternalAdd< DdType::CUDD, ValueType > const &other) const
Retrieves the function that maps all evaluations to one that have distinct function values.