|
@@ -537,103 +537,25 @@ Element function constraint(model : Element, name : String):
|
|
|
["OK"],
|
|
|
mode))
|
|
|
|
|
|
- def test_po_pn_interface_transform(self):
|
|
|
- action_code = \
|
|
|
- """
|
|
|
-include "primitives.alh"
|
|
|
-Integer function value(host_model : Element, mapping : Element):
|
|
|
-\treturn 5!
|
|
|
- """
|
|
|
-
|
|
|
- constraint_code = \
|
|
|
- """
|
|
|
-include "primitives.alh"
|
|
|
-Boolean function constraint(host_model : Element, name : String):
|
|
|
-\treturn value_eq(host_model["model"][name], 2)!
|
|
|
- """
|
|
|
-
|
|
|
- global_constraint_code = \
|
|
|
- """
|
|
|
-include "primitives.alh"
|
|
|
-Boolean function constraint(host_model : Element, mapping : Element):
|
|
|
-\treturn value_eq(host_model["model"][mapping["0_tokens"]], 2)!
|
|
|
- """
|
|
|
-
|
|
|
- constructor_action = get_constructor(action_code)
|
|
|
- constructor_constraint = get_constructor(constraint_code)
|
|
|
- constructor_global_constraint = get_constructor(global_constraint_code)
|
|
|
-
|
|
|
- self.assertTrue(run_file(all_files,
|
|
|
- ["new", "PetriNets", "pn",
|
|
|
- "instantiate", "Place", "p1",
|
|
|
- "instantiate", "Place", "p2",
|
|
|
- "instantiate", "Transition", "t1",
|
|
|
- "instantiate", "P2T", "p2t", "p1", "t1",
|
|
|
- "instantiate", "P2T", "p2t2", "p2", "t1",
|
|
|
- "attr_add", "p1", "tokens", 1,
|
|
|
- "attr_add", "p2", "tokens", 2,
|
|
|
- "attr_add", "p2t", "weight", 1,
|
|
|
- "attr_add", "p2t2", "weight", 2,
|
|
|
- "exit",
|
|
|
- "ramify", "PetriNets",
|
|
|
- "new", "PetriNets_PRE", "pn_LHS",
|
|
|
- "instantiate", "LHS", "lhs",
|
|
|
- "instantiate", "Pre_Place", "p",
|
|
|
- "instantiate", "Pre_Natural", "tokens",
|
|
|
- "instantiate", "Pre_Place_tokens", "p_tokens", "p", "tokens",
|
|
|
- "instantiate", "Pre_Transition", "t",
|
|
|
- "instantiate", "Pre_P2T", "pt", "p", "t",
|
|
|
- "instantiate", "LHS_contains", "", "lhs", "p",
|
|
|
- "instantiate", "LHS_contains", "", "lhs", "t",
|
|
|
- "instantiate", "LHS_contains", "", "lhs", "pt",
|
|
|
- "instantiate", "LHS_contains", "", "lhs", "tokens",
|
|
|
- "instantiate", "LHS_contains", "", "lhs", "p_tokens",
|
|
|
- "attr_add", "tokens", "label", "0_tokens",
|
|
|
- "attr_add", "p_tokens", "label", "1_p_tokens",
|
|
|
- "attr_add_code", "tokens", "constraint",
|
|
|
- ] + constructor_constraint + [
|
|
|
- "attr_add", "p", "label", "2_p",
|
|
|
- "attr_add", "t", "label", "3_t",
|
|
|
- "attr_add", "pt", "label", "4_pt",
|
|
|
- "attr_add_code", "lhs", "constraint",
|
|
|
- ] + constructor_global_constraint + [
|
|
|
- "exit",
|
|
|
- "new", "PetriNets_POST", "pn_RHS",
|
|
|
- "instantiate", "RHS", "rhs",
|
|
|
- "instantiate", "Post_Place", "p",
|
|
|
- "instantiate", "Post_Transition", "t",
|
|
|
- "instantiate", "Post_Natural", "tokens",
|
|
|
- "instantiate", "Post_Place_tokens", "p_tokens", "p", "tokens",
|
|
|
- "instantiate", "RHS_contains", "", "rhs", "p",
|
|
|
- "instantiate", "RHS_contains", "", "rhs", "t",
|
|
|
- "instantiate", "RHS_contains", "", "rhs", "p_tokens",
|
|
|
- "instantiate", "RHS_contains", "", "rhs", "tokens",
|
|
|
- "attr_add", "tokens", "label", "5_tokens",
|
|
|
- "attr_add", "p_tokens", "label", "6_p_tokens",
|
|
|
- "attr_add", "p", "label", "2_p",
|
|
|
- "attr_add", "t", "label", "3_t",
|
|
|
- "attr_add_code", "tokens", "value",
|
|
|
- ] + constructor_action + [
|
|
|
- "exit",
|
|
|
- "transform", "pn", "pn_LHS", "pn_RHS",
|
|
|
- "load", "pn",
|
|
|
- "list",
|
|
|
- "verify",
|
|
|
- "read",
|
|
|
- "p1",
|
|
|
- "read",
|
|
|
- "p2",
|
|
|
- "exit",
|
|
|
- ],
|
|
|
- None, "PO"))
|
|
|
-
|
|
|
- def test_po_pn_interface_transform_UI(self):
|
|
|
+ def test_po_pn_interface_transform_pn(self):
|
|
|
constraint_code = \
|
|
|
"""
|
|
|
include "primitives.alh"
|
|
|
include "modelling.alh"
|
|
|
+include "object_operations.alh"
|
|
|
Boolean function constraint(host_model : Element, name : String):
|
|
|
-\treturn value_eq(read_attribute(host_model, name, "tokens"), 1)!
|
|
|
+\t// Make sure that all places have enough tokens
|
|
|
+\tElement links
|
|
|
+\tElement link
|
|
|
+\tElement place
|
|
|
+\tlinks = allIncomingAssociationInstances(host_model, name, "P2T")
|
|
|
+\twhile (read_nr_out(links) > 0):
|
|
|
+\t\tlink = set_pop(links)
|
|
|
+\t\tplace = readAssociationSource(host_model, link)
|
|
|
+\t\tif (integer_lt(read_attribute(host_model, place, "tokens"), read_attribute(host_model, link, "weight"))):
|
|
|
+\t\t\t// Not enough tokens for this weight
|
|
|
+\t\t\treturn False!
|
|
|
+\treturn True!
|
|
|
"""
|
|
|
|
|
|
action_code = \
|
|
@@ -641,7 +563,8 @@ Boolean function constraint(host_model : Element, name : String):
|
|
|
include "primitives.alh"
|
|
|
include "modelling.alh"
|
|
|
Void function action(host_model : Element, name : String, mapping : Element):
|
|
|
-\tinstantiate_attribute(host_model, name, "tokens", read_attribute(host_model, mapping["0_p"], "tokens"))
|
|
|
+\tunset_attribute(host_model, name, "executing")
|
|
|
+\tinstantiate_attribute(host_model, name, "executing", True)
|
|
|
\treturn!
|
|
|
"""
|
|
|
|
|
@@ -649,54 +572,57 @@ Void function action(host_model : Element, name : String, mapping : Element):
|
|
|
constructor_constraint = get_constructor(constraint_code)
|
|
|
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- ["new", "PetriNets", "pn",
|
|
|
+ ["new", "SimpleClassDiagrams", "PetriNets_runtime",
|
|
|
+ "set_inheritance", "Inheritance",
|
|
|
+ "instantiate", "Class", "Natural",
|
|
|
+ "instantiate", "Class", "Boolean",
|
|
|
+ "instantiate", "Class", "Place",
|
|
|
+ "attr_def", "Place", "tokens", "Natural",
|
|
|
+ "attr_def", "Place", "executed", "Boolean",
|
|
|
+ "instantiate", "Class", "Transition",
|
|
|
+ "attr_def", "Transition", "executing", "Boolean",
|
|
|
+ "instantiate", "Association", "P2T", "Place", "Transition",
|
|
|
+ "attr_def", "P2T", "weight", "Natural",
|
|
|
+ "instantiate", "Association", "T2P", "Transition", "Place",
|
|
|
+ "attr_def", "T2P", "weight", "Natural",
|
|
|
+ "exit",
|
|
|
+ "new", "PetriNets_runtime", "pn",
|
|
|
"instantiate", "Place", "p1",
|
|
|
+ "attr_add", "p1", "tokens", 1,
|
|
|
+ "attr_add", "p1", "executed", False,
|
|
|
"instantiate", "Place", "p2",
|
|
|
+ "attr_add", "p2", "tokens", 2,
|
|
|
+ "attr_add", "p2", "executed", False,
|
|
|
"instantiate", "Transition", "t1",
|
|
|
+ "attr_add", "t1", "executing", False,
|
|
|
"instantiate", "P2T", "p2t", "p1", "t1",
|
|
|
+ "attr_add", "p2t", "weight", 2,
|
|
|
"instantiate", "P2T", "p2t2", "p2", "t1",
|
|
|
- "attr_add", "p1", "tokens", 1,
|
|
|
- "attr_add", "p2", "tokens", 2,
|
|
|
- "attr_add", "p2t", "weight", 1,
|
|
|
- "attr_add", "p2t2", "weight", 2,
|
|
|
+ "attr_add", "p2t2", "weight", 1,
|
|
|
"exit",
|
|
|
- "ramify", "PetriNets",
|
|
|
- "new", "PetriNets_PRE", "pn_LHS",
|
|
|
+ "ramify", "PetriNets_runtime",
|
|
|
+ "new", "PetriNets_runtime_PRE", "pn_LHS",
|
|
|
"instantiate", "LHS", "lhs",
|
|
|
- "instantiate", "Pre_Place", "p",
|
|
|
"instantiate", "Pre_Transition", "t",
|
|
|
- "instantiate", "Pre_P2T", "pt", "p", "t",
|
|
|
- "instantiate", "LHS_contains", "", "lhs", "p",
|
|
|
+ "attr_add", "t", "label", "0",
|
|
|
+ #"attr_add_code", "t", "constraint",
|
|
|
+ #] + constructor_constraint + [
|
|
|
"instantiate", "LHS_contains", "", "lhs", "t",
|
|
|
- "instantiate", "LHS_contains", "", "lhs", "pt",
|
|
|
- "attr_add", "p", "label", "0_p",
|
|
|
- "attr_add", "t", "label", "1_t",
|
|
|
- "attr_add", "pt", "label", "2_pt",
|
|
|
- "attr_add_code", "p", "constraint",
|
|
|
- ] + constructor_constraint + [
|
|
|
"exit",
|
|
|
- "new", "PetriNets_POST", "pn_RHS",
|
|
|
+ "new", "PetriNets_runtime_POST", "pn_RHS",
|
|
|
"instantiate", "RHS", "rhs",
|
|
|
- "instantiate", "Post_Place", "p",
|
|
|
- "instantiate", "Post_Place", "p2",
|
|
|
"instantiate", "Post_Transition", "t",
|
|
|
- "instantiate", "RHS_contains", "", "rhs", "p",
|
|
|
- "instantiate", "RHS_contains", "", "rhs", "p2",
|
|
|
- "instantiate", "RHS_contains", "", "rhs", "t",
|
|
|
- "attr_add", "p", "label", "0_p",
|
|
|
- "attr_add", "t", "label", "1_t",
|
|
|
- "attr_add", "p2", "label", "3_p",
|
|
|
- "attr_add_code", "p2", "action",
|
|
|
+ "attr_add", "t", "label", "0",
|
|
|
+ "attr_add_code", "t", "action",
|
|
|
] + constructor_action + [
|
|
|
+ "instantiate", "RHS_contains", "", "rhs", "t",
|
|
|
"exit",
|
|
|
"transform", "pn", "pn_LHS", "pn_RHS",
|
|
|
"load", "pn",
|
|
|
"list",
|
|
|
"verify",
|
|
|
"read",
|
|
|
- "p1",
|
|
|
- "read",
|
|
|
- "p2",
|
|
|
+ "t1",
|
|
|
"exit",
|
|
|
],
|
|
|
None, "PO"))
|