DEVS_merge.alc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. include "primitives.alh"
  2. include "object_operations.alh"
  3. include "modelling.alh"
  4. Boolean function main(model : Element):
  5. // Find all source elements and add them to the target element
  6. // We actually only have to change the type of each element and rename a bit!
  7. // Model merge operations in the Modelverse take care of the rest automatically
  8. Element all_elements
  9. Element split
  10. String key
  11. String new_key
  12. String type
  13. all_elements = dict_keys(model["model"])
  14. while (set_len(all_elements) > 0):
  15. key = set_pop(all_elements)
  16. // key now contains an element, which we must retype
  17. split = string_split(key, "/")
  18. if (list_len(split) > 1):
  19. new_key = list_read(split, 1)
  20. dict_add(model["model"], new_key, model["model"][key])
  21. dict_delete(model["model"], key)
  22. key = new_key
  23. type = read_type(model, key)
  24. split = string_split(type, "/")
  25. // Got the type, which might contain a /
  26. if (list_len(split) > 1):
  27. type = list_read(split, 1)
  28. // Strip of the part before the / and make it into "DEVS"
  29. retype(model, key, "result/" + type)
  30. return True!