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.

54 lines
1.7 KiB

2 months ago
  1. import stormpy
  2. import stormpy.core
  3. import pycarl
  4. import pycarl.core
  5. import stormpy.examples
  6. import stormpy.examples.files
  7. import stormpy._config as config
  8. def example_parametric_models_04():
  9. # Check support for parameters
  10. if not config.storm_with_pars:
  11. print("Support parameters is missing. Try building storm-pars.")
  12. return
  13. import stormpy.pars
  14. path = stormpy.examples.files.prism_pdtmc_die
  15. prism_program = stormpy.parse_prism_program(path)
  16. formula_str = "P=? [F s=7 & d=2]"
  17. properties = stormpy.parse_properties(formula_str, prism_program)
  18. model = stormpy.build_parametric_model(prism_program, properties)
  19. # Modify
  20. i = 0
  21. for state in model.states:
  22. if state.id in model.initial_states:
  23. print(state)
  24. for action in state.actions:
  25. for transition in action.transitions:
  26. if len(transition.value().gather_variables()) > 0:
  27. new_var = pycarl.Variable("p{}".format(i))
  28. i += 1
  29. new_pol = stormpy.Polynomial(new_var)
  30. pol_in_right_format = stormpy.FactorizedPolynomial(new_pol, transition.value().numerator.cache())
  31. new_factorized_ratfunc = stormpy.FactorizedRationalFunction(pol_in_right_format)
  32. transition.set_value(new_factorized_ratfunc)
  33. # Display
  34. for state in model.states:
  35. if state.id in model.initial_states:
  36. print(state)
  37. for action in state.actions:
  38. for transition in action.transitions:
  39. print("From state {}, with probability {}, go to state {}".format(state, transition.value(), transition.column))
  40. if __name__ == '__main__':
  41. example_parametric_models_04()