Browse Source

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

Joeri Exelmans 11 months ago
parent
commit
bef233a854

+ 16 - 0
examples/petrinet/models/m_example_inharc.od

@@ -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)

+ 11 - 0
examples/petrinet/models/m_example_inharc_rt_initial.od

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

+ 4 - 0
examples/petrinet/renderer.py

@@ -42,5 +42,9 @@ def render_petri_net(od: ODAPI):
         src_name = od.get_name(od.get_source(arc))
         tgt_name = od.get_name(od.get_target(arc))
         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")
     return ""

+ 4 - 2
examples/petrinet/runner.py

@@ -27,8 +27,10 @@ if __name__ == "__main__":
     mm_rt_cs        = mm_cs + read_file('metamodels/mm_runtime.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_cs            =         read_file('models/m_example_mutex.od')
-    m_rt_initial_cs = m_cs +  read_file('models/m_example_mutex_rt_initial.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_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
     mm           = loader.parse_and_check(state, mm_cs,           scd_mmm, "Petri-Net Design meta-model")