rename types in Petri Net formalism to prevent naming collisions when merging with 'Port' formalism

This commit is contained in:
Joeri Exelmans 2024-11-22 15:20:16 +01:00
parent 6ac8e30747
commit 5962a476c0
10 changed files with 69 additions and 69 deletions

View file

@ -1,11 +1,11 @@
# Places, transitions, arcs (and only one kind of arc)
Connectable:Class { abstract = True; }
PNConnectable:Class { abstract = True; }
arc:Association (Connectable -> Connectable)
pn_arc:Association (PNConnectable -> PNConnectable)
Place:Class
Transition:Class
PNPlace:Class
PNTransition:Class
:Inheritance (Place -> Connectable)
:Inheritance (Transition -> Connectable)
:Inheritance (PNPlace -> PNConnectable)
:Inheritance (PNTransition -> PNConnectable)

View file

@ -1,13 +1,13 @@
# A place has a number of tokens, and that's it.
PlaceState:Class
PlaceState_numTokens:AttributeLink (PlaceState -> Integer) {
PNPlaceState:Class
PNPlaceState_numTokens:AttributeLink (PNPlaceState -> Integer) {
name = "numTokens";
optional = False;
constraint = `"numTokens cannot be negative" if get_value(get_target(this)) < 0 else None`;
}
of:Association (PlaceState -> Place) {
pn_of:Association (PNPlaceState -> PNPlace) {
# one-to-one
source_lower_cardinality = 1;
source_upper_cardinality = 1;

View file

@ -2,29 +2,29 @@
# http://msdl.uantwerpen.be/people/hv/teaching/MoSIS/lectures/presentation.PetriNets.pdf
# page 51
general_1:Place
general_2:Place
critical_1:Place
critical_2:Place
semaphore:Place
general_1:PNPlace
general_2:PNPlace
critical_1:PNPlace
critical_2:PNPlace
semaphore:PNPlace
enterCritical_1:Transition
leaveCritical_1:Transition
enterCritical_2:Transition
leaveCritical_2:Transition
enterCritical_1:PNTransition
leaveCritical_1:PNTransition
enterCritical_2:PNTransition
leaveCritical_2:PNTransition
:arc (general_1 -> enterCritical_1)
:arc (semaphore -> enterCritical_1)
:arc (enterCritical_1 -> critical_1)
:pn_arc (general_1 -> enterCritical_1)
:pn_arc (semaphore -> enterCritical_1)
:pn_arc (enterCritical_1 -> critical_1)
:arc (critical_1 -> leaveCritical_1)
:arc (leaveCritical_1 -> semaphore)
:arc (leaveCritical_1 -> general_1)
:pn_arc (critical_1 -> leaveCritical_1)
:pn_arc (leaveCritical_1 -> semaphore)
:pn_arc (leaveCritical_1 -> general_1)
:arc (semaphore -> enterCritical_2)
:arc (general_2 -> enterCritical_2)
:arc (enterCritical_2 -> critical_2)
:pn_arc (semaphore -> enterCritical_2)
:pn_arc (general_2 -> enterCritical_2)
:pn_arc (enterCritical_2 -> critical_2)
:arc (leaveCritical_2 -> semaphore)
:arc (leaveCritical_2 -> general_2)
:arc (critical_2 -> leaveCritical_2)
:pn_arc (leaveCritical_2 -> semaphore)
:pn_arc (leaveCritical_2 -> general_2)
:pn_arc (critical_2 -> leaveCritical_2)

View file

@ -1,25 +1,25 @@
general_1_s:PlaceState {
general_1_s:PNPlaceState {
numTokens = 1;
}
general_2_s:PlaceState {
general_2_s:PNPlaceState {
numTokens = 1;
}
critical_1_s:PlaceState {
critical_1_s:PNPlaceState {
numTokens = 0;
}
critical_2_s:PlaceState {
critical_2_s:PNPlaceState {
numTokens = 0;
}
semaphore_s:PlaceState {
semaphore_s:PNPlaceState {
numTokens = 1;
}
:of (general_1_s -> general_1)
:of (general_2_s -> general_2)
:of (critical_1_s -> critical_1)
:of (critical_2_s -> critical_2)
:of (semaphore_s -> semaphore)
:pn_of (general_1_s -> general_1)
:pn_of (general_2_s -> general_2)
:pn_of (critical_1_s -> critical_1)
:pn_of (critical_2_s -> critical_2)
:pn_of (semaphore_s -> semaphore)

View file

@ -1,10 +1,10 @@
p0:Place
p1:Place
p0:PNPlace
p1:PNPlace
t0:Transition
:arc (p0 -> t0)
:arc (t0 -> p1)
t0:PNTransition
:pn_arc (p0 -> t0)
:pn_arc (t0 -> p1)
t1:Transition
:arc (p1 -> t1)
:arc (t1 -> p0)
t1:PNTransition
:pn_arc (p1 -> t1)
:pn_arc (t1 -> p0)

View file

@ -1,11 +1,11 @@
p0s:PlaceState {
p0s:PNPlaceState {
numTokens = 1;
}
:of (p0s -> p0)
:pn_of (p0s -> p0)
p1s:PlaceState {
p1s:PNPlaceState {
numTokens = 0;
}
:of (p1s -> p1)
:pn_of (p1s -> p1)

View file

@ -1 +1 @@
t:RAM_Transition
t:RAM_PNTransition

View file

@ -1,13 +1,13 @@
# A place with no tokens:
p:RAM_Place
ps:RAM_PlaceState {
p:RAM_PNPlace
ps:RAM_PNPlaceState {
RAM_numTokens = `get_value(this) == 0`;
}
:RAM_of (ps -> p)
:RAM_pn_of (ps -> p)
# An incoming arc from that place to our transition:
t:RAM_Transition
t:RAM_PNTransition
:RAM_arc (p -> t)
:RAM_pn_arc (p -> t)

View file

@ -1,19 +1,19 @@
t:RAM_Transition {
t:RAM_PNTransition {
condition = ```
# remove 1 token from every place connected with incoming arc
for incoming in get_incoming(this, "arc"):
for incoming in get_incoming(this, "pn_arc"):
in_place = get_source(incoming)
in_place_state = get_source(get_incoming(in_place, "of")[0])
in_place_state = get_source(get_incoming(in_place, "pn_of")[0])
in_num_tokens = get_slot_value(in_place_state, "numTokens")
set_slot_value(in_place_state, "numTokens", in_num_tokens - 1)
print("place", get_name(in_place_state), "now has", in_num_tokens-1, "tokens")
print("PNPlace", get_name(in_place_state), "now has", in_num_tokens-1, "tokens")
# add 1 token to every place connected with outgoing arc
for outgoing in get_outgoing(this, "arc"):
for outgoing in get_outgoing(this, "pn_arc"):
out_place = get_target(outgoing)
out_place_state = get_source(get_incoming(out_place, "of")[0])
out_place_state = get_source(get_incoming(out_place, "pn_of")[0])
out_num_tokens = get_slot_value(out_place_state, "numTokens")
set_slot_value(out_place_state, "numTokens", out_num_tokens + 1)
print("place", get_name(out_place_state), "now has", out_num_tokens+1, "tokens")
print("PNPlace", get_name(out_place_state), "now has", out_num_tokens+1, "tokens")
```;
}

View file

@ -24,18 +24,18 @@ def render_petri_net(od: ODAPI):
dot += "node[fontname=Arial,fontsize=10];\n"
dot += "subgraph places {"
dot += " node [shape=circle,fixedsize=true,label=\"\", height=.35,width=.35];"
for _, place_state in od.get_all_instances("PlaceState"):
place = od.get_target(od.get_outgoing(place_state, "of")[0])
for _, place_state in od.get_all_instances("PNPlaceState"):
place = od.get_target(od.get_outgoing(place_state, "pn_of")[0])
place_name = od.get_name(place)
num_tokens = od.get_slot_value(place_state, "numTokens")
dot += f" {place_name} [label=\"{place_name}\\n\\n{render_tokens(num_tokens)}\\n\\n­\"];\n"
dot += "}\n"
dot += "subgraph transitions {"
dot += " node [shape=rect,fixedsize=true,height=.3,width=.12,style=filled,fillcolor=black,color=white];\n"
for transition_name, _ in od.get_all_instances("Transition"):
for transition_name, _ in od.get_all_instances("PNTransition"):
dot += f" {transition_name} [label=\"{transition_name}\\n\\n\\n­\"];\n"
dot += "}\n"
for _, arc in od.get_all_instances("arc"):
for _, arc in od.get_all_instances("pn_arc"):
src_name = od.get_name(od.get_source(arc))
tgt_name = od.get_name(od.get_target(arc))
dot += f"{src_name} -> {tgt_name};"