ramify.alc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. include "primitives.alh"
  2. include "object_operations.alh"
  3. include "modelling.alh"
  4. include "metamodels.alh"
  5. include "model_management.alh"
  6. include "conformance_scd.alh"
  7. Element function ramify(model : Element):
  8. // Create new model structure
  9. Element new_model
  10. new_model = instantiate_model(model["metamodel"])
  11. // Get local variables for parts
  12. Element old_m
  13. Element new_m
  14. Element mm
  15. new_m = new_model["model"]
  16. old_m = model["model"]
  17. mm = new_model["metamodel"]["model"]
  18. // Add in some primitives
  19. instantiate_node(new_model, "SimpleAttribute", "Natural")
  20. instantiate_attribute(new_model, "Natural", "constraint", constraint_Natural)
  21. instantiate_node(new_model, "SimpleAttribute", "String")
  22. instantiate_attribute(new_model, "String", "constraint", constraint_String)
  23. instantiate_node(new_model, "SimpleAttribute", "Boolean")
  24. instantiate_attribute(new_model, "Boolean", "constraint", constraint_Boolean)
  25. instantiate_node(new_model, "SimpleAttribute", "Location")
  26. instantiate_attribute(new_model, "Location", "constraint", constraint_Location)
  27. instantiate_node(new_model, "ComplexAttribute", "ActionLanguage")
  28. instantiate_attribute(new_model, "ActionLanguage", "constraint", constraint_ActionLanguage)
  29. model_define_attribute(new_model, "ActionLanguage", "type", False, "Location")
  30. // Add some default elements
  31. // Class LHS_Root {
  32. // constraint? : ActionLanguage
  33. // upper_cardinality = 1
  34. // lower_cardinality = 1
  35. // }
  36. instantiate_node(new_model, "Class", "LHS_Root")
  37. instantiate_attribute(new_model, "LHS_Root", "lower_cardinality", 1)
  38. instantiate_attribute(new_model, "LHS_Root", "upper_cardinality", 1)
  39. model_define_attribute(new_model, "LHS_Root", "constraint", True, "ActionLanguage")
  40. // Class LHS : LHS_Root {}
  41. instantiate_node(new_model, "Class", "LHS")
  42. instantiate_link(new_model, "Inheritance", "", "LHS", "LHS_Root")
  43. // Class NAC : LHS_Root {}
  44. instantiate_node(new_model, "Class", "NAC")
  45. instantiate_link(new_model, "Inheritance", "", "NAC", "LHS_Root")
  46. // Class PreElement {
  47. // label : String
  48. // constraint? : ActionLanguage
  49. // }
  50. instantiate_node(new_model, "Class", "PreElement")
  51. model_define_attribute(new_model, "PreElement", "label", False, "String")
  52. model_define_attribute(new_model, "PreElement", "constraint", True, "ActionLanguage")
  53. // Association LHS_contains (LHS_Root, PreElement) {}
  54. instantiate_link(new_model, "Association", "LHS_contains", "LHS_Root", "PreElement")
  55. // Class RHS {
  56. // action? : ActionLanguage
  57. // upper_cardinality = 1
  58. // lower_cardinality = 1
  59. // }
  60. instantiate_node(new_model, "Class", "RHS")
  61. instantiate_attribute(new_model, "RHS", "lower_cardinality", 1)
  62. instantiate_attribute(new_model, "RHS", "upper_cardinality", 1)
  63. model_define_attribute(new_model, "RHS", "action", True, "ActionLanguage")
  64. // Class PostElement {
  65. // label : String
  66. // action? : ActionLanguage
  67. // }
  68. instantiate_node(new_model, "Class", "PostElement")
  69. model_define_attribute(new_model, "PostElement", "label", False, "String")
  70. model_define_attribute(new_model, "PostElement", "action", True, "ActionLanguage")
  71. // Association RHS_contains (RHS, PostElement) {}
  72. instantiate_link(new_model, "Association", "RHS_contains", "RHS", "PostElement")
  73. // Basics are added, now we need to add each node and transition, but slightly modified
  74. Element keys
  75. String key
  76. Element new_entry
  77. Element entry
  78. keys = set_to_list(dict_keys(old_m))
  79. String type_name
  80. String old_source
  81. String old_target
  82. String attr_name
  83. Element masked_attributes
  84. Element copied_attributes
  85. Element local_copied_attributes
  86. masked_attributes = set_create()
  87. set_add(masked_attributes, "constraint")
  88. set_add(masked_attributes, "lower_cardinality")
  89. set_add(masked_attributes, "source_lower_cardinality")
  90. set_add(masked_attributes, "target_lower_cardinality")
  91. copied_attributes = set_create()
  92. set_add(copied_attributes, "upper_cardinality")
  93. set_add(copied_attributes, "source_upper_cardinality")
  94. set_add(copied_attributes, "target_upper_cardinality")
  95. while (list_len(keys) > 0):
  96. key = list_pop(keys, 0)
  97. entry = old_m[key]
  98. type_name = read_type(model, key)
  99. if (type_name == "Class"):
  100. instantiate_node(new_model, type_name, "Pre_" + key)
  101. instantiate_node(new_model, type_name, "Post_" + key)
  102. // Also make it inherit from the "root element"
  103. instantiate_link(new_model, "Inheritance", "", "Pre_" + key, "PreElement")
  104. instantiate_link(new_model, "Inheritance", "", "Post_" + key, "PostElement")
  105. local_copied_attributes = set_copy(copied_attributes)
  106. while (set_len(local_copied_attributes) > 0):
  107. attr_name = set_pop(local_copied_attributes)
  108. if (element_neq(read_attribute(model, key, attr_name), read_root())):
  109. // Attribute was defined, so reassign in both LHS and RHS
  110. instantiate_attribute(new_model, "Pre_" + key, attr_name, read_attribute(model, key, attr_name))
  111. instantiate_attribute(new_model, "Post_" + key, attr_name, read_attribute(model, key, attr_name))
  112. elif (type_name == "AttributeLink"):
  113. // Got an attribute, so find out the source and name
  114. old_source = reverseKeyLookup(model["model"], read_edge_src(entry))
  115. attr_name = read_attribute(model, key, "name")
  116. // TODO distinguish between Simple and Complex Attributes
  117. if (dict_in(new_model["model"], "Pre_" + old_source)):
  118. // Only if it is a class that it originates from is a class, should we add this
  119. if (is_nominal_instance(model, old_source, "Element")):
  120. // If the attribute is one used in the conformance check, we should mask it
  121. // Add the attribute in the new model, altering its name and making it optional
  122. model_define_attribute(new_model, "Pre_" + old_source, "constraint_" + attr_name, True, "ActionLanguage")
  123. model_define_attribute(new_model, "Post_" + old_source, "value_" + attr_name, True, "ActionLanguage")
  124. else:
  125. // Queue for later
  126. list_append(keys, key)
  127. continue!
  128. elif (type_name == "Association"):
  129. old_source = reverseKeyLookup(model["model"], read_edge_src(entry))
  130. old_target = reverseKeyLookup(model["model"], read_edge_dst(entry))
  131. if (bool_and(dict_in(new_model["model"], "Pre_" + old_source), dict_in(new_model["model"], "Pre_" + old_target))):
  132. instantiate_link(new_model, type_name, "Pre_" + key, "Pre_" + old_source, "Pre_" + old_target)
  133. instantiate_link(new_model, type_name, "Post_" + key, "Post_" + old_source, "Post_" + old_target)
  134. // Make it inherit from the Root Element (PreElement or PostElement)
  135. instantiate_link(new_model, "Inheritance", "", "Pre_" + key, "PreElement")
  136. instantiate_link(new_model, "Inheritance", "", "Post_" + key, "PostElement")
  137. else:
  138. // Queue for later
  139. list_append(keys, key)
  140. continue!
  141. local_copied_attributes = set_copy(copied_attributes)
  142. while (set_len(local_copied_attributes) > 0):
  143. attr_name = set_pop(local_copied_attributes)
  144. if (element_neq(read_attribute(model, key, attr_name), read_root())):
  145. // Attribute was defined, so reassign in both LHS and RHS
  146. instantiate_attribute(new_model, "Pre_" + key, attr_name, read_attribute(model, key, attr_name))
  147. instantiate_attribute(new_model, "Post_" + key, attr_name, read_attribute(model, key, attr_name))
  148. elif (type_name == "Inheritance"):
  149. old_source = reverseKeyLookup(model["model"], read_edge_src(entry))
  150. old_target = reverseKeyLookup(model["model"], read_edge_dst(entry))
  151. if (bool_and(dict_in(new_model["model"], "Pre_" + old_source), dict_in(new_model["model"], "Pre_" + old_target))):
  152. instantiate_link(new_model, type_name, "Pre_" + key, "Pre_" + old_source, "Pre_" + old_target)
  153. instantiate_link(new_model, type_name, "Post_" + key, "Post_" + old_source, "Post_" + old_target)
  154. else:
  155. // Queue for later
  156. list_append(keys, key)
  157. continue!
  158. // Define schedule over these elements
  159. // Class Entry {}
  160. instantiate_node(new_model, "Class", "Entry")
  161. // Class Success : Entry {}
  162. instantiate_node(new_model, "Class", "Success")
  163. instantiate_link(new_model, "Inheritance", "", "Success", "Entry")
  164. // Class Failure : Entry {}
  165. instantiate_node(new_model, "Class", "Failure")
  166. instantiate_link(new_model, "Inheritance", "", "Failure", "Entry")
  167. // Class Rule : Entry {}
  168. instantiate_node(new_model, "Class", "Rule")
  169. instantiate_link(new_model, "Inheritance", "", "Rule", "Entry")
  170. // Association OnSuccess(Rule, Entry){
  171. // target_lower_cardinality = 1
  172. // target_upper_cardinality = 1
  173. // }
  174. instantiate_link(new_model, "Association", "OnSuccess", "Rule", "Entry")
  175. instantiate_attribute(new_model, "OnSuccess", "target_lower_cardinality", 1)
  176. instantiate_attribute(new_model, "OnSuccess", "target_upper_cardinality", 1)
  177. // Association OnFailure(Rule, Entry){
  178. // target_lower_cardinality = 1
  179. // target_upper_cardinality = 1
  180. // }
  181. instantiate_link(new_model, "Association", "OnFailure", "Rule", "Entry")
  182. instantiate_attribute(new_model, "OnFailure", "target_lower_cardinality", 1)
  183. instantiate_attribute(new_model, "OnFailure", "target_upper_cardinality", 1)
  184. // Class LHSRule : Rule {}
  185. instantiate_node(new_model, "Class", "LHSRule")
  186. instantiate_link(new_model, "Inheritance", "", "LHSRule", "Rule")
  187. // Association LHSLink (LHSRule, LHS) {
  188. // target_lower_cardinality = 1
  189. // target_upper_cardinality = 1
  190. // }
  191. instantiate_link(new_model, "Association", "LHSLink", "LHSRule", "LHS")
  192. instantiate_attribute(new_model, "LHSLink", "target_lower_cardinality", 1)
  193. instantiate_attribute(new_model, "LHSLink", "target_upper_cardinality", 1)
  194. // Association NACLink (LHSRule, NAC) {}
  195. instantiate_link(new_model, "Association", "NACLink", "LHSRule", "NAC")
  196. // Class RHSRule : Rule {}
  197. instantiate_node(new_model, "Class", "RHSRule")
  198. instantiate_link(new_model, "Inheritance", "", "RHSRule", "Rule")
  199. // Association RHSLink (RHSRule, RHS) {
  200. // target_lower_cardinality = 1
  201. // target_upper_cardinality = 1
  202. // }
  203. instantiate_link(new_model, "Association", "RHSLink", "RHSRule", "RHS")
  204. instantiate_attribute(new_model, "RHSLink", "target_lower_cardinality", 1)
  205. instantiate_attribute(new_model, "RHSLink", "target_upper_cardinality", 1)
  206. // Class Query : LHSRule {}
  207. instantiate_node(new_model, "Class", "Query")
  208. instantiate_link(new_model, "Inheritance", "", "Query", "LHSRule")
  209. // Class Atomic : LHSRule, RHSRule {}
  210. instantiate_node(new_model, "Class", "Atomic")
  211. instantiate_link(new_model, "Inheritance", "", "Atomic", "LHSRule")
  212. instantiate_link(new_model, "Inheritance", "", "Atomic", "RHSRule")
  213. // Class ForAll : LHSRule, RHSRule {}
  214. instantiate_node(new_model, "Class", "ForAll")
  215. instantiate_link(new_model, "Inheritance", "", "ForAll", "LHSRule")
  216. instantiate_link(new_model, "Inheritance", "", "ForAll", "RHSRule")
  217. // Class Composite : Rule {}
  218. instantiate_node(new_model, "Class", "Composite")
  219. instantiate_link(new_model, "Inheritance", "", "Composite", "Rule")
  220. // Association Initial(Composite, Entry){
  221. // target_lower_cardinality = 1
  222. // target_upper_cardinality = 1
  223. // }
  224. instantiate_link(new_model, "Association", "Initial", "Composite", "Entry")
  225. instantiate_attribute(new_model, "Initial", "target_lower_cardinality", 1)
  226. instantiate_attribute(new_model, "Initial", "target_upper_cardinality", 1)
  227. // Association Contains(Composite, Entry){
  228. // source_upper_cardinality = 1
  229. // target_lower_cardinality = 1
  230. // }
  231. instantiate_link(new_model, "Association", "Contains", "Composite", "Entry")
  232. instantiate_attribute(new_model, "Contains", "source_upper_cardinality", 1)
  233. instantiate_attribute(new_model, "Contains", "target_lower_cardinality", 1)
  234. return new_model!