Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Add.h
Go to the documentation of this file.
1#ifndef STORM_STORAGE_DD_ADD_H_
2#define STORM_STORAGE_DD_ADD_H_
3
4#include <functional>
5#include <map>
6
10
13
16
17#include "storm-config.h"
18
19namespace storm {
20namespace dd {
21template<DdType LibraryType>
22class Bdd;
23
24template<DdType LibraryType, typename ValueType>
26
27namespace bisimulation {
28template<DdType LibraryType, typename ValueType>
30}
31
32template<DdType LibraryType, typename ValueType = double>
33class Add : public Dd<LibraryType> {
34 public:
35 friend class DdManager<LibraryType>;
36 friend class Bdd<LibraryType>;
37
38 template<DdType LibraryTypePrime, typename ValueTypePrime>
39 friend class Add;
40
41 friend class bisimulation::InternalSignatureRefiner<LibraryType, ValueType>;
42
43 // Instantiate all copy/move constructors/assignments with the default implementation.
44 Add() = default;
45 Add(Add<LibraryType, ValueType> const& other) = default;
46 Add& operator=(Add<LibraryType, ValueType> const& other) = default;
47 Add(Add<LibraryType, ValueType>&& other) = default;
49
59 static Add<LibraryType, ValueType> fromVector(DdManager<LibraryType> const& ddManager, std::vector<ValueType> const& values, Odd const& odd,
60 std::set<storm::expressions::Variable> const& metaVariables);
61
68 bool operator==(Add<LibraryType, ValueType> const& other) const;
69
76 bool operator!=(Add<LibraryType, ValueType> const& other) const;
77
85
93
101
109
117
124
132
140
148
156
164
173
182
191
200
208
216
225
232
239
246
254
262
268 template<typename TargetValueType>
269 typename std::enable_if<std::is_same<TargetValueType, ValueType>::value, Add<LibraryType, TargetValueType>>::type toValueType() const;
270 template<typename TargetValueType>
271 typename std::enable_if<!std::is_same<TargetValueType, ValueType>::value, Add<LibraryType, TargetValueType>>::type toValueType() const;
272
278 Add<LibraryType, ValueType> sumAbstract(std::set<storm::expressions::Variable> const& metaVariables) const;
279
285 Add<LibraryType, ValueType> minAbstract(std::set<storm::expressions::Variable> const& metaVariables) const;
286
294 Bdd<LibraryType> minAbstractRepresentative(std::set<storm::expressions::Variable> const& metaVariables) const;
295
301 Add<LibraryType, ValueType> maxAbstract(std::set<storm::expressions::Variable> const& metaVariables) const;
302
310 Bdd<LibraryType> maxAbstractRepresentative(std::set<storm::expressions::Variable> const& metaVariables) const;
311
321 bool equalModuloPrecision(Add<LibraryType, ValueType> const& other, ValueType const& precision, bool relative = true) const;
322
332 Add<LibraryType, ValueType> renameVariables(std::set<storm::expressions::Variable> const& from, std::set<storm::expressions::Variable> const& to) const;
333
345 Add<LibraryType, ValueType> renameVariablesAbstract(std::set<storm::expressions::Variable> const& from,
346 std::set<storm::expressions::Variable> const& to) const;
347
356 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& metaVariablePairs) const;
357
366 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& metaVariablePairs) const;
367
378 std::set<storm::expressions::Variable> const& summationMetaVariables) const;
379
389 Add<LibraryType, ValueType> multiplyMatrix(Bdd<LibraryType> const& otherMatrix, std::set<storm::expressions::Variable> const& summationMetaVariables) const;
390
398 Bdd<LibraryType> greater(ValueType const& value) const;
399
407 Bdd<LibraryType> greaterOrEqual(ValueType const& value) const;
408
416 Bdd<LibraryType> less(ValueType const& value) const;
417
425 Bdd<LibraryType> lessOrEqual(ValueType const& value) const;
426
434
444
454
460 Bdd<LibraryType> getSupport() const override;
461
467 virtual uint_fast64_t getNonZeroCount() const override;
468
474 virtual uint_fast64_t getLeafCount() const override;
475
481 virtual uint_fast64_t getNodeCount() const override;
482
488 ValueType getMin() const;
489
495 ValueType getMax() const;
496
506 void setValue(storm::expressions::Variable const& metaVariable, int_fast64_t variableValue, ValueType const& targetValue);
507
522 void setValue(storm::expressions::Variable const& metaVariable1, int_fast64_t variableValue1, storm::expressions::Variable const& metaVariable2,
523 int_fast64_t variableValue2, ValueType const& targetValue);
524
533 void setValue(std::map<storm::expressions::Variable, int_fast64_t> const& metaVariableToValueMap = std::map<storm::expressions::Variable, int_fast64_t>(),
534 ValueType const& targetValue = 0);
535
543 ValueType getValue(
544 std::map<storm::expressions::Variable, int_fast64_t> const& metaVariableToValueMap = std::map<storm::expressions::Variable, int_fast64_t>()) const;
545
551 bool isOne() const;
552
558 bool isZero() const;
559
565 bool isConstant() const;
566
567 virtual uint_fast64_t getIndex() const override;
568
569 virtual uint_fast64_t getLevel() const override;
570
576 std::vector<ValueType> toVector() const;
577
585 std::vector<ValueType> toVector(storm::dd::Odd const& rowOdd) const;
586
605 std::vector<ValueType> toVector(storm::dd::Add<LibraryType, ValueType> const& matrix, std::vector<uint_fast64_t> const& rowGroupIndices,
606 std::set<storm::expressions::Variable> const& rowMetaVariables,
607 std::set<storm::expressions::Variable> const& columnMetaVariables,
608 std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd) const;
609
617
628
639 storm::storage::SparseMatrix<ValueType> toMatrix(std::set<storm::expressions::Variable> const& rowMetaVariables,
640 std::set<storm::expressions::Variable> const& columnMetaVariables, storm::dd::Odd const& rowOdd,
641 storm::dd::Odd const& columnOdd) const;
642
654 storm::storage::SparseMatrix<ValueType> toMatrix(std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd,
655 storm::dd::Odd const& columnOdd) const;
656
674 MatrixAndLabeling() = default;
675
677 // Intentionally left empty.
678 }
679
681 // Intentionally left empty.
682 }
683
685 std::vector<std::vector<uint64_t>> labelings;
686 };
687
689 std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables,
690 std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd,
691 std::vector<std::set<storm::expressions::Variable>> const& labelMetaVariables = std::vector<std::set<storm::expressions::Variable>>()) const;
692
706 std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<ValueType>> toMatrixVector(storm::dd::Add<LibraryType, ValueType> const& vector,
707 std::set<storm::expressions::Variable> const& groupMetaVariables,
708 storm::dd::Odd const& rowOdd,
709 storm::dd::Odd const& columnOdd) const;
710 std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<ValueType>> toMatrixVector(
711 std::vector<uint_fast64_t>&& rowGroupSizes, storm::dd::Add<LibraryType, ValueType> const& vector,
712 std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables,
713 std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd) const;
714
728 std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<std::vector<ValueType>>> toMatrixVectors(
729 std::vector<storm::dd::Add<LibraryType, ValueType>> const& vectors, std::set<storm::expressions::Variable> const& groupMetaVariables,
730 storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd) const;
731 std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<std::vector<ValueType>>> toMatrixVectors(
732 std::vector<uint_fast64_t>&& rowGroupSizes, std::vector<storm::dd::Add<LibraryType, ValueType>> const& vectors,
733 std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables,
734 std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd) const;
735
741 void exportToDot(std::string const& filename, bool showVariablesIfPossible = true) const override;
742
743 virtual void exportToText(std::string const& filename) const override;
744
752 AddIterator<LibraryType, ValueType> begin(bool enumerateDontCareMetaVariables = true) const;
753
760
761 template<DdType LibraryTypePrime, typename ValueTypePrime>
762 friend std::ostream& operator<<(std::ostream& out, Add<LibraryTypePrime, ValueTypePrime> const& add);
763
770 Bdd<LibraryType> toBdd() const;
771
777 Odd createOdd() const;
778
783
788
789 private:
797 Add(DdManager<LibraryType> const& ddManager, InternalAdd<LibraryType, ValueType> const& internalAdd,
798 std::set<storm::expressions::Variable> const& containedMetaVariables = std::set<storm::expressions::Variable>());
799
804
820 std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<ValueType>> toMatrixVector(storm::dd::Add<LibraryType, ValueType> const& vector,
821 std::set<storm::expressions::Variable> const& rowMetaVariables,
822 std::set<storm::expressions::Variable> const& columnMetaVariables,
823 std::set<storm::expressions::Variable> const& groupMetaVariables,
824 storm::dd::Odd const& rowOdd,
825 storm::dd::Odd const& columnOdd) const;
826
827 // The internal ADD that depends on the chosen library.
829};
830} // namespace dd
831} // namespace storm
832
833#endif /* STORM_STORAGE_DD_ADD_H_ */
Add< LibraryType, ValueType > restrict(Add< LibraryType, ValueType > const &constraint) const
Computes the restriction of the current ADD with the given constraint.
Definition Add.cpp:441
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:292
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:752
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:126
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:96
friend class Add
Definition Add.h:39
bool isOne() const
Retrieves whether this ADD represents the constant one function.
Definition Add.cpp:527
Add< LibraryType, ValueType > operator+(Add< LibraryType, ValueType > const &other) const
Adds the two ADDs.
Definition Add.cpp:43
Add< LibraryType, ValueType > operator*(Add< LibraryType, ValueType > const &other) const
Multiplies the two ADDs.
Definition Add.cpp:55
ValueType getMax() const
Retrieves the highest function value of any encoding.
Definition Add.cpp:475
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:1139
InternalAdd< LibraryType, ValueType > const & getInternalAdd() const
Retrieves the internal ADD.
Definition Add.cpp:1197
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:141
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:111
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:962
virtual uint_fast64_t getLevel() const override
Retrieves the level of the topmost variable in the DD.
Definition Add.cpp:547
Add< LibraryType, ValueType > operator-() const
Subtracts the ADD from the constant zero function.
Definition Add.cpp:72
bool operator==(Add< LibraryType, ValueType > const &other) const
Retrieves whether the two DDs represent the same function.
Definition Add.cpp:33
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:136
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:168
Add< LibraryType, ValueType > & operator+=(Add< LibraryType, ValueType > const &other)
Adds the given ADD to the current one.
Definition Add.cpp:48
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:151
std::enable_if< std::is_same< TargetValueType, ValueType >::value, Add< LibraryType, TargetValueType > >::type toValueType() const
Replaces the leaves in this MTBDD, converting them to double if possible, and -1.0 else.
Definition Add.cpp:1213
storm::storage::SparseMatrix< ValueType > toMatrix() const
Converts the ADD to a (sparse) matrix.
Definition Add.cpp:634
Add & operator=(Add< LibraryType, ValueType > const &other)=default
ValueType getMin() const
Retrieves the lowest function value of any encoding.
Definition Add.cpp:470
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:116
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:173
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:508
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:216
Add< LibraryType, ValueType > maxAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Max-abstracts from the given meta variables.
Definition Add.cpp:198
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:916
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:1178
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:1149
InternalDdManager< LibraryType > const & getInternalDdManager() const
Retrieves the internal ADD.
Definition Add.cpp:1202
virtual uint_fast64_t getNonZeroCount() const override
Retrieves the number of encodings that are mapped to a non-zero value.
Definition Add.cpp:451
Add< LibraryType, ValueType > sumAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Sum-abstracts from the given meta variables.
Definition Add.cpp:178
virtual uint_fast64_t getNodeCount() const override
Retrieves the number of nodes necessary to represent the DD.
Definition Add.cpp:465
Bdd< LibraryType > getSupport() const override
Retrieves the support of the current ADD.
Definition Add.cpp:446
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:192
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:121
Add< LibraryType, ValueType > minAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Min-abstracts from the given meta variables.
Definition Add.cpp:185
Odd createOdd() const
Creates an ODD based on the current ADD.
Definition Add.cpp:1192
AddIterator< LibraryType, ValueType > end() const
Retrieves an iterator that points past the end of the container.
Definition Add.cpp:1161
virtual uint_fast64_t getIndex() const override
Retrieves the index of the topmost variable in the DD.
Definition Add.cpp:542
bool isZero() const
Retrieves whether this ADD represents the constant zero function.
Definition Add.cpp:532
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:372
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:77
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:131
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:60
Add< LibraryType, ValueType > operator/(Add< LibraryType, ValueType > const &other) const
Divides the current ADD by the given one.
Definition Add.cpp:84
virtual uint_fast64_t getLeafCount() const override
Retrieves the number of leaves of the ADD.
Definition Add.cpp:460
bool isConstant() const
Retrieves whether this ADD represents a constant function.
Definition Add.cpp:537
Bdd< LibraryType > toBdd() const
Converts the ADD to a BDD by mapping all values unequal to zero to 1.
Definition Add.cpp:1187
Add< LibraryType, ValueType > constrain(Add< LibraryType, ValueType > const &constraint) const
Computes the constraint of the current ADD with the given constraint.
Definition Add.cpp:436
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:211
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:101
virtual void exportToText(std::string const &filename) const override
Exports the DD to the given file in the dot format.
Definition Add.cpp:1144
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:480
Bdd< LibraryType > notZero() const
Computes a BDD that represents the function in which all assignments with a function value unequal to...
Definition Add.cpp:431
Add< LibraryType, ValueType > ceil() const
Retrieves the function that ceils all values in the current ADD.
Definition Add.cpp:146
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:89
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:205
bool operator!=(Add< LibraryType, ValueType > const &other) const
Retrieves whether the two DDs represent different functions.
Definition Add.cpp:38
std::vector< ValueType > toVector() const
Converts the ADD to a vector.
Definition Add.cpp:552
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:247
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:337
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:106
A class that holds a possibly non-square matrix in the compressed row storage format.
LabParser.cpp.
Definition cli.cpp:18
Converts the ADD to a row-grouped (sparse) matrix.
Definition Add.h:673
MatrixAndLabeling(storm::storage::SparseMatrix< ValueType > &&matrix)
Definition Add.h:680
std::vector< std::vector< uint64_t > > labelings
Definition Add.h:685
MatrixAndLabeling(storm::storage::SparseMatrix< ValueType > const &matrix)
Definition Add.h:676
storm::storage::SparseMatrix< ValueType > matrix
Definition Add.h:684