ペトリネット

ペトリネットについて

ペトリネットは、離散事象システムにおける並行性・同期・リソースフローをモデリングするための基礎的な形式手法です。1962年に Carl Adam Petri が発明し、コンピュータサイエンス・制御工学・製造・ビジネスプロセスモデリングの分野で継続的に使用されています。記法はシンプルで一目でわかります。プレースは円、トランジションはバー、アークは重みを持ち、システムの動的状態はプレース上に散りばめられたトークンで表されます。

Schematex の petri エンジンがドラッグ&ドロップの形状ライブラリと異なるのは、動的挙動を理解している点です。マーキング(どのプレースにいくつのトークンがあるか)を知り、どのトランジションが有効(enabled)か(各入力プレースにアーク重み以上のトークンがある — 緑でハイライト)を計算し、トランジションを発火させて次のマーキングを生成できます。レンダリングはセマンティクスの下流にあります — pert がスケジューリングに対して取るのと同じスタンスです。状態図(トークン分布ではなく1つのアクティブ状態)、sfc(PLC 用の制限されたセーフペトリネット)、bpmn(トークンセマンティクスがワークフローペトリネットへの縮小によって定義される)とは明確に異なります。

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·10.6 ms·5.1 KB SVG

初期マーキングでは、T1 が有効です(入力の P1 と P4 がそれぞれトークンを持つ)ので緑のリングが付きます。T2 は有効ではありません(P2 が空)。P4 -> T1 のフィードバックアークはバックエッジカーブとしてルーティングされます。


1. はじめてのネット

すべてのドキュメントは petri キーワードと任意のタイトルで始まり、プレーストランジションを宣言してからアークで接続します。

petri "Minimal"
  place P1 *1
  transition T1
  place P2
  P1 -> T1
  T1 -> P2
  • place <id> — 円。*1 で初期トークン数(マーキング)を設定します。
  • transition <id> — バー(イベント/アクション)。
  • <a> -> <b> — 有向アーク。アークは二部構造です。すべてのアークはプレース→トランジションまたはトランジション→プレースの方向であり、プレース→プレースやトランジション→トランジションはありません。間違いを書くと、エンジンがどの行かを教えてくれます。

他の一部の Schematex 図とは異なり、ノードはアークから自動宣言されません — 未宣言の ID はプレースかトランジションかを安全に型付けできないためです。不明なノードへのアークは読みやすいエラーになります。


2. マーキングとトークン

マーキングは各プレースが持つトークンの数です。3つの等価な設定方法があります。

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

または marking: 行で複数のプレースをまとめて設定できます。

marking: P1=3, P3=2

トークンは点(4つまでグリッドにレイアウト)としてレンダリングされ、それ以上は数字で表示されます。tokens: dots | count | auto(デフォルト auto)でスタイルを強制できます。


3. トランジション:即時と時限

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

即時トランジションはゼロ時間で発火し、古典的な塗りつぶしバーとして描画されます。時限トランジション(GSPN の慣習)は中空のボックスとして描画され、オプションの rate:(λ)を持ちます。rate: を持つトランジションは自動的に時限として扱われます。prio: n で優先度を設定し、[guard] はラベルとして描画されます(v0.1 では評価されません)。


4. アークの種類

4種類のアークヘッドが標準的な並行性の語彙をカバーします。

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)

抑制アークとリセットアークはプレース→トランジションのみ — パーサーは逆方向を拒否します。


5. 容量

プレースに上限を設定できます。それを超えようとする発火は無効になり、プレースは破線の境界線と K=n ラベルで描画されます。

place Buffer capacity: 3

6. 動的挙動:有効化と発火

エンジンはすべてのレンダリングでセマンティクスを計算します。

  • **有効(Enabled)**なトランジション(すべての入力が満たされ、抑制入力が空で、出力が容量を超えない)は緑のリングを持ちます。
  • デッドトランジション — 現在のマーキングから決して発火できないもの — はミュートされます。
  • fire: 行は発火シーケンスを再生し、結果として生じるマーキングをレンダリングします。
petri
  place P1 *1
  transition T1
  place P2
  transition T2
  place P3
  P1 -> T1
  T1 -> P2
  P2 -> T2
  T2 -> P3
  fire: T1

T1 を発火させると、トークンが P1 → P2 に移動し、今度は T2 が有効なトランジションになります。SVG の <desc> にマーキング、有効セット、および検出されたサブクラス(状態機械 / マークドグラフ / ワークフローネット)が記録されます。


7. レイアウトとテーマ

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

プレースとトランジションは交互のレイヤーに自動的に配置されます。サイクルが検出され、そのフィードバックアークはバックエッジカーブとしてルーティングされます。3つのテーマ:

  • default — ハウスのブルーグレー、有効には緑、抑制には赤が予約されています。
  • monochrome — 忠実な Murata-1989 テキストブックの見た目。有効は二重の黒いリングで表示されます(色はなく形状で区別)。
  • dark — Catppuccin Mocha。

CJK ラベルと 「…」 / "…" の引用符はクリーンにパースされます。

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

完全な仕様:ペトリネット標準リファレンス


関連サンプル

サンプルギャラリーから使用可能なシナリオ:

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

Found this useful?

Schematex is free, fully open source, and zero-dependency. A star helps other developers discover it.