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.

62 lines
2.1 KiB

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