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.

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