metamodels.alc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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, "class_inherits_any", "Class", "Any")
  18. model_add_edge(scd, "type_inherits_any", "Type", "Any")
  19. model_add_edge(scd, "Inheritance", "Any", "Any")
  20. model_add_edge(scd, "inheritance_name", "Inheritance", "inheritance")
  21. model_add_edge(scd, "Association", "Any", "Any")
  22. model_add_edge(scd, "assoc_inherits_any", "Association", "Any")
  23. model_add_edge(scd, "association_name", "Association", "link")
  24. model_add_edge(scd, "association_attr", "Association", "String")
  25. model_add_edge(scd, "attr_name", "association_attr", "name")
  26. model_add_node(scd, "Integer")
  27. retype_model(scd, scd)
  28. define_inheritance(scd, "Inheritance")
  29. retype(scd, "Class", "Class")
  30. retype(scd, "Type", "Class")
  31. retype(scd, "Any", "Class")
  32. retype(scd, "String", "Type")
  33. retype(scd, "inheritance", "String")
  34. retype(scd, "link", "String")
  35. retype(scd, "name", "String")
  36. retype(scd, "class_inherits_any", "Inheritance")
  37. retype(scd, "type_inherits_any", "Inheritance")
  38. retype(scd, "Inheritance", "Association")
  39. retype(scd, "inheritance_name", "association_attr")
  40. retype(scd, "Association", "Association")
  41. retype(scd, "assoc_inherits_any", "Inheritance")
  42. retype(scd, "association_name", "association_attr")
  43. retype(scd, "association_attr", "Association")
  44. retype(scd, "attr_name", "association_attr")
  45. retype(scd, "Integer", "Type")
  46. // Add some attributes "the nice way" now that everything is typed
  47. instantiate_link(scd, "Association", "lc", "Class", "Integer")
  48. instantiate_attribute(scd, "lc", "name", "lower_cardinality")
  49. instantiate_link(scd, "Association", "uc", "Class", "Integer")
  50. instantiate_attribute(scd, "uc", "name", "upper_cardinality")
  51. instantiate_link(scd, "Association", "slc", "Association", "Integer")
  52. instantiate_attribute(scd, "slc", "name", "source_lower_cardinality")
  53. instantiate_link(scd, "Association", "suc", "Association", "Integer")
  54. instantiate_attribute(scd, "suc", "name", "source_upper_cardinality")
  55. instantiate_link(scd, "Association", "tlc", "Association", "Integer")
  56. instantiate_attribute(scd, "tlc", "name", "target_lower_cardinality")
  57. instantiate_link(scd, "Association", "tuc", "Association", "Integer")
  58. instantiate_attribute(scd, "tuc", "name", "target_upper_cardinality")
  59. export_node("models/SimpleClassDiagrams", scd)
  60. Element pn
  61. pn = instantiate_model(scd)
  62. define_inheritance(pn, "Inheritance")
  63. instantiate_node(pn, "Class", "Place")
  64. instantiate_node(pn, "Class", "Transition")
  65. instantiate_node(pn, "Type", "Integer")
  66. instantiate_link(pn, "Association", "P2T", "Place", "Transition")
  67. instantiate_link(pn, "Association", "T2P", "Transition", "Place")
  68. instantiate_link(pn, "Association", "Place_tokens", "Place", "Integer")
  69. instantiate_attribute(pn, "Place_tokens", "name", "tokens")
  70. instantiate_attribute(pn, "Place_tokens", "target_lower_cardinality", 1)
  71. instantiate_attribute(pn, "Place_tokens", "target_upper_cardinality", 1)
  72. instantiate_link(pn, "Association", "P2T_weight", "P2T", "Integer")
  73. instantiate_attribute(pn, "P2T_weight", "name", "weight")
  74. instantiate_attribute(pn, "P2T_weight", "target_lower_cardinality", 1)
  75. instantiate_attribute(pn, "P2T_weight", "target_upper_cardinality", 1)
  76. instantiate_link(pn, "Association", "T2P_weight", "T2P", "Integer")
  77. instantiate_attribute(pn, "T2P_weight", "name", "weight")
  78. instantiate_attribute(pn, "T2P_weight", "target_lower_cardinality", 1)
  79. instantiate_attribute(pn, "T2P_weight", "target_upper_cardinality", 1)
  80. set_model_constraints(pn, petrinet_constraints)
  81. export_node("models/PetriNets", pn)
  82. Element ltm_bottom
  83. ltm_bottom = instantiate_bottom()
  84. model_add_node(ltm_bottom, "Node")
  85. model_add_edge(ltm_bottom, "Edge", "Node", "Node")
  86. model_add_edge(ltm_bottom, "inheritance", "Node", "Node")
  87. model_add_edge(ltm_bottom, "__inh", "Edge", "Node")
  88. retype_model(ltm_bottom, ltm_bottom)
  89. define_inheritance(ltm_bottom, "inheritance")
  90. retype(ltm_bottom, "Node", "Node")
  91. retype(ltm_bottom, "Edge", "Edge")
  92. retype(ltm_bottom, "inheritance", "Edge")
  93. retype(ltm_bottom, "__inh", "inheritance")
  94. export_node("models/LTM_bottom", ltm_bottom)
  95. return dict_read(dict_read(read_root(), "__hierarchy"), "models")
  96. String function petrinet_constraints(model : Element):
  97. // Check places to have positive number of tokens
  98. Element all_elems
  99. Element elem_constraint
  100. all_elems = allInstances(model, model["metamodel"]["model"]["Place"])
  101. while (0 < read_nr_out(all_elems)):
  102. elem_constraint = set_pop(all_elems)
  103. if (integer_lt(read_attribute(model, getName(model, elem_constraint), "tokens"), 0)):
  104. return "Negative number of tokens in Place " + getName(model, elem_constraint)
  105. // Check P2T transitions to have positive weight
  106. all_elems = allInstances(model, model["metamodel"]["model"]["P2T"])
  107. while (0 < read_nr_out(all_elems)):
  108. elem_constraint = set_pop(all_elems)
  109. if (integer_lt(read_attribute(model, getName(model, elem_constraint), "weight"), 0)):
  110. return "Negative weight in arc " + getName(model, elem_constraint)
  111. // Check T2P transitions to have positive weight
  112. all_elems = allInstances(model, model["metamodel"]["model"]["T2P"])
  113. while (0 < read_nr_out(all_elems)):
  114. elem_constraint = set_pop(all_elems)
  115. if (integer_lt(read_attribute(model, getName(model, elem_constraint), "weight"), 0)):
  116. return "Negative weight in arc " + getName(model, elem_constraint)
  117. return "OK"