|
@@ -4,11 +4,20 @@ include "library.alh"
|
|
|
include "conformance_scd.alh"
|
|
|
include "modelling.alh"
|
|
|
|
|
|
-Element function constraint_integer(model : Element, name : String):
|
|
|
+Element function constraint_natural(model : Element, name : String):
|
|
|
if (is_physical_int(model["model"][name])):
|
|
|
+ if (integer_gte(model["model"][name], 0)):
|
|
|
+ return "OK"
|
|
|
+ else:
|
|
|
+ return "Natural number not larger than or equal to zero"
|
|
|
+ else:
|
|
|
+ return "Natural has non-integer instance"
|
|
|
+
|
|
|
+Element function constraint_string(model : Element, name : String):
|
|
|
+ if (is_physical_string(model["model"][name])):
|
|
|
return "OK"
|
|
|
else:
|
|
|
- return "Integer has non-integer instance"
|
|
|
+ return "String has non-string instance"
|
|
|
|
|
|
Element function create_metamodels():
|
|
|
if (bool_not(dict_in(dict_read(read_root(), "__hierarchy"), "models"))):
|
|
@@ -44,18 +53,18 @@ Element function create_metamodels():
|
|
|
retype(scd, "string_inh_any", "Inheritance")
|
|
|
|
|
|
// Add some attributes, now that it is an ordinary model
|
|
|
- instantiate_node(scd, "Class", "Integer")
|
|
|
- instantiate_link(scd, "Association", "lc", "Class", "Integer")
|
|
|
+ instantiate_node(scd, "Class", "Natural")
|
|
|
+ instantiate_link(scd, "Association", "lc", "Class", "Natural")
|
|
|
instantiate_attribute(scd, "lc", "name", "lower_cardinality")
|
|
|
- instantiate_link(scd, "Association", "uc", "Class", "Integer")
|
|
|
+ instantiate_link(scd, "Association", "uc", "Class", "Natural")
|
|
|
instantiate_attribute(scd, "uc", "name", "upper_cardinality")
|
|
|
- instantiate_link(scd, "Association", "slc", "Association", "Integer")
|
|
|
+ instantiate_link(scd, "Association", "slc", "Association", "Natural")
|
|
|
instantiate_attribute(scd, "slc", "name", "source_lower_cardinality")
|
|
|
- instantiate_link(scd, "Association", "suc", "Association", "Integer")
|
|
|
+ instantiate_link(scd, "Association", "suc", "Association", "Natural")
|
|
|
instantiate_attribute(scd, "suc", "name", "source_upper_cardinality")
|
|
|
- instantiate_link(scd, "Association", "tlc", "Association", "Integer")
|
|
|
+ instantiate_link(scd, "Association", "tlc", "Association", "Natural")
|
|
|
instantiate_attribute(scd, "tlc", "name", "target_lower_cardinality")
|
|
|
- instantiate_link(scd, "Association", "tuc", "Association", "Integer")
|
|
|
+ instantiate_link(scd, "Association", "tuc", "Association", "Natural")
|
|
|
instantiate_attribute(scd, "tuc", "name", "target_upper_cardinality")
|
|
|
|
|
|
// Add in the Action Language metamodel
|
|
@@ -128,6 +137,10 @@ Element function create_metamodels():
|
|
|
instantiate_link(scd, "Association", "constraint", "Class", "funcdef")
|
|
|
instantiate_attribute(scd, "constraint", "name", "constraint")
|
|
|
|
|
|
+ // And add some, to enforce correct physical types
|
|
|
+ add_constraint(scd, "Natural", constraint_natural)
|
|
|
+ add_constraint(scd, "String", constraint_string)
|
|
|
+
|
|
|
// Finally done, so export!
|
|
|
export_node("models/SimpleClassDiagrams", scd)
|
|
|
|
|
@@ -137,27 +150,27 @@ Element function create_metamodels():
|
|
|
define_inheritance(pn, "Inheritance")
|
|
|
instantiate_node(pn, "Class", "Place")
|
|
|
instantiate_node(pn, "Class", "Transition")
|
|
|
- instantiate_node(pn, "Class", "Integer")
|
|
|
+ instantiate_node(pn, "Class", "Natural")
|
|
|
instantiate_link(pn, "Association", "P2T", "Place", "Transition")
|
|
|
instantiate_link(pn, "Association", "T2P", "Transition", "Place")
|
|
|
- instantiate_link(pn, "Association", "Place_tokens", "Place", "Integer")
|
|
|
+ instantiate_link(pn, "Association", "Place_tokens", "Place", "Natural")
|
|
|
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_link(pn, "Association", "P2T_weight", "P2T", "Natural")
|
|
|
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_link(pn, "Association", "T2P_weight", "T2P", "Natural")
|
|
|
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)
|
|
|
|
|
|
- // Add constraint on the Integer
|
|
|
- add_constraint(pn, "Integer", constraint_integer)
|
|
|
+ // Add constraint on the Natural
|
|
|
+ add_constraint(pn, "Natural", constraint_natural)
|
|
|
|
|
|
// Add global constraints
|
|
|
- set_model_constraints(pn, petrinet_constraints)
|
|
|
+ //set_model_constraints(pn, petrinet_constraints)
|
|
|
export_node("models/PetriNets", pn)
|
|
|
|
|
|
Element ltm_bottom
|
|
@@ -177,41 +190,3 @@ Element function create_metamodels():
|
|
|
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
|
|
|
- String elem_constraint
|
|
|
-
|
|
|
- log("Check constraints")
|
|
|
- all_elems = allInstances(model, "Place")
|
|
|
- log("Got all instances")
|
|
|
- log("Length " + cast_i2s(list_len(all_elems)))
|
|
|
- log("First element: " + cast_e2s(all_elems[0]))
|
|
|
- while (0 < list_len(all_elems)):
|
|
|
- elem_constraint = set_pop(all_elems)
|
|
|
- log("Check Place " + elem_constraint)
|
|
|
- if (integer_lt(read_attribute(model, elem_constraint, "tokens"), 0)):
|
|
|
- return "Negative number of tokens in Place " + elem_constraint
|
|
|
-
|
|
|
- // Check P2T transitions to have positive weight
|
|
|
- log("Check constraints 2")
|
|
|
- all_elems = allInstances(model, "P2T")
|
|
|
- log("Got all instances")
|
|
|
- while (0 < read_nr_out(all_elems)):
|
|
|
- elem_constraint = set_pop(all_elems)
|
|
|
- log("Check P2T " + elem_constraint)
|
|
|
- if (integer_lt(read_attribute(model, elem_constraint, "weight"), 0)):
|
|
|
- return "Negative weight in arc " + elem_constraint
|
|
|
-
|
|
|
- // Check T2P transitions to have positive weight
|
|
|
- log("Check constraints 3")
|
|
|
- all_elems = allInstances(model, "T2P")
|
|
|
- log("Got all instances")
|
|
|
- while (0 < read_nr_out(all_elems)):
|
|
|
- elem_constraint = set_pop(all_elems)
|
|
|
- log("Check T2P " + elem_constraint)
|
|
|
- if (integer_lt(read_attribute(model, elem_constraint, "weight"), 0)):
|
|
|
- return "Negative weight in arc " + elem_constraint
|
|
|
-
|
|
|
- return "OK"
|