Schematex

Petri Net

About Petri nets

A Petri net is the foundational formalism for modelling concurrency, synchronisation, and resource flow in discrete-event systems — invented by Carl Adam Petri in 1962 and used continuously since across computer science, control engineering, manufacturing, and business-process modelling. The notation is small and instantly recognisable: a place is a circle, a transition is a bar, an arc carries a weight, and the dynamic state of the system is a sprinkle of tokens sitting in the places.

What makes Schematex's petri engine different from a drag-and-drop shape library is that it understands the dynamics. It knows a marking (which places hold how many tokens), computes which transitions are enabled (every input place has at least the arc weight of tokens — highlighted green), and can fire a transition to produce the next marking. The render is downstream of the semantics — the same stance pert takes toward scheduling. Distinct from state diagrams (one active state, not a token distribution), sfc (a restricted safe Petri net for PLCs), and bpmn (whose token semantics are defined by reduction to workflow Petri nets).

petri·§
↘ preview
100%
Petri net — Classic 4 places, 2 transitions, 7 arcs. Marking {P1:1, P3:2, P4:1}. Enabled: T1. Classic P1 P2 P3 P4 T1 T2
UTF-8 · LF · 14 lines · 151 chars✓ parsed·4.7 ms·5.1 KB SVG

Under the initial marking, T1 is enabled (its inputs P1 and P4 each hold a token) so it gets the green ring; T2 is not (P2 is empty). The P4 -> T1 feedback arc is routed as a back-edge curve.


1. Your first net

Every document starts with the petri keyword and an optional title, then declares places and transitions before connecting them with arcs:

petri "Minimal"
  place P1 *1
  transition T1
  place P2
  P1 -> T1
  T1 -> P2
  • place <id> — a circle. *1 sets its initial token count (the marking).
  • transition <id> — a bar (an event/action).
  • <a> -> <b> — a directed arc. Arcs are bipartite: every arc goes place→transition or transition→place, never place→place or transition→transition. If you write one wrong, the engine tells you which line.

Unlike some Schematex diagrams, nodes are not auto-declared from arcs — because an undeclared id can't be safely typed as a place or a transition. An arc that references an unknown node is a readable error.


2. Marking & tokens

The marking is how many tokens each place holds. Three equivalent ways to set it:

place P1 *3            # *n shorthand
place P2 tokens: 3     # explicit
place P3 •••           # literal dots (1–4)

Or set several at once with a marking: line:

marking: P1=3, P3=2

Tokens render as dots (up to 4, laid out in a grid) and as a numeral beyond that. Force one style with tokens: dots | count | auto (default auto).


3. Transitions: immediate vs timed

transition fast                 # immediate — a solid bar (the default)
transition slow timed rate: 0.8 # timed — a hollow box with a rate label λ

Immediate transitions fire in zero time and render as the classic filled bar; timed transitions (the GSPN convention) render as a hollow box and carry an optional rate: (λ). A transition with a rate: is treated as timed automatically. prio: n sets a priority, and a [guard] is rendered as a label (not evaluated in v0.1).


4. Arc types

Four arc heads cover the standard concurrency vocabulary:

P -> T              # standard arc (filled arrowhead)
P -> T weight: 2    # weight > 1 is labelled (weight: n or *n)
P -o T              # inhibitor — enabled only while the place is empty (hollow-circle head)
P -- T              # read / test — tests presence without consuming (no head)
P => T              # reset — empties the place when the transition fires (double head)

Inhibitor and reset arcs are place→transition only — the parser rejects the reverse direction.


5. Capacity

A place can be capped. Firing that would overflow it is disabled, and the place is drawn with a dashed border and a K=n label:

place Buffer capacity: 3

6. The dynamics: enabled & fire

The engine computes the semantics on every render:

  • Enabled transitions (every input satisfied; inhibitor inputs empty; no output would overflow capacity) get a green ring.
  • Dead transitions — those that can never fire from the current marking — are muted.
  • A fire: line replays a firing sequence and renders the resulting marking:
