Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Add.h
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4
5#include "storm/dd/Dd.h"
6#include "storm/dd/DdType.h"
9#include "storm/dd/Odd.h"
16
17namespace storm {
18namespace dd {
19template<DdType LibraryType>
20class Bdd;
21
22template<DdType LibraryType, typename ValueType>
24
25namespace bisimulation {
26template<DdType LibraryType, typename ValueType>
28}
29
33template<DdType LibraryType, typename ValueType>
34inline constexpr bool SupportsSharpening = BackendTraits<LibraryType>::template supportsValueType<storm::RationalNumber> &&
35 (std::is_same_v<ValueType, double> || std::is_same_v<ValueType, storm::RationalNumber>);
36
37template<DdType LibraryType, typename ValueType = double>
38class Add : public Dd<LibraryType> {
39 public:
40 friend class DdManager<LibraryType>;
41 friend class Bdd<LibraryType>;
42
43 template<DdType LibraryTypePrime, typename ValueTypePrime>
44 friend class Add;
45
46 friend class bisimulation::InternalSignatureRefiner<LibraryType, ValueType>;
47
48 // Instantiate all copy/move constructors/assignments with the default implementation.
49 Add() = default;
50 Add(Add<LibraryType, ValueType> const& other) = default;
51 Add& operator=(Add<LibraryType, ValueType> const& other) = default;
52 Add(Add<LibraryType, ValueType>&& other) = default;
54
64 static Add<LibraryType, ValueType> fromVector(DdManager<LibraryType> const& ddManager, std::vector<ValueType> const& values, Odd const& odd,
65 std::set<storm::expressions::Variable> const& metaVariables);
66
73 bool operator==(Add<LibraryType, ValueType> const& other) const;
74
81 bool operator!=(Add<LibraryType, ValueType> const& other) const;
82
90
98
106
114
122
129
137
145
153
161
169
178
187
196
205
213
221
230
237
244
253
261
269
275 template<typename TargetValueType>
276 typename std::enable_if_t<std::is_same_v<TargetValueType, ValueType>, Add<LibraryType, TargetValueType>> toValueType() const;
277 template<typename TargetValueType>
278 typename std::enable_if_t<!std::is_same_v<TargetValueType, ValueType>, Add<LibraryType, TargetValueType>> toValueType() const;
279
285 Add<LibraryType, ValueType> sumAbstract(std::set<storm::expressions::Variable> const& metaVariables) const;
286
292 Add<LibraryType, ValueType> minAbstract(std::set<storm::expressions::Variable> const& metaVariables) const;
293
301 Bdd<LibraryType> minAbstractRepresentative(std::set<storm::expressions::Variable> const& metaVariables) const;
302
308 Add<LibraryType, ValueType> maxAbstract(std::set<storm::expressions::Variable> const& metaVariables) const;
309
317 Bdd<LibraryType> maxAbstractRepresentative(std::set<storm::expressions::Variable> const& metaVariables) const;
318
328 bool equalModuloPrecision(Add<LibraryType, ValueType> const& other, ValueType const& precision, bool relative = true) const;
329
339 Add<LibraryType, ValueType> renameVariables(std::set<storm::expressions::Variable> const& from, std::set<storm::expressions::Variable> const& to) const;
340
352 Add<LibraryType, ValueType> renameVariablesAbstract(std::set<storm::expressions::Variable> const& from,
353 std::set<storm::expressions::Variable> const& to) const;
354
363 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& metaVariablePairs) const;
364
373 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& metaVariablePairs) const;
374
384 std::set<storm::expressions::Variable> const& summationMetaVariables) const;
385
394 Add<LibraryType, ValueType> multiplyMatrix(Bdd<LibraryType> const& otherMatrix, std::set<storm::expressions::Variable> const& summationMetaVariables) const;
395
403 Bdd<LibraryType> greater(ValueType const& value) const;
404
412 Bdd<LibraryType> greaterOrEqual(ValueType const& value) const;
413
421 Bdd<LibraryType> less(ValueType const& value) const;
422
430 Bdd<LibraryType> lessOrEqual(ValueType const& value) const;
431
439
449
459
465 Bdd<LibraryType> getSupport() const override;
466
472 virtual uint_fast64_t getNonZeroCount() const override;
473
479 virtual uint_fast64_t getLeafCount() const override;
480
486 virtual uint_fast64_t getNodeCount() const override;
487
493 ValueType getMin() const;
494
500 ValueType getMax() const;
501
511 void setValue(storm::expressions::Variable const& metaVariable, int_fast64_t variableValue, ValueType const& targetValue);
512
527 void setValue(storm::expressions::Variable const& metaVariable1, int_fast64_t variableValue1, storm::expressions::Variable const& metaVariable2,
528 int_fast64_t variableValue2, ValueType const& targetValue);
529
538 void setValue(std::map<storm::expressions::Variable, int_fast64_t> const& metaVariableToValueMap = std::map<storm::expressions::Variable, int_fast64_t>(),
539 ValueType const& targetValue = 0);
540
548 ValueType getValue(
549 std::map<storm::expressions::Variable, int_fast64_t> const& metaVariableToValueMap = std::map<storm::expressions::Variable, int_fast64_t>()) const;
550
556 bool isOne() const;
557
563 bool isZero() const;
564
570 bool isConstant() const;
571
572 virtual uint_fast64_t getIndex() const override;
573
574 virtual uint_fast64_t getLevel() const override;
575
581 std::vector<ValueType> toVector() const;
582
590 std::vector<ValueType> toVector(storm::dd::Odd const& rowOdd) const;
591
610 std::vector<ValueType> toVector(storm::dd::Add<LibraryType, ValueType> const& matrix, std::vector<uint_fast64_t> const& rowGroupIndices,
611 std::set<storm::expressions::Variable> const& rowMetaVariables,
612 std::set<storm::expressions::Variable> const& columnMetaVariables,
613 std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd) const;
614
622
633
644 storm::storage::SparseMatrix<ValueType> toMatrix(std::set<storm::expressions::Variable> const& rowMetaVariables,
645 std::set<storm::expressions::Variable> const& columnMetaVariables, storm::dd::Odd const& rowOdd,
646 storm::dd::Odd const& columnOdd) const;
647
659 storm::storage::SparseMatrix<ValueType> toMatrix(std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd,
660 storm::dd::Odd const& columnOdd) const;
661
679 MatrixAndLabeling() = default;
680
682 // Intentionally left empty.
683 }
684
686 // Intentionally left empty.
687 }
688
690 std::vector<std::vector<uint64_t>> labelings;
691 };
692
694 std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables,
695 std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd,
696 std::vector<std::set<storm::expressions::Variable>> const& labelMetaVariables = std::vector<std::set<storm::expressions::Variable>>()) const;
697
711 std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<ValueType>> toMatrixVector(storm::dd::Add<LibraryType, ValueType> const& vector,
712 std::set<storm::expressions::Variable> const& groupMetaVariables,
713 storm::dd::Odd const& rowOdd,
714 storm::dd::Odd const& columnOdd) const;
715 std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<ValueType>> toMatrixVector(
716 std::vector<uint_fast64_t>&& rowGroupSizes, storm::dd::Add<LibraryType, ValueType> const& vector,
717 std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables,
718 std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd) const;
719
733 std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<std::vector<ValueType>>> toMatrixVectors(
734 std::vector<storm::dd::Add<LibraryType, ValueType>> const& vectors, std::set<storm::expressions::Variable> const& groupMetaVariables,
735 storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd) const;
736 std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<std::vector<ValueType>>> toMatrixVectors(
737 std::vector<uint_fast64_t>&& rowGroupSizes, std::vector<storm::dd::Add<LibraryType, ValueType>> const& vectors,
738 std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables,
739 std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd) const;
740
746 void exportToDot(std::string const& filename, bool showVariablesIfPossible = true) const override;
747
748 virtual void exportToText(std::string const& filename) const override;
749
757 AddIterator<LibraryType, ValueType> begin(bool enumerateDontCareMetaVariables = true) const;
758
765
766 template<DdType LibraryTypePrime, typename ValueTypePrime>
767 friend std::ostream& operator<<(std::ostream& out, Add<LibraryTypePrime, ValueTypePrime> const& add);
768
775 Bdd<LibraryType> toBdd() const;
776
782 Odd createOdd() const;
783
788
793
794 private:
802 Add(DdManager<LibraryType> const& ddManager, InternalAdd<LibraryType, ValueType> const& internalAdd,
803 std::set<storm::expressions::Variable> const& containedMetaVariables = std::set<storm::expressions::Variable>());
804
809
825 std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<ValueType>> toMatrixVector(storm::dd::Add<LibraryType, ValueType> const& vector,
826 std::set<storm::expressions::Variable> const& rowMetaVariables,
827 std::set<storm::expressions::Variable> const& columnMetaVariables,
828 std::set<storm::expressions::Variable> const& groupMetaVariables,
829 storm::dd::Odd const& rowOdd,
830 storm::dd::Odd const& columnOdd) const;
831
832 // The internal ADD that depends on the chosen library.
834};
835} // namespace dd
836} // namespace storm
Add< LibraryType, ValueType > restrict(Add< LibraryType, ValueType > const &constraint) const
Computes the restriction of the current ADD with the given constraint.
Definition Add.cpp:425
Add< LibraryType, ValueType > swapVariables(std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &metaVariablePairs) const
Swaps the given pairs of meta variables in the ADD.
Definition Add.cpp:276
MatrixAndLabeling toLabeledMatrix(std::set< storm::expressions::Variable > const &rowMetaVariables, std::set< storm::expressions::Variable > const &columnMetaVariables, std::set< storm::expressions::Variable > const &groupMetaVariables, storm::dd::Odd const &rowOdd, storm::dd::Odd const &columnOdd, std::vector< std::set< storm::expressions::Variable > > const &labelMetaVariables=std::vector< std::set< storm::expressions::Variable > >()) const
Definition Add.cpp:736
Add< LibraryType, ValueType > pow(Add< LibraryType, ValueType > const &other) const
Retrieves the function that represents the current ADD to the power of the given ADD.
Definition Add.cpp:119
Bdd< LibraryType > equals(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one that have identical function values.
Definition Add.cpp:89
friend class Add
Definition Add.h:44
bool isOne() const
Retrieves whether this ADD represents the constant one function.
Definition Add.cpp:511
Add< LibraryType, ValueType > operator+(Add< LibraryType, ValueType > const &other) const
Adds the two ADDs.
Definition Add.cpp:36
Add< LibraryType, ValueType > operator*(Add< LibraryType, ValueType > const &other) const
Multiplies the two ADDs.
Definition Add.cpp:48
ValueType getMax() const
Retrieves the highest function value of any encoding.
Definition Add.cpp:459
void exportToDot(std::string const &filename, bool showVariablesIfPossible=true) const override
Exports the DD to the given file in the dot format.
Definition Add.cpp:1123
InternalAdd< LibraryType, ValueType > const & getInternalAdd() const
Retrieves the internal ADD.
Definition Add.cpp:1181
friend std::ostream & operator<<(std::ostream &out, Add< LibraryTypePrime, ValueTypePrime > const &add)
Add< LibraryType, ValueType > floor() const
Retrieves the function that floors all values in the current ADD.
Definition Add.cpp:134
Add & operator=(Add< LibraryType, ValueType > &&other)=default
Add(Add< LibraryType, ValueType > &&other)=default
Bdd< LibraryType > lessOrEqual(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are les...
Definition Add.cpp:104
std::pair< storm::storage::SparseMatrix< ValueType >, std::vector< std::vector< ValueType > > > toMatrixVectors(std::vector< storm::dd::Add< LibraryType, ValueType > > const &vectors, std::set< storm::expressions::Variable > const &groupMetaVariables, storm::dd::Odd const &rowOdd, storm::dd::Odd const &columnOdd) const
Converts the ADD to a row-grouped (sparse) matrix and the given vectors to row-grouped vectors.
Definition Add.cpp:946
virtual uint_fast64_t getLevel() const override
Retrieves the level of the topmost variable in the DD.
Definition Add.cpp:531
Add< LibraryType, ValueType > operator-() const
Subtracts the ADD from the constant zero function.
Definition Add.cpp:65
bool operator==(Add< LibraryType, ValueType > const &other) const
Retrieves whether the two DDs represent the same function.
Definition Add.cpp:26
Add< LibraryType, ValueType > logxy(Add< LibraryType, ValueType > const &other) const
Retrieves the function that represents the logarithm of the current ADD to the bases given by the sec...
Definition Add.cpp:129
Add< LibraryType, ValueType > minimum(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to the minimum of the function values of the two ADD...
Definition Add.cpp:152
Add< LibraryType, ValueType > & operator+=(Add< LibraryType, ValueType > const &other)
Adds the given ADD to the current one.
Definition Add.cpp:41
Add(Add< LibraryType, ValueType > const &other)=default
storm::storage::SparseMatrix< ValueType > toMatrix() const
Converts the ADD to a (sparse) matrix.
Definition Add.cpp:618
Add & operator=(Add< LibraryType, ValueType > const &other)=default
ValueType getMin() const
Retrieves the lowest function value of any encoding.
Definition Add.cpp:454
Bdd< LibraryType > greater(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are gre...
Definition Add.cpp:109
Add< LibraryType, ValueType > maximum(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to the maximum of the function values of the two ADD...
Definition Add.cpp:157
ValueType getValue(std::map< storm::expressions::Variable, int_fast64_t > const &metaVariableToValueMap=std::map< storm::expressions::Variable, int_fast64_t >()) const
Retrieves the value of the function when all meta variables are assigned the values of the given mapp...
Definition Add.cpp:492
Add< LibraryType, storm::RationalNumber > sharpenKwekMehlhorn(uint64_t precision) const
Retrieves the function that sharpens all values in the current ADD with the Kwek-Mehlhorn algorithm.
Definition Add.cpp:144
Add()=default
Add< LibraryType, ValueType > renameVariables(std::set< storm::expressions::Variable > const &from, std::set< storm::expressions::Variable > const &to) const
Renames the given meta variables in the ADD.
Definition Add.cpp:200
Add< LibraryType, ValueType > maxAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Max-abstracts from the given meta variables.
Definition Add.cpp:182
std::pair< storm::storage::SparseMatrix< ValueType >, std::vector< ValueType > > toMatrixVector(storm::dd::Add< LibraryType, ValueType > const &vector, std::set< storm::expressions::Variable > const &groupMetaVariables, storm::dd::Odd const &rowOdd, storm::dd::Odd const &columnOdd) const
Converts the ADD to a row-grouped (sparse) matrix and the given vector to a row-grouped vector.
Definition Add.cpp:900
static Add< LibraryType, ValueType > fromVector(DdManager< LibraryType > const &ddManager, std::vector< ValueType > const &values, Odd const &odd, std::set< storm::expressions::Variable > const &metaVariables)
Builds an ADD representing the given vector.
Definition Add.cpp:1162
AddIterator< LibraryType, ValueType > begin(bool enumerateDontCareMetaVariables=true) const
Retrieves an iterator that points to the first meta variable assignment with a non-zero function valu...
Definition Add.cpp:1133
InternalDdManager< LibraryType > const & getInternalDdManager() const
Retrieves the internal ADD.
Definition Add.cpp:1186
virtual uint_fast64_t getNonZeroCount() const override
Retrieves the number of encodings that are mapped to a non-zero value.
Definition Add.cpp:435
Add< LibraryType, ValueType > sumAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Sum-abstracts from the given meta variables.
Definition Add.cpp:162
std::enable_if_t< std::is_same_v< TargetValueType, ValueType >, Add< LibraryType, TargetValueType > > toValueType() const
Replaces the leaves in this MTBDD, converting them to double if possible, and -1.0 else.
Definition Add.cpp:1197
virtual uint_fast64_t getNodeCount() const override
Retrieves the number of nodes necessary to represent the DD.
Definition Add.cpp:449
Bdd< LibraryType > getSupport() const override
Retrieves the support of the current ADD.
Definition Add.cpp:430
Bdd< LibraryType > minAbstractRepresentative(std::set< storm::expressions::Variable > const &metaVariables) const
Similar to minAbstract, but does not abstract from the variables but rather picks a valuation of each...
Definition Add.cpp:176
Bdd< LibraryType > greaterOrEqual(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are gre...
Definition Add.cpp:114
Add< LibraryType, ValueType > minAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Min-abstracts from the given meta variables.
Definition Add.cpp:169
Odd createOdd() const
Creates an ODD based on the current ADD.
Definition Add.cpp:1176
AddIterator< LibraryType, ValueType > end() const
Retrieves an iterator that points past the end of the container.
Definition Add.cpp:1145
virtual uint_fast64_t getIndex() const override
Retrieves the index of the topmost variable in the DD.
Definition Add.cpp:526
bool isZero() const
Retrieves whether this ADD represents the constant zero function.
Definition Add.cpp:516
Add< LibraryType, ValueType > multiplyMatrix(Add< LibraryType, ValueType > const &otherMatrix, std::set< storm::expressions::Variable > const &summationMetaVariables) const
Multiplies the current ADD (representing a matrix) with the given matrix by summing over the given me...
Definition Add.cpp:356
Add< LibraryType, ValueType > & operator-=(Add< LibraryType, ValueType > const &other)
Subtracts the given ADD from the current one and assigns the result to the current ADD.
Definition Add.cpp:70
Add< LibraryType, ValueType > mod(Add< LibraryType, ValueType > const &other) const
Retrieves the function that represents the current ADD modulo the given ADD.
Definition Add.cpp:124
Add< LibraryType, ValueType > & operator*=(Add< LibraryType, ValueType > const &other)
Multiplies the given ADD with the current one and assigns the result to the current ADD.
Definition Add.cpp:53
Add< LibraryType, ValueType > operator/(Add< LibraryType, ValueType > const &other) const
Divides the current ADD by the given one.
Definition Add.cpp:77
virtual uint_fast64_t getLeafCount() const override
Retrieves the number of leaves of the ADD.
Definition Add.cpp:444
bool isConstant() const
Retrieves whether this ADD represents a constant function.
Definition Add.cpp:521
Bdd< LibraryType > toBdd() const
Converts the ADD to a BDD by mapping all values unequal to zero to 1.
Definition Add.cpp:1171
Add< LibraryType, ValueType > constrain(Add< LibraryType, ValueType > const &constraint) const
Computes the constraint of the current ADD with the given constraint.
Definition Add.cpp:420
bool equalModuloPrecision(Add< LibraryType, 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.
Definition Add.cpp:195
Bdd< LibraryType > notEquals(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one that have distinct function values.
Definition Add.cpp:94
virtual void exportToText(std::string const &filename) const override
Exports the DD to the given file in the dot format.
Definition Add.cpp:1128
void setValue(storm::expressions::Variable const &metaVariable, int_fast64_t variableValue, ValueType const &targetValue)
Sets the function values of all encodings that have the given value of the meta variable to the given...
Definition Add.cpp:464
Bdd< LibraryType > notZero() const
Computes a BDD that represents the function in which all assignments with a function value unequal to...
Definition Add.cpp:415
Add< LibraryType, ValueType > ceil() const
Retrieves the function that ceils all values in the current ADD.
Definition Add.cpp:139
Add< LibraryType, ValueType > & operator/=(Add< LibraryType, ValueType > const &other)
Divides the current ADD by the given one and assigns the result to the current ADD.
Definition Add.cpp:82
Bdd< LibraryType > maxAbstractRepresentative(std::set< storm::expressions::Variable > const &metaVariables) const
Similar to maxAbstract, but does not abstract from the variables but rather picks a valuation of each...
Definition Add.cpp:189
bool operator!=(Add< LibraryType, ValueType > const &other) const
Retrieves whether the two DDs represent different functions.
Definition Add.cpp:31
std::vector< ValueType > toVector() const
Converts the ADD to a vector.
Definition Add.cpp:536
Add< LibraryType, ValueType > renameVariablesAbstract(std::set< storm::expressions::Variable > const &from, std::set< storm::expressions::Variable > const &to) const
Renames the given meta variables in the ADD.
Definition Add.cpp:231
Add< LibraryType, ValueType > permuteVariables(std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &metaVariablePairs) const
Permutes the given pairs of meta variables in the ADD.
Definition Add.cpp:321
Bdd< LibraryType > less(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are les...
Definition Add.cpp:99
Dd()=default
A class that holds a possibly non-square matrix in the compressed row storage format.
constexpr bool SupportsSharpening
Whether the Kwek-Mehlhorn sharpening is available: the backend has to support rational numbers and th...
Definition Add.h:34
The contract of a DD backend.
Converts the ADD to a row-grouped (sparse) matrix.
Definition Add.h:678
MatrixAndLabeling(storm::storage::SparseMatrix< ValueType > &&matrix)
Definition Add.h:685
std::vector< std::vector< uint64_t > > labelings
Definition Add.h:690
MatrixAndLabeling(storm::storage::SparseMatrix< ValueType > const &matrix)
Definition Add.h:681
storm::storage::SparseMatrix< ValueType > matrix
Definition Add.h:689