fsa_simulate.alc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. include "primitives.alh"
  2. include "modelling.alh"
  3. include "object_operations.alh"
  4. include "conformance_scd.alh"
  5. include "io.alh"
  6. include "metamodels.alh"
  7. include "mini_modify.alh"
  8. Boolean function main(model : Element):
  9. String input_value
  10. Float start_time
  11. String current_state
  12. String old_state
  13. Element transitions
  14. String transition
  15. start_time = time()
  16. Element all_states
  17. String element_name
  18. all_states = allInstances(model, "FullRuntime/State")
  19. while (set_len(all_states) > 0):
  20. element_name = set_pop(all_states)
  21. log("Check " + cast_value(read_attribute(model, element_name, "name")))
  22. log(" Current: " + cast_value(read_attribute(model, element_name, "current")))
  23. if (value_eq(read_attribute(model, element_name, "current"), True)):
  24. log("Found current: " + cast_value(read_attribute(model, element_name, "current")))
  25. current_state = element_name
  26. old_state = element_name
  27. break!
  28. while (True):
  29. if (has_input()):
  30. input_value = input()
  31. if (input_value == "__EXIT__"):
  32. break!
  33. transitions = allOutgoingAssociationInstances(model, current_state, "FullRuntime/Transition")
  34. while (set_len(transitions) > 0):
  35. transition = set_pop(transitions)
  36. if (cast_string(read_attribute(model, transition, "trigger")) == input_value):
  37. if (element_neq(read_attribute(model, transition, "raise"), read_root())):
  38. log(cast_value(time() - start_time) + " ! " + cast_string(read_attribute(model, transition, "raise")))
  39. output(cast_value(time() - start_time) + " ! " + cast_string(read_attribute(model, transition, "raise")))
  40. current_state = readAssociationDestination(model, transition)
  41. break!
  42. log(cast_value(time() - start_time) + " : " + cast_string(read_attribute(model, current_state, "name")))
  43. output(cast_value(time() - start_time) + " : " + cast_string(read_attribute(model, current_state, "name")))
  44. sleep(0.2)
  45. log("CLOSE")
  46. output("CLOSE")
  47. instantiate_attribute(model, current_state, "current", True)
  48. instantiate_attribute(model, old_state, "current", True)
  49. return True!