test.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. from modelverse import *
  2. import random
  3. def print_mv_with_input(value):
  4. if value.startswith("#"):
  5. print_mv(value[1:])
  6. return
  7. if value.startswith("%"):
  8. if (value[1:] == "construct_function"):
  9. print("Enter your code...")
  10. code = \
  11. """
  12. include "primitives.alh"
  13. Boolean function bp_1():
  14. log("Breakpoint check!")
  15. return True!
  16. """
  17. upload_code(code)
  18. return
  19. print(value)
  20. return raw_input()
  21. def print_mv(value):
  22. print(value)
  23. return None
  24. print("Init")
  25. init()
  26. print("Login")
  27. #login(str(random.random()), str(random.random()))
  28. login("admin", "admin")
  29. # Add the metamodels for PetriNet and ReachabilityGraph
  30. print("Add metamodels")
  31. try:
  32. model_add("PetriNet", "SimpleClassDiagrams", open("models/petrinets.mvc").read())
  33. except ModelExists:
  34. pass
  35. try:
  36. model_add("ReachabilityGraph", "SimpleClassDiagrams", open("models/reachability_graph.mvc").read())
  37. except ModelExists:
  38. pass
  39. print("Add model")
  40. try:
  41. model_add("my_pn", "PetriNet", open("models/my_pn.mvc").read())
  42. except ModelExists:
  43. pass
  44. # Add the action language code to transform between them
  45. print("Add AL model")
  46. try:
  47. transformation_add_AL({"PetriNet": "PetriNet"}, {"ReachabilityGraph": "ReachabilityGraph"}, "analyseReachability", open("models/reachability.alc", "r").read())
  48. except ModelExists:
  49. pass
  50. # Add an example model transformation to print the reachability graph
  51. print("Add MT model")
  52. try:
  53. transformation_add_MT({"ReachabilityGraph": "ReachabilityGraph"}, {}, "printReachability", open("models/reachabilitygraph_print.mvc").read())
  54. except ModelExists:
  55. pass
  56. # Do the reachability graph generation
  57. print("Execute AL")
  58. status = transformation_execute_AL("analyseReachability", {"PetriNet": "my_pn"}, {"ReachabilityGraph": "my_reachability"}, callback=print_mv)
  59. print("Reachability generation success: " + str(status))
  60. print("Execute MT")
  61. status = transformation_execute_MT("printReachability", {"ReachabilityGraph": "my_reachability"}, {}, callback=print_mv)
  62. print("Reachability printing success: " + str(status))