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.

58 lines
2.0 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. path = stormpy.examples.files.prism_dtmc_brp
  8. prism_program = stormpy.parse_prism_program(path)
  9. formula_str = "P=? [F \"target\"]"
  10. properties = stormpy.parse_properties_for_prism_program(formula_str, prism_program)
  11. model = stormpy.build_parametric_model(prism_program, properties)
  12. print(model.model_type)
  13. start = time.time()
  14. t = 0
  15. for state in model.states:
  16. if state.id in model.initial_states:
  17. print(state)
  18. for action in state.actions:
  19. for transition in action.transitions:
  20. if transition.value().constant_part() == 1:
  21. t += 1
  22. #print("From state {}, with probability {}, go to state {}".format(state, transition.value(), transition.column))
  23. print(time.time() - start)
  24. print(t)
  25. t2 = 0
  26. start = time.time()
  27. for row_group in range(model.nr_states):
  28. for row in range(model.transition_matrix.get_row_group_start(row_group), model.transition_matrix.get_row_group_end(row_group)):
  29. for entry in model.transition_matrix.get_row(row):
  30. if entry.value().constant_part() == 1:
  31. t2 += 1
  32. print(time.time() - start)
  33. print(t2)
  34. states_and_transitions = []
  35. for row_group in range(model.nr_states):
  36. states_and_transitions.append([])
  37. for row in range(model.transition_matrix.get_row_group_start(row_group), model.transition_matrix.get_row_group_end(row_group)):
  38. for entry in model.transition_matrix.get_row(row):
  39. states_and_transitions[-1].append((entry.value(), entry.column))
  40. t3 = 0
  41. start = time.time()
  42. for s in states_and_transitions:
  43. for (v,c) in s:
  44. if v.constant_part() == 1:
  45. t3 += 1
  46. print(time.time() - start)
  47. print(t3)
  48. if __name__ == '__main__':
  49. example_parametric_models_03()