PT connection syntax¶
Starting from v0.4.0, SoyutNet supports a simpler syntax for connecting
places and transitions by overloading operators >>, <<, >, <.
Graph format¶
Places are represented by circles with labels \(p_i\).
Transitions are represented by boxes with labels \(t_i\).
- Arcs are arrows with labels in the form of ‘\(w ~ \{l_1, l_2, \dots \}\)’.
\(w\) is the weight of arc.
\(\{l_i\}\) is the arc labels meaning that a particular arc accepts tokens with a label in the set \(\{l_i\}\).
If arc has no label, then it has the default label ‘\(1 \{0\}\)’.
Single branch examples¶
assert t1 == p1 >> t1
assert t1 == t1 > p1
assert p3 == (p1 >> t1 >> p2 >> t2 >> p3)
assert p1 == (p1 > (t1 > (p2 > (t2 > p3))))
assert p1 == (p3 << t2 << p2 << t1 << p1)
assert p3 == (p3 < (t2 < (p2 < (t1 < p1))))
assert p3 == (p3 > (t2 >> p2 >> t1 >> p1 >> t3))
_ = net.Arc()
assert p3 == (p1 >> _ >> t1 >> _ >> p2 >> t2 >> _ >> p3)
_ = net.Arc()
assert p1 == (p3 << _ << t2 << _ << p2 << _ << t1 << _ << p1)
_ = net.Arc()
assert t2 == (p1 > _ > t1 > _ > p2 > _ > t2 > _ > p3)
_ = net.Arc()
assert t1 == (p3 < _ < t2 < _ < p2 < _ < t1 < _ < p1)
_ = net.Arc(weight=3, labels=[1, 2])
assert t1 == (p3 < _ < t2 < _ < p2 < _ < t1 < _ < p1)
Multiple branch examples¶
_ = net.Arc(weight=2)
assert p2 == (p1 >> _ >> t1 >> p2)
assert p3 == (t1 >> p3)
_ = net.Arc(weight=2)
assert t1 == (p1 >> _ >> t1 > {
p2,
p3,
})
_ = net.Arc(weight=2)
assert t1 == (p1 >> _ >> t1 > {
p3 << t2 << p2,
p3,
})
assert p1 == (((p1 > t1) > t2) > t3)
assert p2 == (t1 >> p2)
assert p3 == (t2 >> p3)
assert p4 == (t3 >> p4)
assert p1 == (((p1 > {t1 > p2}) > {t2 > p3}) > {t3 > p4})
_ = net.Arc(weight=2)
assert t1 == (p1 >> _ >> t1 > {
p2 > (t2 > (p3 > (t4 > p4))),
p3,
})
a1 = net.Arc(labels=[1])
a2 = net.Arc(labels=[2])
a = net.Arc(labels=[1, 2], weight=2)
assert t1 == (p1 >> a >> {
t1 > a1 > p2,
t1 > a2 > p3,
})
a = lambda x: net.Arc(labels=[x])
_ = net.Arc(labels=[1, 2, 3], weight=4)
assert p1 == (p1 >> _ >> {
t1 > a(1) > {
p2 > a(1) > {t2 > a(1) > p4},
p3 > a(2) > {t2 > a(2) > p5},
},
t1 > a(2) > {
p3 > a(1) > {t3 > a(1) > p4},
},
}) >> a(3) >> p1