You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.9 KiB

  1. from . import _config
  2. if not _config.storm_with_pars:
  3. raise ImportError("No support for parametric analysis was built in Storm.")
  4. from . import pars
  5. from .pars import *
  6. from stormpy import ModelType, StormError
  7. pars._set_up()
  8. class ModelInstantiator:
  9. """
  10. Class for instantiating models.
  11. """
  12. def __init__(self, model):
  13. """
  14. Constructor.
  15. :param model: Model.
  16. """
  17. if model.model_type == ModelType.MDP:
  18. self._instantiator = PMdpInstantiator(model)
  19. elif model.model_type == ModelType.DTMC:
  20. self._instantiator = PDtmcInstantiator(model)
  21. elif model.model_type == ModelType.CTMC:
  22. self._instantiator = PCtmcInstantiator(model)
  23. elif model.model_type == ModelType.MA:
  24. self._instantiator = PMaInstantiator(model)
  25. else:
  26. raise StormError("Model type {} not supported".format(model.model_type))
  27. def instantiate(self, valuation):
  28. """
  29. Instantiate model with given valuation.
  30. :param valuation: Valuation from parameter to value.
  31. :return: Instantiated model.
  32. """
  33. return self._instantiator.instantiate(valuation)
  34. def simplify_model(model, formula):
  35. """
  36. Simplify parametric model preserving the given formula by eliminating states with constant outgoing probabilities.
  37. :param model: Model.
  38. :param formula: Formula.
  39. :return: Tuple of simplified model and simplified formula.
  40. """
  41. if model.model_type == ModelType.DTMC:
  42. simplifier = pars._SparseParametricDtmcSimplifier(model)
  43. elif model.model_type == ModelType.MDP:
  44. simplifier = pars._SparseParametricMdpSimplifier(model)
  45. else:
  46. raise StormError("Model type {} cannot be simplified.".format(model.model_type))
  47. if not simplifier.simplify(formula):
  48. raise StormError("Model could not be simplified")
  49. return simplifier.simplified_model, simplifier.simplified_formula