transform.alc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. Element function make_matching_schedule(LHS_model : Element):
  2. Element schedule
  3. Element workset
  4. Element all_elements
  5. Integer required_size
  6. String new_element
  7. Element tmp
  8. schedule = create_node()
  9. workset = create_node()
  10. all_elements = allInstances(LHS_model, "Pre_Element")
  11. //TODO is this completely true?
  12. // Calculate the size of the final match
  13. required_size = read_nr_out(all_elements)
  14. while (read_nr_out(schedule) < required_size):
  15. // Need to keep adding to the schedule
  16. // workset is empty, but we still need to add to the list
  17. // Therefore, we pick a random, unbound node, and add it to the workset
  18. new_element = set_pop(all_elements)
  19. while (bool_or(set_in(schedule, new_element), (is_edge(LHS_model["model"][new_element]))):
  20. new_element = set_pop(all_elements)
  21. set_add(workset, new_element)
  22. while (read_nr_out(workset) > 0):
  23. // Still elements in the workset, so pop from these first
  24. next = set_pop(workset)
  25. if (bool_not(set_in(schedule, next))):
  26. list_append(schedule, next)
  27. if (is_edge(next)):
  28. // Add the target/source to the schedule
  29. if (bool_not(set_in(schedule, read_edge_src(next)))):
  30. // Add source
  31. set_add(workset, read_edge_src(next))
  32. if (bool_not(set_in(schedule, read_edge_dst(next)))):
  33. // Add destination
  34. set_add(workset, read_edge_dst(next))
  35. // Also add all outgoing and incoming elements
  36. tmp = allOutgoingAssociations(next)
  37. while (read_nr_out(tmp) > 0):
  38. set_add(workset, set_pop(tmp))
  39. tmp = allIncomingAssociations(next)
  40. while (read_nr_out(tmp) > 0):
  41. set_add(workset, set_pop(tmp))
  42. return schedule