metamodels.alc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_link(pn, "Association", "P2T_weight", "P2T", "Integer")
  71. instantiate_attribute(pn, "P2T_weight", "name", "weight")
  72. instantiate_link(pn, "Association", "T2P_weight", "T2P", "Integer")
  73. instantiate_attribute(pn, "T2P_weight", "name", "weight")
  74. set_model_constraints(pn, petrinet_constraints)
  75. export_node("models/PetriNets", pn)
  76. Element ltm_bottom
  77. ltm_bottom = instantiate_bottom()
  78. model_add_node(ltm_bottom, "Node")
  79. model_add_edge(ltm_bottom, "Edge", "Node", "Node")
  80. model_add_edge(ltm_bottom, "inheritance", "Node", "Node")
  81. model_add_edge(ltm_bottom, "__inh", "Edge", "Node")
  82. retype_model(ltm_bottom, ltm_bottom)
  83. define_inheritance(ltm_bottom, "inheritance")
  84. retype(ltm_bottom, "Node", "Node")
  85. retype(ltm_bottom, "Edge", "Edge")
  86. retype(ltm_bottom, "inheritance", "Edge")
  87. retype(ltm_bottom, "__inh", "inheritance")
  88. export_node("models/LTM_bottom", ltm_bottom)
  89. return dict_read(dict_read(read_root(), "__hierarchy"), "models")
  90. String function petrinet_constraints(model : Element):
  91. // Check places to have positive number of tokens
  92. Element all_elems
  93. Element elem_constraint
  94. all_elems = allInstances(model, model["metamodel"]["model"]["Place"])
  95. while (0 < read_nr_out(all_elems)):
  96. elem_constraint = set_pop(all_elems)
  97. if (integer_lt(read_attribute(model, getName(model, elem_constraint), "tokens"), 0)):
  98. return "Negative number of tokens in Place " + getName(model, elem_constraint)
  99. // Check P2T transitions to have positive weight
  100. all_elems = allInstances(model, model["metamodel"]["model"]["P2T"])
  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), "weight"), 0)):
  104. return "Negative weight in arc " + getName(model, elem_constraint)
  105. // Check T2P transitions to have positive weight
  106. all_elems = allInstances(model, model["metamodel"]["model"]["T2P"])
  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. return "OK"