transform.alc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. log("Fetching all instances")
  16. all_elements = allInstances(LHS_model, "Pre_Element")
  17. log("Got all instances")
  18. required_size = read_nr_out(all_elements)
  19. // Need to keep adding to the schedule
  20. while (read_nr_out(schedule) < required_size):
  21. // workset is empty, but we still need to add to the list
  22. // Therefore, we pick a random, unbound node, and add it to the workset
  23. new_element = set_pop(all_elements)
  24. while (bool_or(set_in(schedule, new_element), is_edge(LHS_model["model"][new_element]))):
  25. // Element is not usable, so pick another one
  26. new_element = set_pop(all_elements)
  27. set_add(workset, new_element)
  28. // Handle the workset
  29. while (read_nr_out(workset) > 0):
  30. // Still elements in the workset, so pop from these first
  31. next = set_pop(workset)
  32. // Check if element might not be already used somewhere
  33. if (bool_not(set_in(schedule, next))):
  34. list_append(schedule, next)
  35. // If it is an edge, we should also add the target and source
  36. if (is_edge(LHS_model["model"][next])):
  37. // Add the target/source to the schedule
  38. set_add(workset, read_edge_src(LHS_model["model"][next]))
  39. set_add(workset, read_edge_dst(LHS_model["model"][next]))
  40. // Also add all outgoing links
  41. counter = read_nr_out(LHS_model["model"][next])
  42. while (counter > 0):
  43. counter = counter - 1
  44. if (set_in_node(LHS_model["model"], read_out(LHS_model["model"][next], counter))):
  45. set_add(workset, reverseKeyLookup(LHS_model["model"], read_out(LHS_model["model"][next], counter)))
  46. return schedule!
  47. Void function transform(host_model : Element, LHS_model : Element, RHS_model : Element):
  48. Element schedule
  49. schedule = make_matching_schedule(LHS_model)
  50. output("Got schedule")
  51. while (read_nr_out(schedule) > 0):
  52. output(list_pop(schedule, 0))
  53. return!