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, "l1", "Class", "Any") model_add_edge(scd, "l2", "Type", "Any") model_add_edge(scd, "l3", "Any", "Any") model_add_edge(scd, "l4", "l3", "inheritance") model_add_edge(scd, "l5", "Any", "Any") model_add_edge(scd, "l6", "l5", "Any") model_add_edge(scd, "l7", "l5", "link") model_add_edge(scd, "l8", "l5", "String") model_add_edge(scd, "l9", "l8", "name") retype_model(scd, scd) define_inheritance(scd, "l3") 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, "l1", "l3") retype(scd, "l2", "l3") retype(scd, "l3", "l5") retype(scd, "l4", "l8") retype(scd, "l5", "l5") retype(scd, "l6", "l3") retype(scd, "l7", "l8") retype(scd, "l8", "l5") retype(scd, "l9", "l8") export_node("models/SimpleClassDiagrams", scd) Element pn pn = instantiate_model(scd) define_inheritance(pn, "l3") instantiate_node(pn, "Class", "Place") instantiate_node(pn, "Class", "Transition") instantiate_node(pn, "Type", "Integer") instantiate_link(pn, "l5", "P2T", "Place", "Transition") instantiate_link(pn, "l5", "T2P", "Transition", "Place") instantiate_named(pn, "l5", "tokens", "Place", "Integer") instantiate_named(pn, "l5", "weight", "P2T", "Integer") instantiate_named(pn, "l5", "weight", "T2P", "Integer") 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(readAttribute(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(readAttribute(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(readAttribute(model, elem_constraint, "weight"), 0)): return "Negative weight in arc " + getName(model, elem_constraint) return "OK"