From a568ea27dd2bbd1856256af3c3680d97b64dc1a2 Mon Sep 17 00:00:00 2001 From: Sebastian Junges Date: Sun, 13 Aug 2017 15:54:46 +0200 Subject: [PATCH] Moved the model instantiator to parameters, as this is now part of stormpy.pars --- lib/stormpy/pars/__init__.py | 30 +++++++++++++++++++++++++++ lib/stormpy/storage/__init__.py | 29 -------------------------- tests/pars/test_model_instantiator.py | 2 +- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/lib/stormpy/pars/__init__.py b/lib/stormpy/pars/__init__.py index fa1becf..8c90b69 100644 --- a/lib/stormpy/pars/__init__.py +++ b/lib/stormpy/pars/__init__.py @@ -11,6 +11,36 @@ from stormpy import ModelType, StormError pars._set_up() +class ModelInstantiator: + """ + Class for instantiating models. + """ + + def __init__(self, model): + """ + Constructor. + :param model: Model. + """ + if model.model_type == ModelType.MDP: + self._instantiator = PMdpInstantiator(model) + elif model.model_type == ModelType.DTMC: + self._instantiator = PDtmcInstantiator(model) + elif model.model_type == ModelType.CTMC: + self._instantiator = PCtmcInstantiator(model) + elif model.model_type == ModelType.MA: + self._instantiator = PMaInstantiator(model) + else: + raise StormError("Model type {} not supported".format(model.model_type)) + + def instantiate(self, valuation): + """ + Instantiate model with given valuation. + :param valuation: Valuation from parameter to value. + :return: Instantiated model. + """ + return self._instantiator.instantiate(valuation) + + def simplify_model(model, formula): """ Simplify parametric model preserving the given formula by eliminating states with constant outgoing probabilities. diff --git a/lib/stormpy/storage/__init__.py b/lib/stormpy/storage/__init__.py index 619de94..d235dea 100644 --- a/lib/stormpy/storage/__init__.py +++ b/lib/stormpy/storage/__init__.py @@ -1,32 +1,3 @@ from . import storage from .storage import * - -class ModelInstantiator: - """ - Class for instantiating models. - """ - - def __init__(self, model): - """ - Constructor. - :param model: Model. - """ - if model.model_type == ModelType.MDP: - self._instantiator = PmdpInstantiator(model) - elif model.model_type == ModelType.DTMC: - self._instantiator = PdtmcInstantiator(model) - elif model.model_type == ModelType.CTMC: - self._instantiator = PctmcInstantiator(model) - elif model.model_type == ModelType.MA: - self._instantiator = PmaInstantiator(model) - else: - raise StormError("Model type {} not supported".format(model.model_type)) - - def instantiate(self, valuation): - """ - Instantiate model with given valuation. - :param valuation: Valuation from parameter to value. - :return: Instantiated model. - """ - return self._instantiator.instantiate(valuation) diff --git a/tests/pars/test_model_instantiator.py b/tests/pars/test_model_instantiator.py index cebc399..cfad8a0 100644 --- a/tests/pars/test_model_instantiator.py +++ b/tests/pars/test_model_instantiator.py @@ -13,7 +13,7 @@ class TestModelInstantiator: model = stormpy.build_parametric_model(program, formulas) parameters = model.collect_probability_parameters() assert len(parameters) == 2 - instantiator = stormpy.pars.PDtmcInstantiator(model) + instantiator = stormpy.pars.ModelInstantiator(model) point = {p: stormpy.RationalRF("0.4") for p in parameters} instantiated_model = instantiator.instantiate(point)