Storm 1.11.1.1
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
15
16namespace storm {
17namespace dd {
18template<DdType LibraryType>
19class Bdd;
20
21template<DdType LibraryType, typename ValueType>
23
24namespace bisimulation {
25template<DdType LibraryType, typename ValueType>
27}
28
29template<DdType LibraryType, typename ValueType = double>
30class Add : public Dd<LibraryType> {
31 public:
32 friend class DdManager<LibraryType>;
33 friend class Bdd<LibraryType>;
34
35 template<DdType LibraryTypePrime, typename ValueTypePrime>
36 friend class Add;
37
38 friend class bisimulation::InternalSignatureRefiner<LibraryType, ValueType>;
39
40 // Instantiate all copy/move constructors/assignments with the default implementation.
41 Add() = default;
42 Add(Add<LibraryType, ValueType> const& other) = default;
43 Add& operator=(Add<LibraryType, ValueType> const& other) = default;
44 Add(Add<LibraryType, ValueType>&& other) = default;
46
56 static Add<LibraryType, ValueType> fromVector(DdManager<LibraryType> const& ddManager, std::vector<ValueType> const& values, Odd const& odd,
57 std::set<storm::expressions::Variable> const& metaVariables);
58
65 bool operator==(Add<LibraryType, ValueType> const& other) const;
66
73 bool operator!=(Add<LibraryType, ValueType> const& other) const;
74
82
90
98
106
114
121
129
137
145
153
161
170
179
188
197
205
213
222
229
236
243
251
259
265 template<typename TargetValueType>
266 typename std::enable_if_t<std::is_same_v<TargetValueType, ValueType>, Add<LibraryType, TargetValueType>> toValueType() const;
267 template<typename TargetValueType>
268 typename std::enable_if_t<!std::is_same_v<TargetValueType, ValueType>, Add<LibraryType, TargetValueType>> toValueType() const;
269
275 Add<LibraryType, ValueType> sumAbstract(std::set<storm::expressions::Variable> const& metaVariables) const;
276
282 Add<LibraryType, ValueType> minAbstract(std::set<storm::expressions::Variable> const& metaVariables) const;
283
291 Bdd<LibraryType> minAbstractRepresentative(std::set<storm::expressions::Variable> const& metaVariables) const;
292
298 Add<LibraryType, ValueType> maxAbstract(std::set<storm::expressions::Variable> const& metaVariables) const;
299
307 Bdd<LibraryType> maxAbstractRepresentative(std::set<storm::expressions::Variable> const& metaVariables) const;
308
318 bool equalModuloPrecision(Add<LibraryType, ValueType> const& other, ValueType const& precision, bool relative = true) const;
319
329 Add<LibraryType, ValueType> renameVariables(std::set<storm::expressions::Variable> const& from, std::set<storm::expressions::Variable> const& to) const;
330
342 Add<LibraryType, ValueType> renameVariablesAbstract(std::set<storm::expressions::Variable> const& from,
343 std::set<storm::expressions::Variable> const& to) const;
344
353 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& metaVariablePairs) const;
354
363 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& metaVariablePairs) const;
364
374 std::set<storm::expressions::Variable> const& summationMetaVariables) const;
375
384 Add<LibraryType, ValueType> multiplyMatrix(Bdd<LibraryType> const& otherMatrix, std::set<storm::expressions::Variable> const& summationMetaVariables) const;
385
393 Bdd<LibraryType> greater(ValueType const& value) const;
394
402 Bdd<LibraryType> greaterOrEqual(ValueType const& value) const;
403
411 Bdd<LibraryType> less(ValueType const& value) const;
412
420 Bdd<LibraryType> lessOrEqual(ValueType const& value) const;
421
429
439
449
455 Bdd<LibraryType> getSupport() const override;
456
462 virtual uint_fast64_t getNonZeroCount() const override;
463
469 virtual uint_fast64_t getLeafCount() const override;
470
476 virtual uint_fast64_t getNodeCount() const override;
477
483 ValueType getMin() const;
484
490 ValueType getMax() const;
491
501 void setValue(storm::expressions::Variable const& metaVariable, int_fast64_t variableValue, ValueType const& targetValue);
502
517 void setValue(storm::expressions::Variable const& metaVariable1, int_fast64_t variableValue1, storm::expressions::Variable const& metaVariable2,
518 int_fast64_t variableValue2, ValueType const& targetValue);
519
528 void setValue(std::map<storm::expressions::Variable, int_fast64_t> const& metaVariableToValueMap = std::map<storm::expressions::Variable, int_fast64_t>(),
529 ValueType const& targetValue = 0);
530
538 ValueType getValue(
539 std::map<storm::expressions::Variable, int_fast64_t> const& metaVariableToValueMap = std::map<storm::expressions::Variable, int_fast64_t>()) const;
540
546 bool isOne() const;
547
553 bool isZero() const;
554
560 bool isConstant() const;
561
562 virtual uint_fast64_t getIndex() const override;
563
564 virtual uint_fast64_t getLevel() const override;
565
571 std::vector<ValueType> toVector() const;
572
580 std::vector<ValueType> toVector(storm::dd::Odd const& rowOdd) const;
581
600 std::vector<ValueType> toVector(storm::dd::Add<LibraryType, ValueType> const& matrix, std::vector<uint_fast64_t> const& rowGroupIndices,
601 std::set<storm::expressions::Variable> const& rowMetaVariables,
602 std::set<storm::expressions::Variable> const& columnMetaVariables,
603 std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd) const;
604
612
623
634 storm::storage::SparseMatrix<ValueType> toMatrix(std::set<storm::expressions::Variable> const& rowMetaVariables,
635 std::set<storm::expressions::Variable> const& columnMetaVariables, storm::dd::Odd const& rowOdd,
636 storm::dd::Odd const& columnOdd) const;
637
649 storm::storage::SparseMatrix<ValueType> toMatrix(std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd,
650 storm::dd::Odd const& columnOdd) const;
651
669 MatrixAndLabeling() = default;
670
672 // Intentionally left empty.
673 }
674
676 // Intentionally left empty.
677 }
678
680 std::vector<std::vector<uint64_t>> labelings;
681 };
682
684 std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables,
685 std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd,
686 std::vector<std::set<storm::expressions::Variable>> const& labelMetaVariables = std::vector<std::set<storm::expressions::Variable>>()) const;
687
701 std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<ValueType>> toMatrixVector(storm::dd::Add<LibraryType, ValueType> const& vector,
702 std::set<storm::expressions::Variable> const& groupMetaVariables,
703 storm::dd::Odd const& rowOdd,
704 storm::dd::Odd const& columnOdd) const;
705 std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<ValueType>> toMatrixVector(
706 std::vector<uint_fast64_t>&& rowGroupSizes, storm::dd::Add<LibraryType, ValueType> const& vector,
707 std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables,
708 std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd) const;
709
723 std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<std::vector<ValueType>>> toMatrixVectors(
724 std::vector<storm::dd::Add<LibraryType, ValueType>> const& vectors, std::set<storm::expressions::Variable> const& groupMetaVariables,
725 storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd) const;
726 std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<std::vector<ValueType>>> toMatrixVectors(
727 std::vector<uint_fast64_t>&& rowGroupSizes, std::vector<storm::dd::Add<LibraryType, ValueType>> const& vectors,
728 std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables,
729 std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd) const;
730
736 void exportToDot(std::string const& filename, bool showVariablesIfPossible = true) const override;
737
738 virtual void exportToText(std::string const& filename) const override;
739
747 AddIterator<LibraryType, ValueType> begin(bool enumerateDontCareMetaVariables = true) const;
748
755
756 template<DdType LibraryTypePrime, typename ValueTypePrime>
757 friend std::ostream& operator<<(std::ostream& out, Add<LibraryTypePrime, ValueTypePrime> const& add);
758
765 Bdd<LibraryType> toBdd() const;
766
772 Odd createOdd() const;
773
778
783
784 private:
792 Add(DdManager<LibraryType> const& ddManager, InternalAdd<LibraryType, ValueType> const& internalAdd,
793 std::set<storm::expressions::Variable> const& containedMetaVariables = std::set<storm::expressions::Variable>());
794
799
815 std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<ValueType>> toMatrixVector(storm::dd::Add<LibraryType, ValueType> const& vector,
816 std::set<storm::expressions::Variable> const& rowMetaVariables,
817 std::set<storm::expressions::Variable> const& columnMetaVariables,
818 std::set<storm::expressions::Variable> const& groupMetaVariables,
819 storm::dd::Odd const& rowOdd,
820 storm::dd::Odd const& columnOdd) const;
821
822 // The internal ADD that depends on the chosen library.
824};
825} // namespace dd
826} // 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:437
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:288
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:748
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:122
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:92
friend class Add
Definition Add.h:36
bool isOne() const
Retrieves whether this ADD represents the constant one function.
Definition Add.cpp:523
Add< LibraryType, ValueType > operator+(Add< LibraryType, ValueType > const &other) const
Adds the two ADDs.
Definition Add.cpp:39
Add< LibraryType, ValueType > operator*(Add< LibraryType, ValueType > const &other) const
Multiplies the two ADDs.
Definition Add.cpp:51
ValueType getMax() const
Retrieves the highest function value of any encoding.
Definition Add.cpp:471
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:1135
InternalAdd< LibraryType, ValueType > const & getInternalAdd() const
Retrieves the internal ADD.
Definition Add.cpp:1193
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:137
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:107
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:958
virtual uint_fast64_t getLevel() const override
Retrieves the level of the topmost variable in the DD.
Definition Add.cpp:543
Add< LibraryType, ValueType > operator-() const
Subtracts the ADD from the constant zero function.
Definition Add.cpp:68
bool operator==(Add< LibraryType, ValueType > const &other) const
Retrieves whether the two DDs represent the same function.
Definition Add.cpp:29
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:132
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:164
Add< LibraryType, ValueType > & operator+=(Add< LibraryType, ValueType > const &other)
Adds the given ADD to the current one.
Definition Add.cpp:44
Add(Add< LibraryType, ValueType > const &other)=default
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:147
storm::storage::SparseMatrix< ValueType > toMatrix() const
Converts the ADD to a (sparse) matrix.
Definition Add.cpp:630
Add & operator=(Add< LibraryType, ValueType > const &other)=default
ValueType getMin() const
Retrieves the lowest function value of any encoding.
Definition Add.cpp:466
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:112
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:169
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:504
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:212
Add< LibraryType, ValueType > maxAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Max-abstracts from the given meta variables.
Definition Add.cpp:194
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:912
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:1174
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:1145
InternalDdManager< LibraryType > const & getInternalDdManager() const
Retrieves the internal ADD.
Definition Add.cpp:1198
virtual uint_fast64_t getNonZeroCount() const override
Retrieves the number of encodings that are mapped to a non-zero value.
Definition Add.cpp:447
Add< LibraryType, ValueType > sumAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Sum-abstracts from the given meta variables.
Definition Add.cpp:174
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:1209
virtual uint_fast64_t getNodeCount() const override
Retrieves the number of nodes necessary to represent the DD.
Definition Add.cpp:461
Bdd< LibraryType > getSupport() const override
Retrieves the support of the current ADD.
Definition Add.cpp:442
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:188
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:117
Add< LibraryType, ValueType > minAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Min-abstracts from the given meta variables.
Definition Add.cpp:181
Odd createOdd() const
Creates an ODD based on the current ADD.
Definition Add.cpp:1188
AddIterator< LibraryType, ValueType > end() const
Retrieves an iterator that points past the end of the container.
Definition Add.cpp:1157
virtual uint_fast64_t getIndex() const override
Retrieves the index of the topmost variable in the DD.
Definition Add.cpp:538
bool isZero() const
Retrieves whether this ADD represents the constant zero function.
Definition Add.cpp:528
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:368
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:73
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:127
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:56
Add< LibraryType, ValueType > operator/(Add< LibraryType, ValueType > const &other) const
Divides the current ADD by the given one.
Definition Add.cpp:80
virtual uint_fast64_t getLeafCount() const override
Retrieves the number of leaves of the ADD.
Definition Add.cpp:456
bool isConstant() const
Retrieves whether this ADD represents a constant function.
Definition Add.cpp:533
Bdd< LibraryType > toBdd() const
Converts the ADD to a BDD by mapping all values unequal to zero to 1.
Definition Add.cpp:1183
Add< LibraryType, ValueType > constrain(Add< LibraryType, ValueType > const &constraint) const
Computes the constraint of the current ADD with the given constraint.
Definition Add.cpp:432
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:207
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:97
virtual void exportToText(std::string const &filename) const override
Exports the DD to the given file in the dot format.
Definition Add.cpp:1140
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:476
Bdd< LibraryType > notZero() const
Computes a BDD that represents the function in which all assignments with a function value unequal to...
Definition Add.cpp:427
Add< LibraryType, ValueType > ceil() const
Retrieves the function that ceils all values in the current ADD.
Definition Add.cpp:142
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:85
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:201
bool operator!=(Add< LibraryType, ValueType > const &other) const
Retrieves whether the two DDs represent different functions.
Definition Add.cpp:34
std::vector< ValueType > toVector() const
Converts the ADD to a vector.
Definition Add.cpp:548
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:243
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:333
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:102
A class that holds a possibly non-square matrix in the compressed row storage format.
Converts the ADD to a row-grouped (sparse) matrix.
Definition Add.h:668
MatrixAndLabeling(storm::storage::SparseMatrix< ValueType > &&matrix)
Definition Add.h:675
std::vector< std::vector< uint64_t > > labelings
Definition Add.h:680
MatrixAndLabeling(storm::storage::SparseMatrix< ValueType > const &matrix)
Definition Add.h:671
storm::storage::SparseMatrix< ValueType > matrix
Definition Add.h:679