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.

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