|
@@ -19,34 +19,36 @@ Element function petrinet_enabled(model : Element):
|
|
|
set_enabled = petrinet_enabled_set(model)
|
|
|
output("Enabled transitions:")
|
|
|
while (0 < read_nr_out(set_enabled)):
|
|
|
- output(getName(model, set_pop(set_enabled)))
|
|
|
+ output(set_pop(set_enabled))
|
|
|
return model
|
|
|
|
|
|
Element function petrinet_enabled_set(model : Element):
|
|
|
Element all_transitions
|
|
|
- all_transitions = allInstances(model, model["metamodel"]["model"]["Transition"])
|
|
|
-
|
|
|
Element enabled_transitions
|
|
|
- enabled_transitions = create_node()
|
|
|
-
|
|
|
- Element under_study
|
|
|
+ String under_study
|
|
|
Element in_arcs
|
|
|
- Element arc_under_study
|
|
|
+ String arc_under_study
|
|
|
Boolean enabled
|
|
|
+
|
|
|
+ all_transitions = allInstances(model, "Transition")
|
|
|
+ enabled_transitions = create_node()
|
|
|
+
|
|
|
while (0 < read_nr_out(all_transitions)):
|
|
|
under_study = set_pop(all_transitions)
|
|
|
enabled = True
|
|
|
|
|
|
// Find all incoming transitions
|
|
|
- in_arcs = allIncomingAssociationInstances(model, reverseKeyLookup(model["model"], under_study), "P2T")
|
|
|
+ in_arcs = allIncomingAssociationInstances(model, under_study, "P2T")
|
|
|
|
|
|
while (0 < read_nr_out(in_arcs)):
|
|
|
arc_under_study = set_pop(in_arcs)
|
|
|
|
|
|
Integer present_tokens
|
|
|
Integer required_tokens
|
|
|
- required_tokens = read_attribute(model, getName(model, arc_under_study), "weight")
|
|
|
- present_tokens = read_attribute(model, getName(model, read_edge_src(arc_under_study)), "tokens")
|
|
|
+ required_tokens = read_attribute(model, arc_under_study, "weight")
|
|
|
+ log("Weight: " + cast_i2s(required_tokens))
|
|
|
+ present_tokens = read_attribute(model, getName(model, read_edge_src(model["model"][arc_under_study])), "tokens")
|
|
|
+ log("Tokens: " + cast_i2s(present_tokens))
|
|
|
if (present_tokens < required_tokens):
|
|
|
// Less tokens than required, so disable the transition completely
|
|
|
enabled = False
|
|
@@ -54,39 +56,39 @@ Element function petrinet_enabled_set(model : Element):
|
|
|
if (enabled):
|
|
|
set_add(enabled_transitions, under_study)
|
|
|
|
|
|
+ log("Got all enabled transitions!")
|
|
|
return enabled_transitions
|
|
|
|
|
|
Element function petrinet_fire(model : Element):
|
|
|
output("Transition to fire?")
|
|
|
- Element transition
|
|
|
+ String transition
|
|
|
transition = input()
|
|
|
if (dict_in(model["model"], transition)):
|
|
|
- transition = model["model"][transition]
|
|
|
if (set_in(petrinet_enabled_set(model), transition)):
|
|
|
Element workset
|
|
|
- Element working_place
|
|
|
- Element working_arc
|
|
|
+ String working_place
|
|
|
+ String working_arc
|
|
|
Integer new_value
|
|
|
|
|
|
// Consume tokens
|
|
|
- workset = allIncomingAssociationInstances(model, reverseKeyLookup(model["model"], transition), "P2T")
|
|
|
+ workset = allIncomingAssociationInstances(model, transition, "P2T")
|
|
|
while (0 < read_nr_out(workset)):
|
|
|
working_arc = set_pop(workset)
|
|
|
- working_place = read_edge_src(working_arc)
|
|
|
- new_value = integer_subtraction(read_attribute(model, getName(model, working_place), "tokens"), read_attribute(model, getName(model, working_arc), "weight"))
|
|
|
- unset_attribute(model, getName(model, working_place), "tokens")
|
|
|
- instantiate_attribute(model, getName(model, working_place), "tokens", new_value)
|
|
|
- output(((" " + getName(model, working_place)) + ": ") + cast_i2s(read_attribute(model, getName(model, working_place), "tokens")))
|
|
|
+ working_place = getName(model, read_edge_src(model["model"][working_arc]))
|
|
|
+ new_value = integer_subtraction(read_attribute(model, working_place, "tokens"), read_attribute(model, working_arc, "weight"))
|
|
|
+ unset_attribute(model, working_place, "tokens")
|
|
|
+ instantiate_attribute(model, working_place, "tokens", new_value)
|
|
|
+ output(((" " + working_place) + ": ") + cast_i2s(read_attribute(model, working_place, "tokens")))
|
|
|
|
|
|
// Add tokens
|
|
|
- workset = allOutgoingAssociationInstances(model, reverseKeyLookup(model["model"], transition), "T2P")
|
|
|
+ workset = allOutgoingAssociationInstances(model, transition, "T2P")
|
|
|
while (0 < read_nr_out(workset)):
|
|
|
working_arc = set_pop(workset)
|
|
|
- working_place = read_edge_dst(working_arc)
|
|
|
- new_value = integer_addition(read_attribute(model, getName(model, working_place), "tokens"), read_attribute(model, getName(model, working_arc), "weight"))
|
|
|
- unset_attribute(model, getName(model, working_place), "tokens")
|
|
|
- instantiate_attribute(model, getName(model, working_place), "tokens", new_value)
|
|
|
- output(((" " + getName(model, working_place)) + ": ") + cast_i2s(read_attribute(model, getName(model, working_place), "tokens")))
|
|
|
+ working_place = getName(model, read_edge_dst(model["model"][working_arc]))
|
|
|
+ new_value = integer_addition(read_attribute(model, working_place, "tokens"), read_attribute(model, working_arc, "weight"))
|
|
|
+ unset_attribute(model, working_place, "tokens")
|
|
|
+ instantiate_attribute(model, working_place, "tokens", new_value)
|
|
|
+ output(((" " + working_place) + ": ") + cast_i2s(read_attribute(model, working_place, "tokens")))
|
|
|
output("Transition fired!")
|
|
|
else:
|
|
|
output("Cannot fire if not enabled; aborting")
|