Storm 1.13.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
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
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.