metamodels.alc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. return dict_read(dict_read(read_root(), "__hierarchy"), "models")
  72. String function petrinet_constraints(model : Element):
  73. // Check places to have positive number of tokens
  74. Element all_elems
  75. Element elem_constraint
  76. all_elems = allInstances(model, model["metamodel"]["model"]["Place"])
  77. while (0 < read_nr_out(all_elems)):
  78. elem_constraint = set_pop(all_elems)
  79. if (integer_lt(readAttribute(model, elem_constraint, "tokens"), 0)):
  80. return "Negative number of tokens in Place " + getName(model, elem_constraint)
  81. // Check P2T transitions to have positive weight
  82. all_elems = allInstances(model, model["metamodel"]["model"]["P2T"])
  83. while (0 < read_nr_out(all_elems)):
  84. elem_constraint = set_pop(all_elems)
  85. if (integer_lt(readAttribute(model, elem_constraint, "weight"), 0)):
  86. return "Negative weight in arc " + getName(model, elem_constraint)
  87. // Check T2P transitions to have positive weight
  88. all_elems = allInstances(model, model["metamodel"]["model"]["T2P"])
  89. while (0 < read_nr_out(all_elems)):
  90. elem_constraint = set_pop(all_elems)
  91. if (integer_lt(readAttribute(model, elem_constraint, "weight"), 0)):
  92. return "Negative weight in arc " + getName(model, elem_constraint)
  93. return "OK"