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.

101 lines
3.8 KiB

8 years ago
8 years ago
8 years ago
  1. from . import core
  2. from .core import *
  3. from . import storage
  4. from .storage import *
  5. from .version import __version__
  6. import stormpy.logic
  7. from pycarl import Variable # needed for building parametric models
  8. core._set_up("")
  9. def build_model(program, properties=None):
  10. """
  11. Build a model from a symbolic description
  12. :param PrismProgram program: Prism program to translate into a model.
  13. :param List[Property] properties: List of properties that should be preserved during the translation. If None, then all properties are preserved.
  14. """
  15. if properties:
  16. formulae = [prop.raw_formula for prop in properties]
  17. intermediate = core._build_sparse_model_from_prism_program(program, formulae)
  18. else:
  19. intermediate = core._build_sparse_model_from_prism_program(program)
  20. assert not intermediate.supports_parameters
  21. if intermediate.model_type == ModelType.DTMC:
  22. return intermediate._as_dtmc()
  23. elif intermediate.model_type == ModelType.MDP:
  24. return intermediate._as_mdp()
  25. else:
  26. raise RuntimeError("Not supported non-parametric model constructed")
  27. def build_parametric_model(program, properties=None):
  28. """
  29. :param PrismProgram program: Prism program with open constants to translate into a parametric model.
  30. :param List[Property] properties: List of properties that should be preserved during the translation. If None, then all properties are preserved.
  31. """
  32. if properties:
  33. formulae = [prop.raw_formula for prop in properties]
  34. else:
  35. formulae = []
  36. intermediate = core._build_sparse_parametric_model_from_prism_program(program, formulae)
  37. assert intermediate.supports_parameters
  38. if intermediate.model_type == ModelType.DTMC:
  39. return intermediate._as_pdtmc()
  40. elif intermediate.model_type == ModelType.MDP:
  41. return intermediate._as_pmdp()
  42. else:
  43. raise RuntimeError("Not supported parametric model constructed")
  44. def perform_bisimulation(model, property, bisimulation_type):
  45. if model.supports_parameters:
  46. return core._perform_parametric_bisimulation(model, property.raw_formula, bisimulation_type)
  47. else:
  48. return core._perform_bisimulation(model, property.raw_formula, bisimulation_type)
  49. def model_checking(model, property):
  50. if model.supports_parameters:
  51. return core._parametric_model_checking(model, property.raw_formula)
  52. else:
  53. return core._model_checking(model, property.raw_formula)
  54. def compute_prob01_states(model, phi_states, psi_states):
  55. """
  56. Compute prob01 states for properties of the form phi_states until psi_states
  57. :param SparseDTMC model:
  58. :param BitVector phi_states:
  59. :param BitVector psi_states:
  60. """
  61. if model.model_type != ModelType.DTMC:
  62. raise ValueError("Prob 01 is only defined for DTMCs -- model must be a DTMC")
  63. if model.supports_parameters:
  64. return core._compute_prob01states_rationalfunc(model, phi_states, psi_states)
  65. else:
  66. return core._compute_prob01states_double(model, phi_states, psi_states)
  67. def compute_prob01min_states(model, phi_states, psi_states):
  68. if model.model_type == ModelType.DTMC:
  69. return compute_prob01_states(model, phi_states, psi_states)
  70. if model.supports_parameters:
  71. return core._compute_prob01states_min_rationalfunc(model, phi_states, psi_states)
  72. else:
  73. return core._compute_prob01states_min_double(model, phi_states, psi_states)
  74. def compute_prob01max_states(model, phi_states, psi_states):
  75. if model.model_type == ModelType.DTMC:
  76. return compute_prob01_states(model, phi_states, psi_states)
  77. if model.supports_parameters:
  78. return core._compute_prob01states_max_rationalfunc(model, phi_states, psi_states)
  79. else:
  80. return core._compute_prob01states_max_double(model, phi_states, psi_states)