metamodels.alc 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. include "primitives.alh"
  2. include "object_operations.alh"
  3. include "library.alh"
  4. include "conformance_scd.alh"
  5. include "modelling.alh"
  6. Element function create_metamodels():
  7. if (bool_not(dict_in(dict_read(read_root(), "__hierarchy"), "models"))):
  8. Element scd
  9. scd = instantiate_bottom()
  10. model_add_node(scd, "Class")
  11. model_add_node(scd, "Type")
  12. model_add_node(scd, "Any")
  13. model_add_node(scd, "String")
  14. model_add_value(scd, "inheritance", "inheritance")
  15. model_add_value(scd, "link", "link")
  16. model_add_value(scd, "name", "name")
  17. model_add_edge(scd, "l1", "Class", "Any")
  18. model_add_edge(scd, "l2", "Type", "Any")
  19. model_add_edge(scd, "l3", "Any", "Any")
  20. model_add_edge(scd, "l4", "l3", "inheritance")
  21. model_add_edge(scd, "l5", "Any", "Any")
  22. model_add_edge(scd, "l6", "l5", "Any")
  23. model_add_edge(scd, "l7", "l5", "link")
  24. model_add_edge(scd, "l8", "l5", "String")
  25. model_add_edge(scd, "l9", "l8", "name")
  26. retype_model(scd, scd)
  27. define_inheritance(scd, "l3")
  28. retype(scd, "Class", "Class")
  29. retype(scd, "Type", "Class")
  30. retype(scd, "Any", "Class")
  31. retype(scd, "String", "Type")
  32. retype(scd, "inheritance", "String")
  33. retype(scd, "link", "String")
  34. retype(scd, "name", "String")
  35. retype(scd, "l1", "l3")
  36. retype(scd, "l2", "l3")
  37. retype(scd, "l3", "l5")
  38. retype(scd, "l4", "l8")
  39. retype(scd, "l5", "l5")
  40. retype(scd, "l6", "l3")
  41. retype(scd, "l7", "l8")
  42. retype(scd, "l8", "l5")
  43. retype(scd, "l9", "l8")
  44. export_node("models/SimpleClassDiagrams", scd)
  45. Element pn
  46. pn = instantiate_model(scd)
  47. define_inheritance(pn, "l3")
  48. instantiate_node(pn, "Class", "Place")
  49. instantiate_node(pn, "Class", "Transition")
  50. instantiate_node(pn, "Type", "Integer")
  51. instantiate_link(pn, "l5", "P2T", "Place", "Transition")
  52. instantiate_link(pn, "l5", "T2P", "Transition", "Place")
  53. instantiate_named(pn, "l5", "tokens", "Place", "Integer")
  54. instantiate_named(pn, "l5", "weight", "P2T", "Integer")
  55. instantiate_named(pn, "l5", "weight", "T2P", "Integer")
  56. set_model_constraints(pn, petrinet_constraints)
  57. export_node("models/PetriNets", pn)
  58. Element ltm_bottom
  59. ltm_bottom = instantiate_bottom()
  60. model_add_node(ltm_bottom, "Node")
  61. model_add_edge(ltm_bottom, "Edge", "Node", "Node")
  62. model_add_edge(ltm_bottom, "inheritance", "Node", "Node")
  63. model_add_edge(ltm_bottom, "__inh", "Edge", "Node")
  64. retype_model(ltm_bottom, ltm_bottom)
  65. define_inheritance(ltm_bottom, "inheritance")
  66. retype(ltm_bottom, "Node", "Node")
  67. retype(ltm_bottom, "Edge", "Edge")
  68. retype(ltm_bottom, "inheritance", "Edge")
  69. retype(ltm_bottom, "__inh", "inheritance")
  70. export_node("models/LTM_bottom", ltm_bottom)
  71. ////////////////////////////////////////////////////////////////////////////
  72. // create PETRINET transformation metamodel
  73. ////////////////////////////////////////////////////////////////////////////
  74. //////////////////
  75. // Constant part (this is what every transformation_metamodel will need)
  76. Element transform_metamodel
  77. transform_metamodel = instantiate_model(scd)
  78. define_inheritance(transform_metamodel, "inheritance")
  79. //create Transformation node with name attribute
  80. instantiate_node(transform_metamodel, "Class", "Transformation")
  81. instantiate_node(transform_metamodel, "Type", "String")
  82. instantiate_named(transform_metamodel, "l5", "name", "Transformation", "String")
  83. //create Rule node with name attribute and precedence attribute (precedence will later be replaced by explicit modelled order)
  84. instantiate_node(transform_metamodel, "Class", "Rule")
  85. instantiate_named(transform_metamodel, "l5", "name", "Rule", "String")
  86. instantiate_node(transform_metamodel, "Type", "Integer")
  87. instantiate_named(transform_metamodel, "l5", "precedence", "Rule", "Integer")
  88. //create edge between transformation and rule
  89. instantiate_link(transform_metamodel, "l5", "transformation_to_rule", "Transformation", "Rule")
  90. //create precondition pattern with condition (condition is a python string of code that should be executed)
  91. instantiate_node(transform_metamodel, "Class", "Precondition")
  92. instantiate_named(transform_metamodel, "l5", "condition", "Precondition", "String")
  93. //create LHS edge between rule and preconditionpattern
  94. instantiate_link(transform_metamodel, "l5", "lhs", "Rule", "Precondition")
  95. //create NAC edge between rule and preconditionpattern
  96. instantiate_link(transform_metamodel, "l5", "nac", "Rule", "Precondition")
  97. //create postcondition pattern with actions code (code is a python string of code that should be executed)
  98. instantiate_node(transform_metamodel, "Class", "Postcondition")
  99. instantiate_named(transform_metamodel, "l5", "code", "Postcondition", "String")
  100. //create RHS edge between pattern and postcondition
  101. instantiate_link(transform_metamodel, "l5", "rhs", "Rule", "Postcondition")
  102. //general lefthandside node (contains plabel for example)
  103. instantiate_node(transform_metamodel, "Class", "RAMgeneral")
  104. instantiate_named(transform_metamodel, "l5", "plabel", "RAMgeneral", "Integer")
  105. instantiate_named(transform_metamodel, "l5", "function", "RAMgeneral", "String")
  106. instantiate_named(transform_metamodel, "l5", "pivotIn", "RAMgeneral", "String")
  107. instantiate_named(transform_metamodel, "l5", "pivotOut", "RAMgeneral", "String")
  108. //connect RAMgeneral to precondition
  109. instantiate_link(transform_metamodel, "l5", "pre2ram", "Precondition","RAMgeneral")
  110. //connect RAMgeneral to postcondition
  111. instantiate_link(transform_metamodel, "l5", "post2ram", "Postcondition", "RAMgeneral")
  112. //////////////////
  113. // Variable part (this is were relaxed metamodels will be inserted )
  114. // for the moment this means that we:
  115. // 1) copy the metamodel (without attributes)
  116. // 2) Relaxation: ignore the constraints by simply not copying them (we will later on make a distinction in constraints that should or should not be respected)
  117. // 3) Augmentation: insert for every element the plabel (now implemented by inheritance)
  118. // 4) Modification: change attributes to string, so that python code can be inserted (later on, change to action code)
  119. // We have a difference in LHS and RHS, as LHS will have boolean functions at attribute-level and RHS will have functions that return values for the new attributes
  120. // As everything is executed in python code for now, there will no visible difference here except for the names.
  121. // Later on, one might add constraints that check the return value
  122. //RAMified petrinet for left hand side
  123. //place with tokens
  124. instantiate_node(transform_metamodel, "Class", "Place_LHS")
  125. //transition
  126. instantiate_node(transform_metamodel, "Class", "Transition_LHS")
  127. //P2T with weight
  128. instantiate_link(transform_metamodel, "l5", "P2T_LHS", "Place_LHS","Transition_LHS")
  129. //T2P with weight
  130. instantiate_link(transform_metamodel, "l5", "T2P_LHS", "Transition_LHS","Place_LHS")
  131. //inheritance links
  132. instantiate_link(transform_metamodel, "inheritance", "Place_LHS_is_RAM", "Place_LHS","RAMgeneral")
  133. instantiate_link(transform_metamodel, "inheritance", "Transition_LHS_is_RAM", "Transition_LHS","RAMgeneral")
  134. instantiate_link(transform_metamodel, "inheritance", "P2T_LHS_is_RAM", "P2T_LHS","RAMgeneral")
  135. instantiate_link(transform_metamodel, "inheritance", "T2P_LHS_is_RAM", "T2P_LHS","RAMgeneral")
  136. //RAMified petrinet for RIGHT hand side
  137. instantiate_node(transform_metamodel, "Class", "Place_RHS")
  138. instantiate_node(transform_metamodel, "Class", "Transition_RHS")
  139. instantiate_link(transform_metamodel, "l5", "P2T_RHS", "Place_RHS","Transition_RHS")
  140. instantiate_link(transform_metamodel, "l5", "T2P_RHS", "Transition_RHS","Place_RHS")
  141. //inheritance links
  142. instantiate_link(transform_metamodel, "inheritance", "Place_RHS_is_RAM", "Place_RHS","RAMgeneral")
  143. instantiate_link(transform_metamodel, "inheritance", "Transition_RHS_is_RAM", "Transition_RHS","RAMgeneral")
  144. instantiate_link(transform_metamodel, "inheritance", "P2T_RHS_is_RAM", "P2T_RHS","RAMgeneral")
  145. instantiate_link(transform_metamodel, "inheritance", "T2P_RHS_is_RAM", "T2P_RHS","RAMgeneral")
  146. export_node("models/PetriNets_MTransformation", transform_metamodel)
  147. return dict_read(dict_read(read_root(), "__hierarchy"), "models")
  148. String function petrinet_constraints(model : Element):
  149. // Check places to have positive number of tokens
  150. Element all_elems
  151. Element elem_constraint
  152. all_elems = allInstances(model, model["metamodel"]["model"]["Place"])
  153. while (0 < read_nr_out(all_elems)):
  154. elem_constraint = set_pop(all_elems)
  155. if (integer_lt(read_attribute(model, getName(model, elem_constraint), "tokens"), 0)):
  156. return "Negative number of tokens in Place " + getName(model, elem_constraint)
  157. // Check P2T transitions to have positive weight
  158. all_elems = allInstances(model, model["metamodel"]["model"]["P2T"])
  159. while (0 < read_nr_out(all_elems)):
  160. elem_constraint = set_pop(all_elems)
  161. if (integer_lt(read_attribute(model, getName(model, elem_constraint), "weight"), 0)):
  162. return "Negative weight in arc " + getName(model, elem_constraint)
  163. // Check T2P transitions to have positive weight
  164. all_elems = allInstances(model, model["metamodel"]["model"]["T2P"])
  165. while (0 < read_nr_out(all_elems)):
  166. elem_constraint = set_pop(all_elems)
  167. if (integer_lt(read_attribute(model, getName(model, elem_constraint), "weight"), 0)):
  168. return "Negative weight in arc " + getName(model, elem_constraint)
  169. return "OK"