Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
ParameterLifter.h
Go to the documentation of this file.
1#pragma once
2
3#include <boost/functional/hash.hpp>
4#include <memory>
5#include <set>
6#include <unordered_map>
7#include <vector>
8
12#include "storm/adapters/RationalFunctionAdapter.h" // TODO: use forward header
16
17namespace storm {
18
19namespace analysis {
20class Order;
21} // namespace analysis
22
23namespace storage {
24template<typename ParametricType>
25class ParameterRegion;
26} // namespace storage
27
28namespace transformer {
29
40template<typename ParametricType, typename ConstantType>
42 public:
46
54 ParameterLifter(storm::storage::SparseMatrix<ParametricType> const& pMatrix, std::vector<ParametricType> const& pVector,
55 storm::storage::BitVector const& selectedRows, storm::storage::BitVector const& selectedColumns, bool generateRowLabels = false,
56 bool useMonotonicity = false);
57
59
60 // Returns the resulting matrix. Should only be called AFTER specifying a region
62
63 // Returns the resulting vector. Should only be called AFTER specifying a region
64 std::vector<ConstantType> const& getVector() const;
65
66 std::vector<std::set<VariableType>> const& getOccurringVariablesAtState() const;
67
68 std::map<VariableType, std::set<uint_fast64_t>> const& getOccuringStatesAtVariable() const;
69
70 uint_fast64_t getRowGroupIndex(uint_fast64_t originalState) const;
71 uint_fast64_t getOriginalStateNumber(uint_fast64_t newState) const;
72 uint_fast64_t getRowGroupSize(uint_fast64_t originalState) const;
73 uint_fast64_t getRowGroupCount() const;
74
75 /*
76 * During initialization, the actual regions are not known. Hence, we consider abstract valuations,
77 * where it is only known whether a parameter will be set to either the lower/upper bound of the region or whether this is unspecified
78 */
80 public:
81 AbstractValuation() = default;
82 AbstractValuation(AbstractValuation const& other) = default;
83 bool operator==(AbstractValuation const& other) const;
84
85 void addParameterLower(VariableType const& var);
86 void addParameterUpper(VariableType const& var);
88
89 std::size_t getHashValue() const;
90 AbstractValuation getSubValuation(std::set<VariableType> const& pars) const;
91 std::set<VariableType> const& getLowerParameters() const;
92 std::set<VariableType> const& getUpperParameters() const;
93 std::set<VariableType> const& getUnspecifiedParameters() const;
94
99 std::vector<storm::utility::parametric::Valuation<ParametricType>> getConcreteValuations(
101
102 private:
103 std::set<VariableType> lowerPars, upperPars, unspecifiedPars;
104 };
105
106 // Returns for each row the abstract valuation for this row
107 // Note: the returned vector might be empty if row label generaion was disabled initially
108 std::vector<AbstractValuation> const& getRowLabels() const;
109
110 private:
111 /*
112 * We minimize the number of function evaluations by only calling evaluate() once for each unique pair of function and valuation.
113 * The result of each evaluation is then written to all positions in the matrix (and the vector) where the corresponding (function,valuation) occurred.
114 */
115
121 class FunctionValuationCollector {
122 public:
123 FunctionValuationCollector() = default;
124
129 ConstantType& add(ParametricType const& function, AbstractValuation const& valuation);
130
131 void evaluateCollectedFunctions(storm::storage::ParameterRegion<ParametricType> const& region,
132 storm::solver::OptimizationDirection const& dirForUnspecifiedParameters);
133
134 private:
135 // Stores a function and a valuation. The valuation is stored as an index of the collectedValuations-vector.
136 typedef std::pair<ParametricType, AbstractValuation> FunctionValuation;
137
138 class FuncValHash {
139 public:
140 std::size_t operator()(FunctionValuation const& fv) const {
141 std::size_t seed = 0;
142 boost::hash_combine(seed, fv.first);
143 boost::hash_combine(seed, fv.second.getHashValue());
144 return seed;
145 }
146 };
147
148 // Stores the collected functions with the valuations together with a placeholder for the result.
149 std::unordered_map<FunctionValuation, ConstantType, FuncValHash> collectedFunctions;
150 };
151
152 FunctionValuationCollector functionValuationCollector;
153
154 // Returns the 2^(variables.size()) vertices of the region
155 std::vector<AbstractValuation> getVerticesOfAbstractRegion(std::set<VariableType> const& variables) const;
156
157 std::vector<AbstractValuation> rowLabels;
158
159 std::vector<uint_fast64_t> oldToNewColumnIndexMapping; // Mapping from old to new columnIndex used for monotonicity
160 std::vector<uint_fast64_t> rowGroupToStateNumber; // Mapping from new to old columnIndex used for monotonicity
161
162 storm::storage::SparseMatrix<ConstantType> matrix; // The resulting matrix;
163 std::vector<std::pair<typename storm::storage::SparseMatrix<ConstantType>::iterator, ConstantType&>>
164 matrixAssignment; // Connection of matrix entries with placeholders
165
166 std::vector<ConstantType> vector; // The resulting vector
167 std::vector<std::pair<typename std::vector<ConstantType>::iterator, ConstantType&>> vectorAssignment; // Connection of vector entries with placeholders
168
169 // Used for monotonicity in sparsedtmcparameterlifter
170 std::vector<std::set<VariableType>> occurringVariablesAtState;
171 std::map<VariableType, std::set<uint_fast64_t>> occuringStatesAtVariable;
172};
173
174} // namespace transformer
175} // namespace storm
storm::analysis::MonotonicityKind Monotonicity
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
A class that holds a possibly non-square matrix in the compressed row storage format.
std::set< VariableType > const & getUnspecifiedParameters() const
std::vector< storm::utility::parametric::Valuation< ParametricType > > getConcreteValuations(storm::storage::ParameterRegion< ParametricType > const &region) const
Returns the concrete valuation(s) (w.r.t.
AbstractValuation(AbstractValuation const &other)=default
std::set< VariableType > const & getUpperParameters() const
AbstractValuation getSubValuation(std::set< VariableType > const &pars) const
bool operator==(AbstractValuation const &other) const
std::set< VariableType > const & getLowerParameters() const
uint_fast64_t getRowGroupSize(uint_fast64_t originalState) const
uint_fast64_t getOriginalStateNumber(uint_fast64_t newState) const
void specifyRegion(storm::storage::ParameterRegion< ParametricType > const &region, storm::solver::OptimizationDirection const &dirForParameters)
storm::storage::SparseMatrix< ConstantType > const & getMatrix() const
std::vector< AbstractValuation > const & getRowLabels() const
uint_fast64_t getRowGroupIndex(uint_fast64_t originalState) const
std::map< VariableType, std::set< uint_fast64_t > > const & getOccuringStatesAtVariable() const
std::vector< ConstantType > const & getVector() const
storm::utility::parametric::CoefficientType< ParametricType >::type CoefficientType
storm::utility::parametric::VariableType< ParametricType >::type VariableType
storm::analysis::MonotonicityResult< VariableType >::Monotonicity Monotonicity
std::vector< std::set< VariableType > > const & getOccurringVariablesAtState() const
ParameterLifter(storm::storage::SparseMatrix< ParametricType > const &pMatrix, std::vector< ParametricType > const &pVector, storm::storage::BitVector const &selectedRows, storm::storage::BitVector const &selectedColumns, bool generateRowLabels=false, bool useMonotonicity=false)
Lifts the parameter choices to nondeterminisim.