Browse Source

Moved the model instantiator to parameters, as this is now part of stormpy.pars

refactoring
Sebastian Junges 7 years ago
parent
commit
a568ea27dd
  1. 30
      lib/stormpy/pars/__init__.py
  2. 29
      lib/stormpy/storage/__init__.py
  3. 2
      tests/pars/test_model_instantiator.py

30
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.

29
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)

2
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)

Loading…
Cancel
Save