bfs.alc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. include "primitives.alh"
  2. include "modelling.alh"
  3. include "object_operations.alh"
  4. Element function bfs(params : Element, output_mms : Element):
  5. Element model
  6. String initial
  7. Element options
  8. Element worklist
  9. String state
  10. Element path
  11. Element path_copy
  12. String option
  13. model = params["reachability"]
  14. worklist = create_node()
  15. initial = set_pop(allInstances(model, "InitialState"))
  16. list_append(worklist, create_tuple(initial, create_node()))
  17. while (read_nr_out(worklist) > 0):
  18. work_unit = list_pop(worklist, 0)
  19. state = work_unit[0]
  20. path = work_unit[1]
  21. log("Searching for length " + cast_v2s(read_nr_out(path)))
  22. if (value_eq(read_attribute(model, state, "error"), True)):
  23. // Found an error path!
  24. log("Found error path!")
  25. log(list_to_string(path))
  26. output("Found error path:")
  27. output(list_to_string(path))
  28. break!
  29. options = allOutgoingAssociationInstances(model, state, "Transition")
  30. while (read_nr_out(options) > 0):
  31. option = set_pop(options)
  32. path_copy = list_copy(path)
  33. list_append(path_copy, read_attribute(model, option, "name"))
  34. list_append(worklist, create_tuple(readAssociationDestination(model, option), path_copy))
  35. return create_node()!