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.

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