|
@@ -539,7 +539,7 @@ Element function constraint(model : Element, name : String):
|
|
|
mode))
|
|
|
|
|
|
def test_po_pn_interface_transform_pn(self):
|
|
|
- constraint_mark_code = \
|
|
|
+ code_mark_constraint = \
|
|
|
"""
|
|
|
include "primitives.alh"
|
|
|
include "modelling.alh"
|
|
@@ -561,7 +561,7 @@ Boolean function constraint(host_model : Element, name : String):
|
|
|
\treturn True!
|
|
|
"""
|
|
|
|
|
|
- action_mark_code = \
|
|
|
+ code_mark_action = \
|
|
|
"""
|
|
|
include "primitives.alh"
|
|
|
include "modelling.alh"
|
|
@@ -571,7 +571,7 @@ Void function action(host_model : Element, name : String, mapping : Element):
|
|
|
\treturn!
|
|
|
"""
|
|
|
|
|
|
- constraint_consume_code = \
|
|
|
+ code_consume_transition_constraint = \
|
|
|
"""
|
|
|
include "primitives.alh"
|
|
|
include "modelling.alh"
|
|
@@ -580,7 +580,16 @@ Boolean function constraint(host_model : Element, name : String):
|
|
|
\treturn value_eq(read_attribute(host_model, name, "executing"), True)!
|
|
|
"""
|
|
|
|
|
|
- action_consume_code = \
|
|
|
+ code_consume_place_constraint = \
|
|
|
+ """
|
|
|
+include "primitives.alh"
|
|
|
+include "modelling.alh"
|
|
|
+Boolean function constraint(host_model : Element, name : String):
|
|
|
+\t// Check if this node is executing currently
|
|
|
+\treturn value_eq(read_attribute(host_model, name, "executed"), False)!
|
|
|
+ """
|
|
|
+
|
|
|
+ code_consume_place_action = \
|
|
|
"""
|
|
|
include "primitives.alh"
|
|
|
include "modelling.alh"
|
|
@@ -594,10 +603,74 @@ Void function action(host_model : Element, name : String, mapping : Element):
|
|
|
\treturn!
|
|
|
"""
|
|
|
|
|
|
- constructor_mark_action = get_constructor(action_mark_code)
|
|
|
- constructor_mark_constraint = get_constructor(constraint_mark_code)
|
|
|
- constructor_consume_constraint = get_constructor(constraint_consume_code)
|
|
|
- constructor_consume_action = get_constructor(action_consume_code)
|
|
|
+ code_produce_place_action = \
|
|
|
+ """
|
|
|
+include "primitives.alh"
|
|
|
+include "modelling.alh"
|
|
|
+Void function action(host_model : Element, name : String, mapping : Element):
|
|
|
+\tInteger tokens
|
|
|
+\tInteger weight
|
|
|
+\ttokens = read_attribute(host_model, name, "tokens")
|
|
|
+\tweight = read_attribute(host_model, mapping["2"], "weight")
|
|
|
+\tunset_attribute(host_model, name, "tokens")
|
|
|
+\tinstantiate_attribute(host_model, name, "tokens", tokens + weight)
|
|
|
+\treturn!
|
|
|
+ """
|
|
|
+
|
|
|
+ code_unmark_transition_constraint = \
|
|
|
+ """
|
|
|
+include "primitives.alh"
|
|
|
+include "modelling.alh"
|
|
|
+Boolean function constraint(host_model : Element, name : String):
|
|
|
+\t// Check if this node is executing currently
|
|
|
+\treturn value_eq(read_attribute(host_model, name, "executing"), True)!
|
|
|
+ """
|
|
|
+
|
|
|
+ code_unmark_place_constraint = \
|
|
|
+ """
|
|
|
+include "primitives.alh"
|
|
|
+include "modelling.alh"
|
|
|
+Boolean function constraint(host_model : Element, name : String):
|
|
|
+\t// Check if this node is executing currently
|
|
|
+\treturn value_eq(read_attribute(host_model, name, "executed"), True)!
|
|
|
+ """
|
|
|
+
|
|
|
+ code_unmark_transition_action = \
|
|
|
+ """
|
|
|
+include "primitives.alh"
|
|
|
+include "modelling.alh"
|
|
|
+Void function action(host_model : Element, name : String, mapping : Element):
|
|
|
+\tunset_attribute(host_model, name, "executing")
|
|
|
+\tinstantiate_attribute(host_model, name, "executing", False)
|
|
|
+\treturn!
|
|
|
+ """
|
|
|
+
|
|
|
+ code_unmark_place_action = \
|
|
|
+ """
|
|
|
+include "primitives.alh"
|
|
|
+include "modelling.alh"
|
|
|
+Void function action(host_model : Element, name : String, mapping : Element):
|
|
|
+\tunset_attribute(host_model, name, "executed")
|
|
|
+\tinstantiate_attribute(host_model, name, "executed", False)
|
|
|
+\treturn!
|
|
|
+ """
|
|
|
+
|
|
|
+ constructor_mark_constraint = get_constructor(code_mark_constraint)
|
|
|
+ constructor_mark_action = get_constructor(code_mark_action)
|
|
|
+
|
|
|
+ constructor_consume_transition_constraint = get_constructor(code_consume_transition_constraint)
|
|
|
+ constructor_consume_place_constraint = get_constructor(code_consume_place_constraint)
|
|
|
+ constructor_consume_place_action = get_constructor(code_consume_place_action)
|
|
|
+
|
|
|
+ constructor_produce_transition_constraint = constructor_consume_transition_constraint
|
|
|
+ constructor_produce_place_constraint = constructor_consume_place_constraint
|
|
|
+ constructor_produce_place_action = get_constructor(code_produce_place_action)
|
|
|
+
|
|
|
+ constructor_unmark_transition_constraint = constructor_consume_transition_constraint
|
|
|
+ constructor_unmark_transition_action = get_constructor(code_unmark_transition_action)
|
|
|
+
|
|
|
+ constructor_unmark_place_constraint = get_constructor(code_unmark_place_constraint)
|
|
|
+ constructor_unmark_place_action = get_constructor(code_unmark_place_action)
|
|
|
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
["new", "SimpleClassDiagrams", "PetriNets_runtime",
|
|
@@ -631,31 +704,153 @@ Void function action(host_model : Element, name : String, mapping : Element):
|
|
|
"ramify", "PetriNets_runtime",
|
|
|
"new", "PetriNets_runtime_SCHEDULE", "pn_simulate",
|
|
|
# Rule 1: mark transition to execute
|
|
|
+ # LHS
|
|
|
"instantiate", "LHS", "lhs_mark",
|
|
|
"instantiate", "Pre_Transition", "pre_mark_t",
|
|
|
"attr_add", "pre_mark_t", "label", "0",
|
|
|
"attr_add_code", "pre_mark_t", "constraint",
|
|
|
] + constructor_mark_constraint + [
|
|
|
"instantiate", "LHS_contains", "", "lhs_mark", "pre_mark_t",
|
|
|
+ # RHS
|
|
|
"instantiate", "RHS", "rhs_mark",
|
|
|
"instantiate", "Post_Transition", "post_mark_t",
|
|
|
"attr_add", "post_mark_t", "label", "0",
|
|
|
"attr_add_code", "post_mark_t", "action",
|
|
|
] + constructor_mark_action + [
|
|
|
"instantiate", "RHS_contains", "", "rhs_mark", "post_mark_t",
|
|
|
- "instantiate", "Composite", "main",
|
|
|
+ # Atomic of rule 1 "mark"
|
|
|
"instantiate", "Atomic", "mark",
|
|
|
"instantiate", "AtomicLHS", "", "mark", "lhs_mark",
|
|
|
"instantiate", "AtomicRHS", "", "mark", "rhs_mark",
|
|
|
+ # Rule 2: consume tokens going into marked transition
|
|
|
+ # LHS
|
|
|
+ "instantiate", "LHS", "lhs_consume",
|
|
|
+ "instantiate", "Pre_Transition", "pre_consume_t",
|
|
|
+ "attr_add", "pre_consume_t", "label", "0",
|
|
|
+ "attr_add_code", "pre_consume_t", "constraint",
|
|
|
+ ] + constructor_consume_transition_constraint + [
|
|
|
+ "instantiate", "Pre_Place", "pre_consume_p",
|
|
|
+ "attr_add", "pre_consume_p", "label", "1",
|
|
|
+ "attr_add_code", "pre_consume_p", "constraint",
|
|
|
+ ] + constructor_consume_place_constraint + [
|
|
|
+ "instantiate", "Pre_P2T", "pre_consume_p2t",
|
|
|
+ "attr_add", "pre_consume_p2t", "label", "2",
|
|
|
+ "instantiate", "LHS_contains", "", "lhs_consume", "pre_consume_t",
|
|
|
+ "instantiate", "LHS_contains", "", "lhs_consume", "pre_consume_p",
|
|
|
+ "instantiate", "LHS_contains", "", "lhs_consume", "pre_consume_p2t",
|
|
|
+ # RHS
|
|
|
+ "instantiate", "RHS", "rhs_consume",
|
|
|
+ "instantiate", "Post_Transition", "post_consume_t",
|
|
|
+ "attr_add", "post_consume_t", "label", "0",
|
|
|
+ "instantiate", "Post_Place", "post_consume_p",
|
|
|
+ "attr_add", "post_consume_p", "label", "1",
|
|
|
+ "attr_add_code", "post_consume_p2t", "action",
|
|
|
+ ] + constructor_consume_place_action + [
|
|
|
+ "instantiate", "Post_P2T", "post_consume_p2t",
|
|
|
+ "attr_add", "post_consume_p2t", "label", "2",
|
|
|
+ "instantiate", "RHS_contains", "", "rhs_consume", "post_consume_t",
|
|
|
+ "instantiate", "RHS_contains", "", "rhs_consume", "post_consume_p",
|
|
|
+ "instantiate", "RHS_contains", "", "rhs_consume", "post_consume_p2t",
|
|
|
+ # Atomic of rule 2 "consume"
|
|
|
+ "instantiate", "Atomic", "consume",
|
|
|
+ "instantiate", "AtomicLHS", "", "consume", "lhs_consume",
|
|
|
+ "instantiate", "AtomicRHS", "", "consume", "rhs_consume",
|
|
|
+ # Rule 3: produce tokens going out of marked transition
|
|
|
+ # LHS
|
|
|
+ "instantiate", "LHS", "lhs_produce",
|
|
|
+ "instantiate", "Pre_Transition", "pre_produce_t",
|
|
|
+ "attr_add", "pre_produce_t", "label", "0",
|
|
|
+ "attr_add_code", "pre_produce_t", "constraint",
|
|
|
+ ] + constructor_produce_transition_constraint + [
|
|
|
+ "instantiate", "Pre_Place", "pre_produce_p",
|
|
|
+ "attr_add", "pre_produce_p", "label", "1",
|
|
|
+ "attr_add_code", "pre_produce_p", "constraint",
|
|
|
+ ] + constructor_produce_place_constraint + [
|
|
|
+ "instantiate", "Pre_T2P", "pre_produce_t2p",
|
|
|
+ "attr_add", "pre_consume_t2p", "label", "2",
|
|
|
+ "instantiate", "LHS_contains", "", "lhs_produce", "pre_produce_t",
|
|
|
+ "instantiate", "LHS_contains", "", "lhs_produce", "pre_produce_p",
|
|
|
+ "instantiate", "LHS_contains", "", "lhs_produce", "pre_produce_t2p",
|
|
|
+ # RHS
|
|
|
+ "instantiate", "RHS", "rhs_produce",
|
|
|
+ "instantiate", "Post_Transition", "post_produce_t",
|
|
|
+ "attr_add", "post_produce_t", "label", "0",
|
|
|
+ "instantiate", "Post_Place", "post_produce_p",
|
|
|
+ "attr_add", "post_produce_p", "label", "1",
|
|
|
+ "attr_add_code", "post_produce_p2t", "action",
|
|
|
+ ] + constructor_produce_place_action + [
|
|
|
+ "instantiate", "Post_T2P", "post_produce_t2p",
|
|
|
+ "attr_add", "post_consume_t2p", "label", "2",
|
|
|
+ "instantiate", "RHS_contains", "", "rhs_produce", "post_produce_t",
|
|
|
+ "instantiate", "RHS_contains", "", "rhs_produce", "post_produce_p",
|
|
|
+ "instantiate", "RHS_contains", "", "rhs_produce", "post_produce_t2p",
|
|
|
+ # Atomic of rule 3 "produce"
|
|
|
+ "instantiate", "Atomic", "consume",
|
|
|
+ "instantiate", "AtomicLHS", "", "produce", "lhs_produce",
|
|
|
+ "instantiate", "AtomicRHS", "", "produce", "rhs_produce",
|
|
|
+ # Rule 4: unmark marked transition
|
|
|
+ # LHS
|
|
|
+ "instantiate", "LHS", "lhs_unmark_transition",
|
|
|
+ "instantiate", "Pre_Transition", "pre_unmark_t",
|
|
|
+ "attr_add", "pre_unmark_t", "label", "0",
|
|
|
+ "attr_add_code", "pre_unmark_t", "constraint",
|
|
|
+ ] + constructor_unmark_transition_constraint + [
|
|
|
+ "instantiate", "LHS_contains", "", "lhs_unmark_transition", "pre_unmark_t",
|
|
|
+ # RHS
|
|
|
+ "instantiate", "RHS", "rhs_unmark_transition",
|
|
|
+ "instantiate", "Post_Transition", "post_unmark_t",
|
|
|
+ "attr_add", "post_unmark_t", "label", "0",
|
|
|
+ "attr_add_code", "post_unmark_t", "action",
|
|
|
+ ] + constructor_unmark_transition_action + [
|
|
|
+ "instantiate", "RHS_contains", "", "rhs_unmark_t", "post_unmark_t",
|
|
|
+ # Atomic of rule 4 "unmark transition"
|
|
|
+ "instantiate", "Atomic", "unmark_transition",
|
|
|
+ "instantiate", "AtomicLHS", "", "produce", "lhs_unmark_transition",
|
|
|
+ "instantiate", "AtomicRHS", "", "produce", "rhs_unmark_transition",
|
|
|
+ # Rule 5: unmark marked places
|
|
|
+ # LHS
|
|
|
+ "instantiate", "LHS", "lhs_unmark_place",
|
|
|
+ "instantiate", "Pre_Place", "pre_unmark_p",
|
|
|
+ "attr_add", "pre_unmark_p", "label", "0",
|
|
|
+ "attr_add_code", "pre_unmark_p", "constraint",
|
|
|
+ ] + constructor_unmark_place_constraint + [
|
|
|
+ "instantiate", "LHS_contains", "", "lhs_unmark_place", "pre_unmark_p",
|
|
|
+ # RHS
|
|
|
+ "instantiate", "RHS", "rhs_unmark_place",
|
|
|
+ "instantiate", "Post_Place", "post_unmark_p",
|
|
|
+ "attr_add", "post_unmark_p", "label", "0",
|
|
|
+ "attr_add_code", "post_unmark_p", "action",
|
|
|
+ ] + constructor_unmark_place_action + [
|
|
|
+ "instantiate", "RHS_contains", "", "rhs_unmark_p", "post_unmark_p",
|
|
|
+ # Atomic of rule 5 "unmark place"
|
|
|
+ "instantiate", "Atomic", "unmark_place",
|
|
|
+ "instantiate", "AtomicLHS", "", "produce", "lhs_unmark_place",
|
|
|
+ "instantiate", "AtomicRHS", "", "produce", "rhs_unmark_place",
|
|
|
+ # Compose schedule
|
|
|
+ "instantiate", "Composite", "main",
|
|
|
"instantiate", "Success", "success",
|
|
|
"instantiate", "Failure", "failure",
|
|
|
- "instantiate", "Contains", "", "main", "mark",
|
|
|
+ # Add all rules
|
|
|
"instantiate", "Contains", "", "main", "success",
|
|
|
"instantiate", "Contains", "", "main", "failure",
|
|
|
+ "instantiate", "Contains", "", "main", "mark",
|
|
|
+ "instantiate", "Contains", "", "main", "consume",
|
|
|
+ "instantiate", "Contains", "", "main", "produce",
|
|
|
+ "instantiate", "Contains", "", "main", "unmark_transition",
|
|
|
+ "instantiate", "Contains", "", "main", "unmark_place",
|
|
|
+ # Scheduling order
|
|
|
"instantiate", "OnSuccess", "", "mark", "success",
|
|
|
"instantiate", "OnFailure", "", "mark", "failure",
|
|
|
+ "instantiate", "OnSucces", "", "consume", "consume",
|
|
|
+ "instantiate", "OnFailure", "", "consume", "produce",
|
|
|
+ "instantiate", "OnSucces", "", "produce", "produce",
|
|
|
+ "instantiate", "OnFailure", "", "produce", "unmark_transition",
|
|
|
+ "instantiate", "OnSucces", "", "unmark_transition", "unmark_place",
|
|
|
+ "instantiate", "OnFailure", "", "unmark_transition", "failure",
|
|
|
+ "instantiate", "OnSucces", "", "unmark_place", "unmark_place",
|
|
|
+ "instantiate", "OnFailure", "", "unmark_place", "success",
|
|
|
+ # Composite initial
|
|
|
"instantiate", "Initial", "", "main", "mark",
|
|
|
- # Rule 2: consume tokens going into marked transition
|
|
|
"exit",
|
|
|
"transform", "pn", "pn_simulate",
|
|
|
"load", "pn",
|