petri
  place P1 *1
  transition T1
  place P2
  transition T2
  place P3
  P1 -> T1
  T1 -> P2
  P2 -> T2
  T2 -> P3
  fire: T1

After firing T1, the token has moved P1 → P2, and now T2 is the enabled transition. The SVG <desc> records the marking, the enabled set, and any detected subclass (state machine / marked graph / workflow net).


7. Layout & themes

layout: lr     # left-to-right (default)
layout: tb     # top-to-bottom

Places and transitions land on alternating layers automatically; cycles are detected and their feedback arcs routed as back-edge curves. Three themes:

  • default — house blue-grey, with green reserved for enabled and red for inhibitor.
  • monochrome — the faithful Murata-1989 textbook look; enabled shows as a doubled black ring (colour falls back to shape).
  • dark — Catppuccin Mocha.

CJK labels and 「…」 / "…" quotes parse cleanly:

petri "生产流程"
  place 原料 *2 「原材料」
  transition 加工
  place 成品
  原料 -> 加工 weight: 2
  加工 -> 成品

Full specification: Petri Net Standard Reference.


Ready-to-use scenarios from the examples gallery:

petri·§ Murata 1989 + ISO/IEC 15909-1 (place/transition net)
Petri net — Classic 4 places, 2 transitions, 7 arcs. Marking {P1:1, P3:2, P4:1}. Enabled: T1. Classic P1 P2 P3 P4 T1 T2
The classic Petri net — concurrency with feedback
Murata's canonical place/transition net — one transition forks a token into two concurrent branches that a second transition joins, with a feedback place closing the loop. The engine marks which transitions are enabled in the current marking.
education
petri·§ Murata 1989 / ISO-IEC 15909-1 (place/transition net)
Petri net — Mutual Exclusion — two processes, one resource 5 places, 4 transitions, 12 arcs. Marking {idleA:1, idleB:1, mutex:1}. Enabled: enterA, enterB. Mutual Exclusion — two processes, one resource idleA A idle idleB B idle mutex resource critA A critical critB B critical enterA exitA enterB exitB
Mutual exclusion with a shared resource
The canonical concurrency pattern as a Petri net — two processes competing for a single Mutex token. Either process may enter its critical section, but the shared token guarantees they never do so at the same time. Both entry transitions show as enabled until one fires and consumes the resource.
industrial & process
petri·§ Murata 1989 (place/transition net firing rule)
Petri net — After fire: T1 3 places, 2 transitions, 4 arcs. Marking {P2:1}. Enabled: T2. Class: state machine, workflow net. After fire: T1 P1 P2 P3 T1 T2
Firing a transition advances the marking
The same three-place net before and after firing — the `fire:` directive replays a transition, so the rendered marking is the state *after* the token moved from P1 to P2, and the engine now highlights T2 as the newly enabled transition.
education
petri·§ van der Aalst 1998 workflow nets (a Murata place/transition net)
Petri net — Order workflow 6 places, 4 transitions, 10 arcs. Marking {in:1}. Enabled: split. Class: workflow net. Order workflow in received pick invoice packed billed out shipped split pack bill ship
Order-fulfilment workflow net (WF-net)
A van der Aalst workflow net — a single source place and single sink place bracket an AND-split/join that runs picking and invoicing concurrently before shipping. The engine detects the WF-net structure and reports it in the SVG description.
business & operations
petri·§ Murata 1989 + Marsan 1995 (GSPN timed transitions)
Petri net — Producer / Consumer (bounded buffer) 4 places, 2 transitions, 8 arcs. Marking {pReady:1, free:3, cReady:1}. Enabled: produce. Class: marked graph. Producer / Consumer (bounded buffer) pReady producer ready free free slots used used slots K=3 cReady consumer ready produce deposit consume withdraw λ=0.8
Producer / consumer with a bounded buffer
The bounded-buffer producer/consumer pattern as a Petri net — complementary free/used slot places enforce the buffer size, a timed withdraw transition models the consumer's rate, and place capacity caps the buffer at three slots. Tokens flowing through free→used→free show backpressure as a structural property.
industrial & process