metamodels.alc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. model_add_value(scd, "lower_multiplicity", "lower_multiplicity")
  28. model_add_value(scd, "upper_multiplicity", "upper_multiplicity")
  29. model_add_edge(scd, "class_to_lm", "Class", "Integer")
  30. model_add_edge(scd, "class_to_um", "Class", "Integer")
  31. model_add_edge(scd, "lm_name", "class_to_lm", "lower_multiplicity")
  32. model_add_edge(scd, "um_name", "class_to_um", "upper_multiplicity")
  33. retype_model(scd, scd)
  34. define_inheritance(scd, "Inheritance")
  35. retype(scd, "Class", "Class")
  36. retype(scd, "Type", "Class")
  37. retype(scd, "Any", "Class")
  38. retype(scd, "String", "Type")
  39. retype(scd, "inheritance", "String")
  40. retype(scd, "link", "String")
  41. retype(scd, "name", "String")
  42. retype(scd, "class_inherits_any", "Inheritance")
  43. retype(scd, "type_inherits_any", "Inheritance")
  44. retype(scd, "Inheritance", "Association")
  45. retype(scd, "inheritance_name", "association_attr")
  46. retype(scd, "Association", "Association")
  47. retype(scd, "assoc_inherits_any", "Inheritance")
  48. retype(scd, "association_name", "association_attr")
  49. retype(scd, "association_attr", "Association")
  50. retype(scd, "attr_name", "association_attr")
  51. retype(scd, "Integer", "Type")
  52. retype(scd, "lower_multiplicity", "String")
  53. retype(scd, "upper_multiplicity", "String")
  54. retype(scd, "class_to_lm", "Association")
  55. retype(scd, "class_to_um", "Association")
  56. retype(scd, "lm_name", "association_attr")
  57. retype(scd, "um_name", "association_attr")
  58. export_node("models/SimpleClassDiagrams", scd)
  59. Element pn
  60. pn = instantiate_model(scd)
  61. define_inheritance(pn, "Inheritance")
  62. instantiate_node(pn, "Class", "Place")
  63. instantiate_node(pn, "Class", "Transition")
  64. instantiate_node(pn, "Type", "Integer")
  65. instantiate_link(pn, "Association", "P2T", "Place", "Transition")
  66. instantiate_link(pn, "Association", "T2P", "Transition", "Place")
  67. instantiate_named(pn, "Association", "tokens", "Place", "Integer")
  68. instantiate_named(pn, "Association", "weight", "P2T", "Integer")
  69. instantiate_named(pn, "Association", "weight", "T2P", "Integer")
  70. set_model_constraints(pn, petrinet_constraints)
  71. export_node("models/PetriNets", pn)
  72. Element ltm_bottom
  73. ltm_bottom = instantiate_bottom()
  74. model_add_node(ltm_bottom, "Node")
  75. model_add_edge(ltm_bottom, "Edge", "Node", "Node")
  76. model_add_edge(ltm_bottom, "inheritance", "Node", "Node")
  77. model_add_edge(ltm_bottom, "__inh", "Edge", "Node")
  78. retype_model(ltm_bottom, ltm_bottom)
  79. define_inheritance(ltm_bottom, "inheritance")
  80. retype(ltm_bottom, "Node", "Node")
  81. retype(ltm_bottom, "Edge", "Edge")
  82. retype(ltm_bottom, "inheritance", "Edge")
  83. retype(ltm_bottom, "__inh", "inheritance")
  84. export_node("models/LTM_bottom", ltm_bottom)
  85. return dict_read(dict_read(read_root(), "__hierarchy"), "models")
  86. String function petrinet_constraints(model : Element):
  87. // Check places to have positive number of tokens
  88. Element all_elems
  89. Element elem_constraint
  90. all_elems = allInstances(model, model["metamodel"]["model"]["Place"])
  91. while (0 < read_nr_out(all_elems)):
  92. elem_constraint = set_pop(all_elems)
  93. if (integer_lt(read_attribute(model, getName(model, elem_constraint), "tokens"), 0)):
  94. return "Negative number of tokens in Place " + getName(model, elem_constraint)
  95. // Check P2T transitions to have positive weight
  96. all_elems = allInstances(model, model["metamodel"]["model"]["P2T"])
  97. while (0 < read_nr_out(all_elems)):
  98. elem_constraint = set_pop(all_elems)
  99. if (integer_lt(read_attribute(model, getName(model, elem_constraint), "weight"), 0)):
  100. return "Negative weight in arc " + getName(model, elem_constraint)
  101. // Check T2P transitions to have positive weight
  102. all_elems = allInstances(model, model["metamodel"]["model"]["T2P"])
  103. while (0 < read_nr_out(all_elems)):
  104. elem_constraint = set_pop(all_elems)
  105. if (integer_lt(read_attribute(model, getName(model, elem_constraint), "weight"), 0)):
  106. return "Negative weight in arc " + getName(model, elem_constraint)
  107. return "OK"