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.

148 lines
5.7 KiB

8 years ago
8 years ago
8 years ago
8 years ago
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. :return: Model in sparse representation.
  15. :rtype: SparseDtmc or SparseMdp
  16. """
  17. if properties:
  18. formulae = [prop.raw_formula for prop in properties]
  19. intermediate = core._build_sparse_model_from_prism_program(program, formulae)
  20. else:
  21. intermediate = core._build_sparse_model_from_prism_program(program)
  22. assert not intermediate.supports_parameters
  23. if intermediate.model_type == ModelType.DTMC:
  24. return intermediate._as_dtmc()
  25. elif intermediate.model_type == ModelType.MDP:
  26. return intermediate._as_mdp()
  27. else:
  28. raise RuntimeError("Not supported non-parametric model constructed")
  29. def build_parametric_model(program, properties=None):
  30. """
  31. Build a parametric model from a symbolic description.
  32. :param PrismProgram program: Prism program with open constants to translate into a parametric model.
  33. :param List[Property] properties: List of properties that should be preserved during the translation. If None, then all properties are preserved.
  34. :return: Parametric model in sparse representation.
  35. :rtype: SparseParametricDtmc or SparseParametricMdp
  36. """
  37. if properties:
  38. formulae = [prop.raw_formula for prop in properties]
  39. else:
  40. formulae = []
  41. intermediate = core._build_sparse_parametric_model_from_prism_program(program, formulae)
  42. assert intermediate.supports_parameters
  43. if intermediate.model_type == ModelType.DTMC:
  44. return intermediate._as_pdtmc()
  45. elif intermediate.model_type == ModelType.MDP:
  46. return intermediate._as_pmdp()
  47. else:
  48. raise RuntimeError("Not supported parametric model constructed")
  49. def build_model_from_drn(file):
  50. """
  51. Build a model from the explicit DRN representation.
  52. :param String file: DRN file containing the model.
  53. :return: Model in sparse representation.
  54. :rtype: SparseDtmc or SparseMdp or SparseCTMC or SparseMA
  55. """
  56. intermediate = core._build_sparse_model_from_drn(file)
  57. assert not intermediate.supports_parameters
  58. if intermediate.model_type == ModelType.DTMC:
  59. return intermediate._as_dtmc()
  60. elif intermediate.model_type == ModelType.MDP:
  61. return intermediate._as_mdp()
  62. elif intermediate.model_type == ModelType.CTMC:
  63. return intermediate._as_ctmc()
  64. elif intermediate.model_type == ModelType.MA:
  65. return intermediate._as_ma()
  66. else:
  67. raise RuntimeError("Not supported non-parametric model constructed")
  68. def build_parametric_model_from_drn(file):
  69. """
  70. Build a parametric model from the explicit DRN representation.
  71. :param String file: DRN file containing the model.
  72. :return: Parametric model in sparse representation.
  73. :rtype: SparseParametricDtmc or SparseParametricMdp or SparseParametricCTMC or SparseParametricMA
  74. """
  75. intermediate = core._build_sparse_parametric_model_from_drn(file)
  76. assert intermediate.supports_parameters
  77. if intermediate.model_type == ModelType.DTMC:
  78. return intermediate._as_pdtmc()
  79. elif intermediate.model_type == ModelType.MDP:
  80. return intermediate._as_pmdp()
  81. elif intermediate.model_type == ModelType.CTMC:
  82. return intermediate._as_pctmc()
  83. elif intermediate.model_type == ModelType.MA:
  84. return intermediate._as_pma()
  85. else:
  86. raise RuntimeError("Not supported parametric model constructed")
  87. def perform_bisimulation(model, properties, bisimulation_type):
  88. formulae = [prop.raw_formula for prop in properties]
  89. if model.supports_parameters:
  90. return core._perform_parametric_bisimulation(model, formulae, bisimulation_type)
  91. else:
  92. return core._perform_bisimulation(model, formulae, bisimulation_type)
  93. def model_checking(model, property):
  94. if model.supports_parameters:
  95. return core._parametric_model_checking(model, property.raw_formula)
  96. else:
  97. return core._model_checking(model, property.raw_formula)
  98. def compute_prob01_states(model, phi_states, psi_states):
  99. """
  100. Compute prob01 states for properties of the form phi_states until psi_states
  101. :param SparseDTMC model:
  102. :param BitVector phi_states:
  103. :param BitVector psi_states:
  104. """
  105. if model.model_type != ModelType.DTMC:
  106. raise ValueError("Prob 01 is only defined for DTMCs -- model must be a DTMC")
  107. if model.supports_parameters:
  108. return core._compute_prob01states_rationalfunc(model, phi_states, psi_states)
  109. else:
  110. return core._compute_prob01states_double(model, phi_states, psi_states)
  111. def compute_prob01min_states(model, phi_states, psi_states):
  112. if model.model_type == ModelType.DTMC:
  113. return compute_prob01_states(model, phi_states, psi_states)
  114. if model.supports_parameters:
  115. return core._compute_prob01states_min_rationalfunc(model, phi_states, psi_states)
  116. else:
  117. return core._compute_prob01states_min_double(model, phi_states, psi_states)
  118. def compute_prob01max_states(model, phi_states, psi_states):
  119. if model.model_type == ModelType.DTMC:
  120. return compute_prob01_states(model, phi_states, psi_states)
  121. if model.supports_parameters:
  122. return core._compute_prob01states_max_rationalfunc(model, phi_states, psi_states)
  123. else:
  124. return core._compute_prob01states_max_double(model, phi_states, psi_states)