diff --git a/src/storm-pars/utility/ModelInstantiator.cpp b/src/storm-pars/utility/ModelInstantiator.cpp index f59649ab7..719427529 100644 --- a/src/storm-pars/utility/ModelInstantiator.cpp +++ b/src/storm-pars/utility/ModelInstantiator.cpp @@ -137,10 +137,7 @@ namespace storm { template ConstantSparseModelType const& ModelInstantiator::instantiate(storm::utility::parametric::Valuation const& valuation){ //Write results into the placeholders - for(auto& functionResult : this->functions){ - functionResult.second=storm::utility::convertNumber( - storm::utility::parametric::evaluate(functionResult.first, valuation)); - } + instantiate_helper(valuation); //Write the instantiated values to the matrices and vectors according to the stored mappings for(auto& entryValuePair : this->matrixMapping){ @@ -170,6 +167,12 @@ namespace storm { template class ModelInstantiator, storm::models::sparse::Ctmc>; template class ModelInstantiator, storm::models::sparse::MarkovAutomaton>; template class ModelInstantiator, storm::models::sparse::StochasticTwoPlayerGame>; + + // For stormpy: + template class ModelInstantiator, storm::models::sparse::Dtmc>; + template class ModelInstantiator, storm::models::sparse::Mdp>; + template class ModelInstantiator, storm::models::sparse::Ctmc>; + template class ModelInstantiator, storm::models::sparse::MarkovAutomaton>; #endif } //namespace utility } //namespace storm diff --git a/src/storm-pars/utility/ModelInstantiator.h b/src/storm-pars/utility/ModelInstantiator.h index e96a4dda8..cba624074 100644 --- a/src/storm-pars/utility/ModelInstantiator.h +++ b/src/storm-pars/utility/ModelInstantiator.h @@ -117,7 +117,29 @@ namespace storm { this->instantiatedModel = std::make_shared(std::move(components)); } - + + template + typename std::enable_if< + std::is_same::value + >::type + instantiate_helper(storm::utility::parametric::Valuation const& valuation) { + for(auto& functionResult : this->functions){ + functionResult.second= + storm::utility::parametric::substitute(functionResult.first, valuation); + } + } + + template + typename std::enable_if< + !std::is_same::value + >::type + instantiate_helper(storm::utility::parametric::Valuation const& valuation) { + for(auto& functionResult : this->functions){ + functionResult.second=storm::utility::convertNumber( + storm::utility::parametric::evaluate(functionResult.first, valuation)); + } + } + /*! * Creates a matrix that has entries at the same position as the given matrix. * The returned matrix is a stochastic matrix, i.e., the rows sum up to one. diff --git a/src/storm-pars/utility/parametric.cpp b/src/storm-pars/utility/parametric.cpp index 3b6934a3e..96c30e78e 100644 --- a/src/storm-pars/utility/parametric.cpp +++ b/src/storm-pars/utility/parametric.cpp @@ -21,7 +21,13 @@ namespace storm { typename CoefficientType::type evaluate(storm::RationalFunction const& function, Valuation const& valuation){ return function.evaluate(valuation); } - + + template<> + typename storm::RationalFunction substitute(storm::RationalFunction const& function, Valuation const& valuation){ + return function.substitute(valuation); + } + + template<> void gatherOccurringVariables(storm::RationalFunction const& function, std::set::type>& variableSet){ function.gatherVariables(variableSet); diff --git a/src/storm-pars/utility/parametric.h b/src/storm-pars/utility/parametric.h index 77a58e7f8..31a81f1a7 100644 --- a/src/storm-pars/utility/parametric.h +++ b/src/storm-pars/utility/parametric.h @@ -35,7 +35,13 @@ namespace storm { */ template typename CoefficientType::type evaluate(FunctionType const& function, Valuation const& valuation); - + + /*! + * Evaluates the given function wrt. the given valuation + */ + template + FunctionType substitute(FunctionType const& function, Valuation const& valuation); + /*! * Add all variables that occur in the given function to the the given set */