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.

141 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, properties, bisimulation_type):
  87. formulae = [prop.raw_formula for prop in properties]
  88. if model.supports_parameters:
  89. return core._perform_parametric_bisimulation(model, formulae, bisimulation_type)
  90. else:
  91. return core._perform_bisimulation(model, formulae, bisimulation_type)
  92. def model_checking(model, property):
  93. if model.supports_parameters:
  94. return core._parametric_model_checking(model, property.raw_formula)
  95. else:
  96. return core._model_checking(model, property.raw_formula)
  97. def compute_prob01_states(model, phi_states, psi_states):
  98. """
  99. Compute prob01 states for properties of the form phi_states until psi_states
  100. :param SparseDTMC model:
  101. :param BitVector phi_states:
  102. :param BitVector psi_states:
  103. """
  104. if model.model_type != ModelType.DTMC:
  105. raise ValueError("Prob 01 is only defined for DTMCs -- model must be a DTMC")
  106. if model.supports_parameters:
  107. return core._compute_prob01states_rationalfunc(model, phi_states, psi_states)
  108. else:
  109. return core._compute_prob01states_double(model, phi_states, psi_states)
  110. def compute_prob01min_states(model, phi_states, psi_states):
  111. if model.model_type == ModelType.DTMC:
  112. return compute_prob01_states(model, phi_states, psi_states)
  113. if model.supports_parameters:
  114. return core._compute_prob01states_min_rationalfunc(model, phi_states, psi_states)
  115. else:
  116. return core._compute_prob01states_min_double(model, phi_states, psi_states)
  117. def compute_prob01max_states(model, phi_states, psi_states):
  118. if model.model_type == ModelType.DTMC:
  119. return compute_prob01_states(model, phi_states, psi_states)
  120. if model.supports_parameters:
  121. return core._compute_prob01states_max_rationalfunc(model, phi_states, psi_states)
  122. else:
  123. return core._compute_prob01states_max_double(model, phi_states, psi_states)