Storm
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
15
16namespace storm {
17namespace utility {
18
24template<typename ParametricSparseModelType, typename ConstantSparseModelType>
26 public:
27 typedef typename ParametricSparseModelType::ValueType ParametricType;
30 typedef typename ConstantSparseModelType::ValueType ConstantType;
31
36 ModelInstantiator(ParametricSparseModelType const& parametricModel);
37
41 virtual ~ModelInstantiator();
42
48 ConstantSparseModelType const& instantiate(storm::utility::parametric::Valuation<ParametricType> const& valuation);
49
53 void checkValid() const;
54
55 private:
60 template<typename PMT = ParametricSparseModelType>
61 typename std::enable_if<std::is_same<PMT, storm::models::sparse::Dtmc<typename ParametricSparseModelType::ValueType>>::value ||
62 std::is_same<PMT, storm::models::sparse::Mdp<typename ParametricSparseModelType::ValueType>>::value>::type
63 initializeModelSpecificData(PMT const& parametricModel) {
65 buildDummyMatrix(parametricModel.getTransitionMatrix()));
66 components.stateLabeling = parametricModel.getStateLabeling();
67 components.rewardModels = buildDummyRewardModels(parametricModel.getRewardModels());
68 components.choiceLabeling = parametricModel.getOptionalChoiceLabeling();
69
70 this->instantiatedModel = std::make_shared<ConstantSparseModelType>(std::move(components));
71 }
72
73 template<typename PMT = ParametricSparseModelType>
74 typename std::enable_if<std::is_same<PMT, storm::models::sparse::Ctmc<typename ParametricSparseModelType::ValueType>>::value>::type
75 initializeModelSpecificData(PMT const& parametricModel) {
77 buildDummyMatrix(parametricModel.getTransitionMatrix()));
78 components.stateLabeling = parametricModel.getStateLabeling();
79 components.rewardModels = buildDummyRewardModels(parametricModel.getRewardModels());
80 components.exitRates = std::vector<ConstantType>(parametricModel.getExitRateVector().size(), storm::utility::one<ConstantType>());
81 components.rateTransitions = true;
82 components.choiceLabeling = parametricModel.getOptionalChoiceLabeling();
83 this->instantiatedModel = std::make_shared<ConstantSparseModelType>(std::move(components));
84
85 initializeVectorMapping(this->instantiatedModel->getExitRateVector(), this->functions, this->vectorMapping, parametricModel.getExitRateVector());
86 }
87
88 template<typename PMT = ParametricSparseModelType>
89 typename std::enable_if<std::is_same<PMT, storm::models::sparse::MarkovAutomaton<typename ParametricSparseModelType::ValueType>>::value>::type
90 initializeModelSpecificData(PMT const& parametricModel) {
92 buildDummyMatrix(parametricModel.getTransitionMatrix()));
93 components.stateLabeling = parametricModel.getStateLabeling();
94 components.rewardModels = buildDummyRewardModels(parametricModel.getRewardModels());
95 components.exitRates = std::vector<ConstantType>(parametricModel.getExitRates().size(), storm::utility::one<ConstantType>());
96 components.markovianStates = parametricModel.getMarkovianStates();
97 components.choiceLabeling = parametricModel.getOptionalChoiceLabeling();
98 this->instantiatedModel = std::make_shared<ConstantSparseModelType>(std::move(components));
99
100 initializeVectorMapping(this->instantiatedModel->getExitRates(), this->functions, this->vectorMapping, parametricModel.getExitRates());
101 }
102
103 template<typename PMT = ParametricSparseModelType>
104 typename std::enable_if<std::is_same<PMT, storm::models::sparse::StochasticTwoPlayerGame<typename ParametricSparseModelType::ValueType>>::value>::type
105 initializeModelSpecificData(PMT const& parametricModel) {
107 buildDummyMatrix(parametricModel.getTransitionMatrix()));
108 components.stateLabeling = parametricModel.getStateLabeling();
109 components.rewardModels = buildDummyRewardModels(parametricModel.getRewardModels());
110 components.player1Matrix = parametricModel.getPlayer1Matrix();
111 components.choiceLabeling = parametricModel.getOptionalChoiceLabeling();
112
113 this->instantiatedModel = std::make_shared<ConstantSparseModelType>(std::move(components));
114 }
115
116 template<typename PMT = ParametricSparseModelType>
117 typename std::enable_if<std::is_same<PMT, ConstantSparseModelType>::value>::type instantiate_helper(
119 for (auto& functionResult : this->functions) {
120 functionResult.second = storm::utility::parametric::substitute(functionResult.first, valuation);
121 }
122 }
123
124 template<typename PMT = ParametricSparseModelType>
125 typename std::enable_if<!std::is_same<PMT, ConstantSparseModelType>::value>::type instantiate_helper(
127 for (auto& functionResult : this->functions) {
128 functionResult.second = storm::utility::convertNumber<ConstantType>(storm::utility::parametric::evaluate(functionResult.first, valuation));
129 }
130 }
131
137
142 std::unordered_map<std::string, typename ConstantSparseModelType::RewardModelType> buildDummyRewardModels(
143 std::unordered_map<std::string, typename ParametricSparseModelType::RewardModelType> const& parametricRewardModel) const;
144
155 void initializeMatrixMapping(storm::storage::SparseMatrix<ConstantType>& constantMatrix, std::unordered_map<ParametricType, ConstantType>& functions,
156 std::vector<std::pair<typename storm::storage::SparseMatrix<ConstantType>::iterator, ConstantType*>>& mapping,
157 storm::storage::SparseMatrix<ParametricType> const& parametricMatrix) const;
158
169 void initializeVectorMapping(std::vector<ConstantType>& constantVector, std::unordered_map<ParametricType, ConstantType>& functions,
170 std::vector<std::pair<typename std::vector<ConstantType>::iterator, ConstantType*>>& mapping,
171 std::vector<ParametricType> const& parametricVector) const;
172
174 std::shared_ptr<ConstantSparseModelType> instantiatedModel;
176 std::unordered_map<ParametricType, ConstantType> functions;
178 std::vector<std::pair<typename storm::storage::SparseMatrix<ConstantType>::iterator, ConstantType*>> matrixMapping;
180 std::vector<std::pair<typename std::vector<ConstantType>::iterator, ConstantType*>> vectorMapping;
181};
182} // Namespace utility
183} // namespace storm
184#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
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:41
CoefficientType< FunctionType >::type evaluate(FunctionType const &function, Valuation< FunctionType > const &valuation)
Evaluates the given function wrt.
LabParser.cpp.
Definition cli.cpp:18