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.

65 lines
2.1 KiB

  1. import time
  2. import stormpy
  3. import stormpy.core
  4. import stormpy.examples
  5. import stormpy.examples.files
  6. import stormpy._config as config
  7. def example_parametric_models_03():
  8. if not config.storm_with_pars:
  9. print("Support parameters is missing. Try building storm-pars.")
  10. return
  11. path = stormpy.examples.files.prism_dtmc_brp
  12. prism_program = stormpy.parse_prism_program(path)
  13. formula_str = "P=? [F \"target\"]"
  14. properties = stormpy.parse_properties_for_prism_program(formula_str, prism_program)
  15. model = stormpy.build_parametric_model(prism_program, properties)
  16. print(model.model_type)
  17. start = time.time()
  18. t = 0
  19. for state in model.states:
  20. if state.id in model.initial_states:
  21. print(state)
  22. for action in state.actions:
  23. for transition in action.transitions:
  24. if transition.value().constant_part() == 1:
  25. t += 1
  26. #print("From state {}, with probability {}, go to state {}".format(state, transition.value(), transition.column))
  27. print(time.time() - start)
  28. print(t)
  29. t2 = 0
  30. start = time.time()
  31. for row_group in range(model.nr_states):
  32. for row in range(model.transition_matrix.get_row_group_start(row_group), model.transition_matrix.get_row_group_end(row_group)):
  33. for entry in model.transition_matrix.get_row(row):
  34. if entry.value().constant_part() == 1:
  35. t2 += 1
  36. print(time.time() - start)
  37. print(t2)
  38. states_and_transitions = []
  39. for row_group in range(model.nr_states):
  40. states_and_transitions.append([])
  41. for row in range(model.transition_matrix.get_row_group_start(row_group), model.transition_matrix.get_row_group_end(row_group)):
  42. for entry in model.transition_matrix.get_row(row):
  43. states_and_transitions[-1].append((entry.value(), entry.column))
  44. t3 = 0
  45. start = time.time()
  46. for s in states_and_transitions:
  47. for (v,c) in s:
  48. if v.constant_part() == 1:
  49. t3 += 1
  50. print(time.time() - start)
  51. print(t3)
  52. if __name__ == '__main__':
  53. example_parametric_models_03()