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) //////////////////////////////////////////////////////////////////////////// // create PETRINET transformation metamodel //////////////////////////////////////////////////////////////////////////// ////////////////// // Constant part (this is what every transformation_metamodel will need) Element transform_metamodel transform_metamodel = instantiate_model(scd) define_inheritance(transform_metamodel, "inheritance") //create Transformation node with name attribute instantiate_node(transform_metamodel, "Class", "Transformation") instantiate_node(transform_metamodel, "Type", "String") instantiate_named(transform_metamodel, "l5", "name", "Transformation", "String") //create Rule node with name attribute and precedence attribute (precedence will later be replaced by explicit modelled order) instantiate_node(transform_metamodel, "Class", "Rule") instantiate_named(transform_metamodel, "l5", "name", "Rule", "String") instantiate_node(transform_metamodel, "Type", "Integer") instantiate_named(transform_metamodel, "l5", "precedence", "Rule", "Integer") //create edge between transformation and rule instantiate_link(transform_metamodel, "l5", "transformation_to_rule", "Transformation", "Rule") //create precondition pattern with condition (condition is a python string of code that should be executed) instantiate_node(transform_metamodel, "Class", "Precondition") instantiate_named(transform_metamodel, "l5", "condition", "Precondition", "String") //create LHS edge between rule and preconditionpattern instantiate_link(transform_metamodel, "l5", "lhs", "Rule", "Precondition") //create NAC edge between rule and preconditionpattern instantiate_link(transform_metamodel, "l5", "nac", "Rule", "Precondition") //create postcondition pattern with actions code (code is a python string of code that should be executed) instantiate_node(transform_metamodel, "Class", "Postcondition") instantiate_named(transform_metamodel, "l5", "code", "Postcondition", "String") //create RHS edge between pattern and postcondition instantiate_link(transform_metamodel, "l5", "rhs", "Rule", "Postcondition") //general lefthandside node (contains plabel for example) instantiate_node(transform_metamodel, "Class", "RAMgeneral") instantiate_named(transform_metamodel, "l5", "plabel", "RAMgeneral", "Integer") //connect RAMgeneral to precondition instantiate_link(transform_metamodel, "l5", "pre2ram", "Precondition","RAMgeneral") //connect RAMgeneral to postcondition instantiate_link(transform_metamodel, "l5", "post2ram", "Postcondition", "RAMgeneral") ////////////////// // Variable part (this is were relaxed metamodels will be inserted ) // for the moment this means that we: // 1) copy the metamodel // 2) Relaxation: ignore the constraints by simply not copying them (we will later on make a distinction in constraints that should or should not be respected) // 3) Augmentation: insert for every element the plabel (now implemented by inheritance) // 4) Modification: change attributes to string, so that python code can be inserted (later on, change to action code) // We have a difference in LHS and RHS, as LHS will have boolean functions at attribute-level and RHS will have functions that return values for the new attributes // As everything is executed in python code for now, there will no visible difference here except for the names. // Later on, one might add constraints that check the return value //RAMified petrinet for left hand side //place with tokens instantiate_node(transform_metamodel, "Class", "Place_LHS") instantiate_named(transform_metamodel, "l5", "tokens", "Place_LHS", "String") //modification //transition instantiate_node(transform_metamodel, "Class", "Transition_LHS") //P2T with weight instantiate_link(transform_metamodel, "l5", "P2T_LHS", "Place_LHS","Transition_LHS") instantiate_named(transform_metamodel, "l5", "weight", "P2T_LHS", "String") //T2P with weight instantiate_link(transform_metamodel, "l5", "T2P_LHS", "Transition_LHS","Place_LHS") instantiate_named(transform_metamodel, "l5", "weight", "T2P_LHS", "String") //inheritance links instantiate_link(transform_metamodel, "inheritance", "Place_LHS_is_RAM", "Place_LHS","RAMgeneral") instantiate_link(transform_metamodel, "inheritance", "Transition_LHS_is_RAM", "Transition_LHS","RAMgeneral") instantiate_link(transform_metamodel, "inheritance", "P2T_LHS_is_RAM", "P2T_LHS","RAMgeneral") instantiate_link(transform_metamodel, "inheritance", "T2P_LHS_is_RAM", "P2T_LHS","RAMgeneral") //RAMified petrinet for RIGHT hand side instantiate_node(transform_metamodel, "Class", "Place_RHS") instantiate_named(transform_metamodel, "l5", "tokens", "Place_RHS", "String") //modification instantiate_node(transform_metamodel, "Class", "Transition_RHS") instantiate_link(transform_metamodel, "l5", "P2T_RHS", "Place_RHS","Transition_RHS") instantiate_named(transform_metamodel, "l5", "weight", "P2T_RHS", "String") instantiate_link(transform_metamodel, "l5", "T2P_RHS", "Transition_RHS","Place_RHS") instantiate_named(transform_metamodel, "l5", "weight", "T2P_RHS", "String") //modification //inheritance links instantiate_link(transform_metamodel, "inheritance", "Place_RHS_is_RAM", "Place_RHS","RAMgeneral") instantiate_link(transform_metamodel, "inheritance", "Transition_RHS_is_RAM", "Transition_RHS","RAMgeneral") instantiate_link(transform_metamodel, "inheritance", "P2T_RHS_is_RAM", "P2T_RHS","RAMgeneral") instantiate_link(transform_metamodel, "inheritance", "T2P_RHS_is_RAM", "P2T_RHS","RAMgeneral") export_node("models/PetriNets_MTransformation", transform_metamodel) 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"