test.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from modelverse import *
  2. import random
  3. def print_mv(value):
  4. print(value)
  5. return None
  6. print("Init")
  7. init()
  8. print("Login")
  9. #login(str(random.random()), str(random.random()))
  10. login("admin", "admin")
  11. # Add the metamodels for PetriNet and ReachabilityGraph
  12. print("Add metamodels")
  13. try:
  14. model_add("PetriNet", "SimpleClassDiagrams", open("models/petrinets.mvc").read())
  15. except ModelExists:
  16. pass
  17. try:
  18. model_add("ReachabilityGraph", "SimpleClassDiagrams", open("models/reachability_graph.mvc").read())
  19. except ModelExists:
  20. pass
  21. print("Add model")
  22. try:
  23. model_add("my_pn", "PetriNet", open("models/my_pn.mvc").read())
  24. except ModelExists:
  25. pass
  26. # Add the action language code to transform between them
  27. print("Add AL model")
  28. try:
  29. transformation_add_AL(["PetriNet"], ["ReachabilityGraph"], "analyseReachability", open("models/reachability.alc", "r").read())
  30. except ModelExists:
  31. pass
  32. # Add an example model transformation to print the reachability graph
  33. print("Add MT model")
  34. try:
  35. transformation_add_MT_language(["ReachabilityGraph"], "RAMified_ReachabilityGraph")
  36. except ModelExists:
  37. pass
  38. try:
  39. transformation_add_MT("RAMified_ReachabilityGraph", ["ReachabilityGraph"], [], "printReachability", open("models/reachabilitygraph_print.mvc").read())
  40. except ModelExists:
  41. pass
  42. # Do the reachability graph generation
  43. print("Execute AL")
  44. status = transformation_execute_AL("analyseReachability", {"PetriNet": "my_pn"}, {"ReachabilityGraph": "my_reachability"}, callback=print_mv)
  45. print("Reachability generation success: " + str(status))
  46. print("Execute MT")
  47. status = transformation_execute_MT("printReachability", {"ReachabilityGraph": "my_reachability"}, {}, callback=print_mv)
  48. print("Reachability printing success: " + str(status))