Storm 2.0.0.3
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"
12#include "storm/dd/DdType.h"
14#include "storm/dd/Odd.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
248 InternalAdd<DdType::CUDD, ValueType> minimum(InternalAdd<DdType::CUDD, ValueType> const& other) const;
249
256 InternalAdd<DdType::CUDD, ValueType> maximum(InternalAdd<DdType::CUDD, ValueType> const& other) const;
257
263 template<typename TargetValueType>
264 typename std::enable_if<std::is_same<ValueType, TargetValueType>::value, InternalAdd<DdType::CUDD, TargetValueType>>::type toValueType() const;
265 template<typename TargetValueType>
266 typename std::enable_if<!std::is_same<ValueType, TargetValueType>::value, InternalAdd<DdType::CUDD, TargetValueType>>::type toValueType() const;
267
273 InternalAdd<DdType::CUDD, ValueType> sumAbstract(InternalBdd<DdType::CUDD> const& cube) const;
274
280 InternalAdd<DdType::CUDD, ValueType> minAbstract(InternalBdd<DdType::CUDD> const& cube) const;
281
287 InternalBdd<DdType::CUDD> minAbstractRepresentative(InternalBdd<DdType::CUDD> const& cube) const;
288
294 InternalAdd<DdType::CUDD, ValueType> maxAbstract(InternalBdd<DdType::CUDD> const& cube) const;
295
301 InternalBdd<DdType::CUDD> maxAbstractRepresentative(InternalBdd<DdType::CUDD> const& cube) const;
302
312 bool equalModuloPrecision(InternalAdd<DdType::CUDD, ValueType> const& other, ValueType const& precision, bool relative = true) const;
313
322 InternalAdd<DdType::CUDD, ValueType> swapVariables(std::vector<InternalBdd<DdType::CUDD>> const& from,
323 std::vector<InternalBdd<DdType::CUDD>> const& to) const;
324
333 InternalAdd<DdType::CUDD, ValueType> permuteVariables(std::vector<InternalBdd<DdType::CUDD>> const& from,
334 std::vector<InternalBdd<DdType::CUDD>> const& to) const;
335
344 InternalAdd<DdType::CUDD, ValueType> multiplyMatrix(InternalAdd<DdType::CUDD, ValueType> const& otherMatrix,
345 std::vector<InternalBdd<DdType::CUDD>> const& summationDdVariables) const;
346
355 InternalAdd<DdType::CUDD, ValueType> multiplyMatrix(InternalBdd<DdType::CUDD> const& otherMatrix,
356 std::vector<InternalBdd<DdType::CUDD>> const& summationDdVariables) const;
357
365 InternalBdd<DdType::CUDD> greater(ValueType const& value) const;
366
374 InternalBdd<DdType::CUDD> greaterOrEqual(ValueType const& value) const;
375
383 InternalBdd<DdType::CUDD> less(ValueType const& value) const;
384
392 InternalBdd<DdType::CUDD> lessOrEqual(ValueType const& value) const;
393
400 InternalBdd<DdType::CUDD> notZero() const;
401
410 InternalAdd<DdType::CUDD, ValueType> constrain(InternalAdd<DdType::CUDD, ValueType> const& constraint) const;
411
420 InternalAdd<DdType::CUDD, ValueType> restrict(InternalAdd<DdType::CUDD, ValueType> const& constraint) const;
421
427 InternalBdd<DdType::CUDD> getSupport() const;
428
435 uint_fast64_t getNonZeroCount(uint_fast64_t numberOfDdVariables) const;
436
442 virtual uint_fast64_t getLeafCount() const;
443
449 virtual uint_fast64_t getNodeCount() const;
450
456 ValueType getMin() const;
457
463 ValueType getMax() const;
464
470 ValueType getValue() const;
471
477 bool isOne() const;
478
484 bool isZero() const;
485
491 bool isConstant() const;
492
498 uint_fast64_t getIndex() const;
499
505 uint_fast64_t getLevel() const;
506
513 void exportToDot(std::string const& filename, std::vector<std::string> const& ddVariableNamesAsStrings, bool showVariablesIfPossible = true) const;
514
520 void exportToText(std::string const& filename) const;
532 AddIterator<DdType::CUDD, ValueType> begin(DdManager<DdType::CUDD> const& fullDdManager, InternalBdd<DdType::CUDD> const& variableCube,
533 uint_fast64_t numberOfDdVariables, std::set<storm::expressions::Variable> const& metaVariables,
534 bool enumerateDontCareMetaVariables = true) const;
535
542 AddIterator<DdType::CUDD, ValueType> end(DdManager<DdType::CUDD> const& fullDdManager) const;
543
554 void composeWithExplicitVector(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices, std::vector<ValueType>& targetVector,
555 std::function<ValueType(ValueType const&, ValueType const&)> const& function) const;
556
567 void forEach(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices,
568 std::function<void(uint64_t const&, ValueType const&)> const& function) const;
569
581 void composeWithExplicitVector(Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices, std::vector<uint_fast64_t> const& offsets,
582 std::vector<ValueType>& targetVector, std::function<ValueType(ValueType const&, ValueType const&)> const& function) const;
583
590 std::vector<InternalAdd<DdType::CUDD, ValueType>> splitIntoGroups(std::vector<uint_fast64_t> const& ddGroupVariableIndices) const;
591
600 std::vector<uint64_t> decodeGroupLabels(std::vector<uint_fast64_t> const& ddGroupVariableIndices,
601 storm::storage::BitVector const& ddLabelVariableIndices) const;
602
612 std::vector<std::pair<InternalAdd<DdType::CUDD, ValueType>, InternalAdd<DdType::CUDD, ValueType>>> splitIntoGroups(
613 InternalAdd<DdType::CUDD, ValueType> vector, std::vector<uint_fast64_t> const& ddGroupVariableIndices) const;
614
624 std::vector<std::vector<InternalAdd<DdType::CUDD, ValueType>>> splitIntoGroups(std::vector<InternalAdd<DdType::CUDD, ValueType>> const& vectors,
625 std::vector<uint_fast64_t> const& ddGroupVariableIndices) const;
626
640 void toMatrixComponents(std::vector<uint_fast64_t> const& rowGroupIndices, std::vector<uint_fast64_t>& rowIndications,
641 std::vector<storm::storage::MatrixEntry<uint_fast64_t, ValueType>>& columnsAndValues, Odd const& rowOdd, Odd const& columnOdd,
642 std::vector<uint_fast64_t> const& ddRowVariableIndices, std::vector<uint_fast64_t> const& ddColumnVariableIndices,
643 bool writeValues) const;
644
653 static InternalAdd<DdType::CUDD, ValueType> fromVector(InternalDdManager<DdType::CUDD> const* ddManager, std::vector<ValueType> const& values,
654 storm::dd::Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices);
655
661 Odd createOdd(std::vector<uint_fast64_t> const& ddVariableIndices) const;
662
663 InternalDdManager<DdType::CUDD> const& getInternalDdManager() const;
664
665#ifdef STORM_HAVE_CUDD
671 cudd::ADD getCuddAdd() const;
672
678 DdNode* getCuddDdNode() const;
679#endif
680
684 std::string getStringId() const;
685
686 private:
687#ifdef STORM_HAVE_CUDD
700 void forEachRec(DdNode const* dd, uint_fast64_t currentLevel, uint_fast64_t maxLevel, uint_fast64_t currentOffset, Odd const& odd,
701 std::vector<uint_fast64_t> const& ddVariableIndices, std::function<void(uint64_t const&, ValueType const&)> const& function) const;
702
713 void splitIntoGroupsRec(DdNode* dd, std::vector<InternalAdd<DdType::CUDD, ValueType>>& groups, std::vector<uint_fast64_t> const& ddGroupVariableIndices,
714 uint_fast64_t currentLevel, uint_fast64_t maxLevel) const;
715
728 void decodeGroupLabelsRec(DdNode* dd, std::vector<uint64_t>& labels, std::vector<uint_fast64_t> const& ddGroupVariableIndices,
729 storm::storage::BitVector const& ddLabelVariableIndices, uint_fast64_t currentLevel, uint_fast64_t maxLevel,
730 uint64_t label) const;
731
743 void splitIntoGroupsRec(DdNode* dd1, DdNode* dd2,
744 std::vector<std::pair<InternalAdd<DdType::CUDD, ValueType>, InternalAdd<DdType::CUDD, ValueType>>>& groups,
745 std::vector<uint_fast64_t> const& ddGroupVariableIndices, uint_fast64_t currentLevel, uint_fast64_t maxLevel) const;
746
757 void splitIntoGroupsRec(std::vector<DdNode*> const& dds, std::vector<std::vector<InternalAdd<DdType::CUDD, ValueType>>>& groups,
758 std::vector<uint_fast64_t> const& ddGroupVariableIndices, uint_fast64_t currentLevel, uint_fast64_t maxLevel) const;
759
785 void toMatrixComponentsRec(DdNode const* dd, std::vector<uint_fast64_t> const& rowGroupOffsets, std::vector<uint_fast64_t>& rowIndications,
786 std::vector<storm::storage::MatrixEntry<uint_fast64_t, ValueType>>& columnsAndValues, Odd const& rowOdd, Odd const& columnOdd,
787 uint_fast64_t currentRowLevel, uint_fast64_t currentColumnLevel, uint_fast64_t maxLevel, uint_fast64_t currentRowOffset,
788 uint_fast64_t currentColumnOffset, std::vector<uint_fast64_t> const& ddRowVariableIndices,
789 std::vector<uint_fast64_t> const& ddColumnVariableIndices, bool writeValues) const;
790
803 static DdNode* fromVectorRec(::DdManager* manager, uint_fast64_t& currentOffset, uint_fast64_t currentLevel, uint_fast64_t maxLevel,
804 std::vector<ValueType> const& values, Odd const& odd, std::vector<uint_fast64_t> const& ddVariableIndices);
805
818 static std::shared_ptr<Odd> createOddRec(DdNode* dd, cudd::Cudd const& manager, uint_fast64_t currentLevel, uint_fast64_t maxLevel,
819 std::vector<uint_fast64_t> const& ddVariableIndices,
820 std::vector<std::unordered_map<DdNode*, std::shared_ptr<Odd>>>& uniqueTableForLevels);
821
822 InternalDdManager<DdType::CUDD> const* ddManager;
823
824 cudd::ADD cuddAdd;
825#endif
826};
827} // namespace dd
828} // 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.
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.
The contract of a DD backend.