Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
ModelInstantiator.h
Go to the documentation of this file.
1#ifndef STORM_UTILITY_MODELINSTANTIATOR_H
2#define STORM_UTILITY_MODELINSTANTIATOR_H
3
4#include <memory>
5#include <type_traits>
6#include <unordered_map>
7
16
17namespace storm {
18namespace utility {
19
25template<typename ParametricSparseModelType, typename ConstantSparseModelType>
27 public:
28 typedef typename ParametricSparseModelType::ValueType ParametricType;
31 typedef typename ConstantSparseModelType::ValueType ConstantType;
32
37 ModelInstantiator(ParametricSparseModelType const& parametricModel);
38
42 virtual ~ModelInstantiator();
43
49 ConstantSparseModelType const& instantiate(storm::utility::parametric::Valuation<ParametricType> const& valuation);
50
54 void checkValid() const;
55
56 private:
61 template<typename PMT = ParametricSparseModelType>
62 typename std::enable_if<std::is_same<PMT, storm::models::sparse::Dtmc<typename ParametricSparseModelType::ValueType>>::value ||
63 std::is_same<PMT, storm::models::sparse::Mdp<typename ParametricSparseModelType::ValueType>>::value>::type
64 initializeModelSpecificData(PMT const& parametricModel) {
66 buildDummyMatrix(parametricModel.getTransitionMatrix()));
67 components.stateLabeling = parametricModel.getStateLabeling();
68 components.rewardModels = buildDummyRewardModels(parametricModel.getRewardModels());
69 components.choiceLabeling = parametricModel.getOptionalChoiceLabeling();
70
71 this->instantiatedModel = std::make_shared<ConstantSparseModelType>(std::move(components));
72 }
73
74 template<typename PMT = ParametricSparseModelType>
75 typename std::enable_if<std::is_same<PMT, storm::models::sparse::Ctmc<typename ParametricSparseModelType::ValueType>>::value>::type
76 initializeModelSpecificData(PMT const& parametricModel) {
78 buildDummyMatrix(parametricModel.getTransitionMatrix()));
79 components.stateLabeling = parametricModel.getStateLabeling();
80 components.rewardModels = buildDummyRewardModels(parametricModel.getRewardModels());
81 components.exitRates = std::vector<ConstantType>(parametricModel.getExitRateVector().size(), storm::utility::one<ConstantType>());
82 components.rateTransitions = true;
83 components.choiceLabeling = parametricModel.getOptionalChoiceLabeling();
84 this->instantiatedModel = std::make_shared<ConstantSparseModelType>(std::move(components));
85
86 initializeVectorMapping(this->instantiatedModel->getExitRateVector(), this->functions, this->vectorMapping, parametricModel.getExitRateVector());
87 }
88
89 template<typename PMT = ParametricSparseModelType>
90 typename std::enable_if<std::is_same<PMT, storm::models::sparse::MarkovAutomaton<typename ParametricSparseModelType::ValueType>>::value>::type
91 initializeModelSpecificData(PMT const& parametricModel) {
93 buildDummyMatrix(parametricModel.getTransitionMatrix()));
94 components.stateLabeling = parametricModel.getStateLabeling();
95 components.rewardModels = buildDummyRewardModels(parametricModel.getRewardModels());
96 components.exitRates = std::vector<ConstantType>(parametricModel.getExitRates().size(), storm::utility::one<ConstantType>());
97 components.markovianStates = parametricModel.getMarkovianStates();
98 components.choiceLabeling = parametricModel.getOptionalChoiceLabeling();
99 this->instantiatedModel = std::make_shared<ConstantSparseModelType>(std::move(components));
100
101 initializeVectorMapping(this->instantiatedModel->getExitRates(), this->functions, this->vectorMapping, parametricModel.getExitRates());
102 }
103
104 template<typename PMT = ParametricSparseModelType>
105 typename std::enable_if<std::is_same<PMT, storm::models::sparse::StochasticTwoPlayerGame<typename ParametricSparseModelType::ValueType>>::value>::type
106 initializeModelSpecificData(PMT const& parametricModel) {
108 buildDummyMatrix(parametricModel.getTransitionMatrix()));
109 components.stateLabeling = parametricModel.getStateLabeling();
110 components.rewardModels = buildDummyRewardModels(parametricModel.getRewardModels());
111 components.player1Matrix = parametricModel.getPlayer1Matrix();
112 components.choiceLabeling = parametricModel.getOptionalChoiceLabeling();
113
114 this->instantiatedModel = std::make_shared<ConstantSparseModelType>(std::move(components));
115 }
116
117 template<typename PMT = ParametricSparseModelType>
118 typename std::enable_if<std::is_same<PMT, ConstantSparseModelType>::value>::type instantiate_helper(
120 for (auto& functionResult : this->functions) {
121 functionResult.second = storm::utility::parametric::substitute(functionResult.first, valuation);
122 }
123 }
124
125 template<typename PMT = ParametricSparseModelType>
126 typename std::enable_if<!std::is_same<PMT, ConstantSparseModelType>::value>::type instantiate_helper(
128 for (auto& functionResult : this->functions) {
129 if (!transformer::BigStep::lastSavedAnnotations.empty() && functionResult.first.gatherVariables().size() == 1 &&
130 transformer::BigStep::lastSavedAnnotations.count(functionResult.first)) {
131 auto const& annotation = transformer::BigStep::lastSavedAnnotations.at(functionResult.first);
132 functionResult.second = annotation.evaluate(storm::utility::convertNumber<ConstantType>(valuation.at(annotation.getParameter())));
133 } else {
134 functionResult.second = storm::utility::parametric::evaluate<ConstantType>(functionResult.first, valuation);
135 }
136 }
137 }
138
144
149 std::unordered_map<std::string, typename ConstantSparseModelType::RewardModelType> buildDummyRewardModels(
150 std::unordered_map<std::string, typename ParametricSparseModelType::RewardModelType> const& parametricRewardModel) const;
151
162 void initializeMatrixMapping(storm::storage::SparseMatrix<ConstantType>& constantMatrix, std::unordered_map<ParametricType, ConstantType>& functions,
163 std::vector<std::pair<typename storm::storage::SparseMatrix<ConstantType>::iterator, ConstantType*>>& mapping,
164 storm::storage::SparseMatrix<ParametricType> const& parametricMatrix) const;
165
176 void initializeVectorMapping(std::vector<ConstantType>& constantVector, std::unordered_map<ParametricType, ConstantType>& functions,
177 std::vector<std::pair<typename std::vector<ConstantType>::iterator, ConstantType*>>& mapping,
178 std::vector<ParametricType> const& parametricVector) const;
179
181 std::shared_ptr<ConstantSparseModelType> instantiatedModel;
183 std::unordered_map<ParametricType, ConstantType> functions;
185 std::vector<std::pair<typename storm::storage::SparseMatrix<ConstantType>::iterator, ConstantType*>> matrixMapping;
187 std::vector<std::pair<typename std::vector<ConstantType>::iterator, ConstantType*>> vectorMapping;
188};
189} // Namespace utility
190} // namespace storm
191#endif /* STORM_UTILITY_MODELINSTANTIATOR_H */
A class that holds a possibly non-square matrix in the compressed row storage format.
std::vector< MatrixEntry< index_type, value_type > >::iterator iterator
static std::unordered_map< RationalFunction, Annotation > lastSavedAnnotations
Definition BigStep.h:198
This class allows efficient instantiation of the given parametric model.
storm::utility::parametric::VariableType< ParametricType >::type VariableType
virtual ~ModelInstantiator()
Destructs the ModelInstantiator.
ParametricSparseModelType::ValueType ParametricType
void checkValid() const
Check validity.
ConstantSparseModelType::ValueType ConstantType
storm::utility::parametric::CoefficientType< ParametricType >::type CoefficientType
ConstantSparseModelType const & instantiate(storm::utility::parametric::Valuation< ParametricType > const &valuation)
Evaluates the occurring parametric functions and retrieves the instantiated model.
FunctionType substitute(FunctionType const &function, Valuation< FunctionType > const &valuation)
Evaluates the given function wrt.
std::map< typename VariableType< FunctionType >::type, typename CoefficientType< FunctionType >::type > Valuation
Definition parametric.h:43
LabParser.cpp.