transform.alc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. include "primitives.alh"
  2. include "object_operations.alh"
  3. include "modelling.alh"
  4. Element function make_matching_schedule(LHS_model : Element):
  5. Element schedule
  6. Element workset
  7. Element all_elements
  8. Integer required_size
  9. String new_element
  10. Integer counter
  11. String next
  12. // Initialize
  13. schedule = create_node()
  14. workset = create_node()
  15. all_elements = allInstances(LHS_model, "Pre_Element")
  16. required_size = read_nr_out(all_elements)
  17. // Need to keep adding to the schedule
  18. while (read_nr_out(schedule) < required_size):
  19. // workset is empty, but we still need to add to the list
  20. // Therefore, we pick a random, unbound node, and add it to the workset
  21. new_element = set_pop(all_elements)
  22. while (bool_or(set_in(schedule, new_element), is_edge(LHS_model["model"][new_element]))):
  23. // Element is not usable, so pick another one
  24. new_element = set_pop(all_elements)
  25. set_add(workset, new_element)
  26. // Handle the workset
  27. while (read_nr_out(workset) > 0):
  28. // Still elements in the workset, so pop from these first
  29. next = set_pop(workset)
  30. // Check if element might not be already used somewhere
  31. if (bool_not(set_in(schedule, next))):
  32. list_append(schedule, next)
  33. // If it is an edge, we should also add the target and source
  34. if (is_edge(LHS_model["model"][next])):
  35. // Add the target/source to the schedule
  36. set_add(workset, read_edge_src(LHS_model["model"][next]))
  37. set_add(workset, read_edge_dst(LHS_model["model"][next]))
  38. // Also add all outgoing links
  39. counter = read_nr_out(LHS_model["model"][next])
  40. while (counter > 0):
  41. counter = counter - 1
  42. if (set_in_node(LHS_model["model"], read_out(LHS_model["model"][next], counter))):
  43. set_add(workset, reverseKeyLookup(LHS_model["model"], read_out(LHS_model["model"][next], counter)))
  44. return schedule!