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.

82 lines
3.2 KiB

  1. import stormpy
  2. import stormpy.core
  3. import stormpy.info
  4. import pycarl
  5. import pycarl.core
  6. import stormpy.examples
  7. import stormpy.examples.files
  8. import stormpy.pomdp
  9. import stormpy._config as config
  10. def example_parametric_models_01():
  11. # Check support for parameters
  12. if not config.storm_with_pars:
  13. print("Support parameters is missing. Try building storm-pars.")
  14. return
  15. import stormpy.pars
  16. from pycarl.formula import FormulaType, Relation
  17. if stormpy.info.storm_ratfunc_use_cln():
  18. import pycarl.cln.formula
  19. else:
  20. import pycarl.gmp.formula
  21. # Prevent curious side effects from earlier runs (for tests only)
  22. pycarl.clear_pools()
  23. ###
  24. # How to apply an unknown FSC to obtain a pMC from a POMDP
  25. path = stormpy.examples.files.prism_pomdp_maze
  26. prism_program = stormpy.parse_prism_program(path)
  27. formula_str = "P=? [\"goal\"]"
  28. properties = stormpy.parse_properties_for_prism_program(formula_str, prism_program)
  29. # construct the POMDP
  30. pomdp = stormpy.build_model(prism_program, properties)
  31. # make its representation canonic.
  32. pomdp = stormpy.pomdp.make_canonic(pomdp)
  33. # make the POMDP simple. This step is optional but often beneficial
  34. pomdp = stormpy.pomdp.make_simple(pomdp)
  35. # construct the memory for the FSC
  36. # in this case, a selective counter with two states
  37. memory_builder = stormpy.pomdp.PomdpMemoryBuilder()
  38. memory = memory_builder.build(stormpy.pomdp.PomdpMemoryPattern.selective_counter, 2)
  39. # apply the memory onto the POMDP to get the cartesian product
  40. pomdp = stormpy.pomdp.unfold_memory(pomdp, memory)
  41. # apply the memory onto the POMDP to get the cartesian product
  42. pmc = stormpy.pomdp.apply_unknown_fsc(pomdp, stormpy.pomdp.PomdpFscApplicationMode.simple_linear)
  43. ####
  44. # How to apply an unknown FSC to obtain a pMC from a pPOMDP
  45. path = stormpy.examples.files.prism_par_pomdp_maze
  46. prism_program = stormpy.parse_prism_program(path)
  47. formula_str = "P=? [\"goal\"]"
  48. properties = stormpy.parse_properties_for_prism_program(formula_str, prism_program)
  49. # construct the pPOMDP
  50. pomdp = stormpy.build_parametric_model(prism_program, properties)
  51. # make its representation canonic.
  52. pomdp = stormpy.pomdp.make_canonic(pomdp)
  53. # make the POMDP simple. This step is optional but often beneficial
  54. pomdp = stormpy.pomdp.make_simple(pomdp)
  55. # construct the memory for the FSC
  56. # in this case, a selective counter with two states
  57. memory_builder = stormpy.pomdp.PomdpMemoryBuilder()
  58. memory = memory_builder.build(stormpy.pomdp.PomdpMemoryPattern.selective_counter, 2)
  59. # apply the memory onto the POMDP to get the cartesian product
  60. pomdp = stormpy.pomdp.unfold_memory(pomdp, memory)
  61. # apply the unknown FSC to obtain a pmc from the POMDP
  62. pmc = stormpy.pomdp.apply_unknown_fsc(pomdp, stormpy.pomdp.PomdpFscApplicationMode.simple_linear)
  63. export_pmc = False # Set to True to export the pMC as drn.
  64. if export_pmc:
  65. export_options = stormpy.core.DirectEncodingOptions()
  66. export_options.allow_placeholders = False
  67. stormpy.export_parametric_to_drn(pmc, "test.out", export_options)
  68. if __name__ == '__main__':
  69. example_parametric_models_01()