bfs.alc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. Element work_unit
  10. String state
  11. Element path
  12. Element path_copy
  13. String option
  14. model = params["reachability_graph"]
  15. worklist = create_node()
  16. initial = set_pop(allInstances(model, "InitialState"))
  17. list_append(worklist, create_tuple(initial, create_node()))
  18. while (read_nr_out(worklist) > 0):
  19. work_unit = list_pop(worklist, 0)
  20. state = work_unit[0]
  21. path = work_unit[1]
  22. log("Searching for length " + cast_v2s(read_nr_out(path)))
  23. if (value_eq(read_attribute(model, state, "error"), True)):
  24. // Found an error path!
  25. log("Found error path!")
  26. log(list_to_string(path))
  27. output("Found error path:")
  28. output(list_to_string(path))
  29. break!
  30. options = allOutgoingAssociationInstances(model, state, "Transition")
  31. while (read_nr_out(options) > 0):
  32. option = set_pop(options)
  33. path_copy = dict_copy(path)
  34. list_append(path_copy, read_attribute(model, option, "name"))
  35. list_append(worklist, create_tuple(readAssociationDestination(model, option), path_copy))
  36. return create_node()!