Petri net: forgot to render inhibitor arcs (thanks Jason)

This commit is contained in:
Joeri Exelmans 2024-12-09 11:49:56 +01:00
parent da5856b33b
commit bef233a854
4 changed files with 35 additions and 2 deletions

View file

@ -0,0 +1,16 @@
# Inhibitor arc example
p0:PNPlace
p1:PNPlace
t0:PNTransition
:arc (p0 -> t0)
:arc (t0 -> p1)
t1:PNTransition
:arc (p1 -> t1)
:arc (t1 -> p0)
t2:PNTransition
:inh_arc (p0 -> t2)
:arc (t2 -> p0)

View file

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

View file

@ -42,5 +42,9 @@ def render_petri_net(od: ODAPI):
src_name = od.get_name(od.get_source(arc)) src_name = od.get_name(od.get_source(arc))
tgt_name = od.get_name(od.get_target(arc)) tgt_name = od.get_name(od.get_target(arc))
dot += f"{src_name} -> {tgt_name};" dot += f"{src_name} -> {tgt_name};"
for _, inhib_arc in od.get_all_instances("inh_arc"):
src_name = od.get_name(od.get_source(inhib_arc))
tgt_name = od.get_name(od.get_target(inhib_arc))
dot += f"{src_name} -> {tgt_name} [arrowhead=odot];\n"
show_graphviz(dot, engine="neato") show_graphviz(dot, engine="neato")
return "" return ""

View file

@ -27,8 +27,10 @@ if __name__ == "__main__":
mm_rt_cs = mm_cs + read_file('metamodels/mm_runtime.od') mm_rt_cs = mm_cs + read_file('metamodels/mm_runtime.od')
# m_cs = read_file('models/m_example_simple.od') # m_cs = read_file('models/m_example_simple.od')
# m_rt_initial_cs = m_cs + read_file('models/m_example_simple_rt_initial.od') # m_rt_initial_cs = m_cs + read_file('models/m_example_simple_rt_initial.od')
m_cs = read_file('models/m_example_mutex.od') # m_cs = read_file('models/m_example_mutex.od')
m_rt_initial_cs = m_cs + read_file('models/m_example_mutex_rt_initial.od') # m_rt_initial_cs = m_cs + read_file('models/m_example_mutex_rt_initial.od')
m_cs = read_file('models/m_example_inharc.od')
m_rt_initial_cs = m_cs + read_file('models/m_example_inharc_rt_initial.od')
# Parse them # Parse them
mm = loader.parse_and_check(state, mm_cs, scd_mmm, "Petri-Net Design meta-model") mm = loader.parse_and_check(state, mm_cs, scd_mmm, "Petri-Net Design meta-model")