123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- include "primitives.alh"
- include "object_operations.alh"
- include "library.alh"
- include "conformance_scd.alh"
- include "modelling.alh"
- Element function create_metamodels():
- if (bool_not(dict_in(dict_read(read_root(), "__hierarchy"), "models"))):
- Element scd
- scd = instantiate_bottom()
- model_add_node(scd, "Class")
- model_add_node(scd, "Type")
- model_add_node(scd, "Any")
- model_add_node(scd, "String")
- model_add_value(scd, "inheritance", "inheritance")
- model_add_value(scd, "link", "link")
- model_add_value(scd, "name", "name")
- model_add_edge(scd, "class_inherits_any", "Class", "Any")
- model_add_edge(scd, "type_inherits_any", "Type", "Any")
- model_add_edge(scd, "Inheritance", "Any", "Any")
- model_add_edge(scd, "inheritance_name", "Inheritance", "inheritance")
- model_add_edge(scd, "Association", "Any", "Any")
- model_add_edge(scd, "assoc_inherits_any", "Association", "Any")
- model_add_edge(scd, "association_name", "Association", "link")
- model_add_edge(scd, "association_attr", "Association", "String")
- model_add_edge(scd, "attr_name", "association_attr", "name")
- model_add_node(scd, "Integer")
- retype_model(scd, scd)
- define_inheritance(scd, "Inheritance")
- retype(scd, "Class", "Class")
- retype(scd, "Type", "Class")
- retype(scd, "Any", "Class")
- retype(scd, "String", "Type")
- retype(scd, "inheritance", "String")
- retype(scd, "link", "String")
- retype(scd, "name", "String")
- retype(scd, "class_inherits_any", "Inheritance")
- retype(scd, "type_inherits_any", "Inheritance")
- retype(scd, "Inheritance", "Association")
- retype(scd, "inheritance_name", "association_attr")
- retype(scd, "Association", "Association")
- retype(scd, "assoc_inherits_any", "Inheritance")
- retype(scd, "association_name", "association_attr")
- retype(scd, "association_attr", "Association")
- retype(scd, "attr_name", "association_attr")
- retype(scd, "Integer", "Type")
- // Add some attributes "the nice way" now that everything is typed
- instantiate_link(scd, "Association", "lc", "Class", "Integer")
- instantiate_attribute(scd, "lc", "name", "lower_cardinality")
- instantiate_link(scd, "Association", "uc", "Class", "Integer")
- instantiate_attribute(scd, "uc", "name", "upper_cardinality")
- instantiate_link(scd, "Association", "slc", "Association", "Integer")
- instantiate_attribute(scd, "slc", "name", "source_lower_cardinality")
- instantiate_link(scd, "Association", "suc", "Association", "Integer")
- instantiate_attribute(scd, "suc", "name", "source_upper_cardinality")
- instantiate_link(scd, "Association", "tlc", "Association", "Integer")
- instantiate_attribute(scd, "tlc", "name", "target_lower_cardinality")
- instantiate_link(scd, "Association", "tuc", "Association", "Integer")
- instantiate_attribute(scd, "tuc", "name", "target_upper_cardinality")
- export_node("models/SimpleClassDiagrams", scd)
- Element pn
- pn = instantiate_model(scd)
- define_inheritance(pn, "Inheritance")
- instantiate_node(pn, "Class", "Place")
- instantiate_node(pn, "Class", "Transition")
- instantiate_node(pn, "Type", "Integer")
- instantiate_link(pn, "Association", "P2T", "Place", "Transition")
- instantiate_link(pn, "Association", "T2P", "Transition", "Place")
- instantiate_link(pn, "Association", "Place_tokens", "Place", "Integer")
- instantiate_attribute(pn, "Place_tokens", "name", "tokens")
- instantiate_attribute(pn, "Place_tokens", "target_lower_cardinality", 1)
- instantiate_attribute(pn, "Place_tokens", "target_upper_cardinality", 1)
- instantiate_link(pn, "Association", "P2T_weight", "P2T", "Integer")
- instantiate_attribute(pn, "P2T_weight", "name", "weight")
- instantiate_attribute(pn, "P2T_weight", "target_lower_cardinality", 1)
- instantiate_attribute(pn, "P2T_weight", "target_upper_cardinality", 1)
- instantiate_link(pn, "Association", "T2P_weight", "T2P", "Integer")
- instantiate_attribute(pn, "T2P_weight", "name", "weight")
- instantiate_attribute(pn, "T2P_weight", "target_lower_cardinality", 1)
- instantiate_attribute(pn, "T2P_weight", "target_upper_cardinality", 1)
- set_model_constraints(pn, petrinet_constraints)
- export_node("models/PetriNets", pn)
- Element ltm_bottom
- ltm_bottom = instantiate_bottom()
- model_add_node(ltm_bottom, "Node")
- model_add_edge(ltm_bottom, "Edge", "Node", "Node")
- model_add_edge(ltm_bottom, "inheritance", "Node", "Node")
- model_add_edge(ltm_bottom, "__inh", "Edge", "Node")
- retype_model(ltm_bottom, ltm_bottom)
- define_inheritance(ltm_bottom, "inheritance")
- retype(ltm_bottom, "Node", "Node")
- retype(ltm_bottom, "Edge", "Edge")
- retype(ltm_bottom, "inheritance", "Edge")
- retype(ltm_bottom, "__inh", "inheritance")
- export_node("models/LTM_bottom", ltm_bottom)
- return dict_read(dict_read(read_root(), "__hierarchy"), "models")
- String function petrinet_constraints(model : Element):
- // Check places to have positive number of tokens
- Element all_elems
- Element elem_constraint
- all_elems = allInstances(model, model["metamodel"]["model"]["Place"])
- while (0 < read_nr_out(all_elems)):
- elem_constraint = set_pop(all_elems)
- if (integer_lt(read_attribute(model, getName(model, elem_constraint), "tokens"), 0)):
- return "Negative number of tokens in Place " + getName(model, elem_constraint)
- // Check P2T transitions to have positive weight
- all_elems = allInstances(model, model["metamodel"]["model"]["P2T"])
- while (0 < read_nr_out(all_elems)):
- elem_constraint = set_pop(all_elems)
- if (integer_lt(read_attribute(model, getName(model, elem_constraint), "weight"), 0)):
- return "Negative weight in arc " + getName(model, elem_constraint)
- // Check T2P transitions to have positive weight
- all_elems = allInstances(model, model["metamodel"]["model"]["T2P"])
- while (0 < read_nr_out(all_elems)):
- elem_constraint = set_pop(all_elems)
- if (integer_lt(read_attribute(model, getName(model, elem_constraint), "weight"), 0)):
- return "Negative weight in arc " + getName(model, elem_constraint)
- return "OK"
|