1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*!
This module provides a set of traits for modeling and analyzing various forms of place/transition or Petri nets.
A Petri net is a graphical and mathematical modeling tool. The concept of Petri nets has its origin in Carl Adam Petri's
dissertation "*Kommunikation mit Automaten*", submitted in 1962 to the faculty of Mathematics and Physics at the
Technische Universität Darmstadt, Germany.
Petri nets are a well-used tool for describing and studying systems that are characterized as being concurrent,
asynchronous, distributed, parallel, nondeterministic, and/or stochastic. As a graphical tool, Petri nets can be used as
a visual-communication aid similar to flow charts, block diagrams, and networks. In addition, tokens are used in these
nets to simulate the dynamic and concurrent activities of systems. As a mathematical tool, it is possible to set up
state equations, algebraic equations, and other mathematical models governing the behavior of systems.
## Definitions
A Net \\(N\\) consists of a tuple of *places* (the set \\(P\\)), *transitions* (the set \\(T\\)), and *arcs* (the set
\\(A\\)) that connect them. Note that arcs are historically known as *flow relations* and the set is named \\(F\\).
$$\tag{Net} N = \left\langle P,T,A \right\rangle$$
The sets of places \\(P\\) and transitions \\(T\\) are disjoint.
$$ P \cap T = \emptyset$$
Arcs are a directed connection between a place/transition pair. We will use the notation \\(\overset{a}{\leftarrow}\\)
for the source end and \\(\overset{a}{\rightarrow}\\) for the target end of an arc \\(a\\).
$$\tag{Net Arc} A = \left(P \times T \right) \cup \left(T \times P \right)$$
*Input arcs* connect a source place to a target transition.
$$\tag{Input Arc} a_{in} = \left \\{ a \in A | \overset{a}{\rightarrow} \in T \right \\}$$
$$ a_{in}(t) = \left \\{ a \in A | \overset{a}{\rightarrow} = t \right \\}$$
The set of *input places* for a transition \\(t\\) is called its *preset* or \\({}^{\bullet}t\\).
$$\tag{Preset} {}^{\bullet}t = \left \\{ p \in P | A(p,t) \right \\}$$
*Output arcs* connect a source transition to a target place.
$$\tag{Output Arc} a_{out} = \left \\{ a \in A | \overset{a}{\leftarrow} \in T \right \\}$$
$$ a_{out}(t) = \left \\{ a \in A | \overset{a}{\leftarrow} = t \right \\}$$
The set of *output places* for a transition \\(t\\) is called its *postset* or \\(t^{\bullet}\\).
$$\tag{Postset} t^{\bullet} = \left \\{ p \in P | A(t,p) \right \\}$$
Places can contain *tokens*; the current state of the modeled system (termed the *marking function* \\(M\\)) is given by the
number of tokens in each place.
$$\tag{Marking Function} M: P \mapsto \mathbb{N}$$
The initial marking of a net is noted as \\(M_{im}\\) or more commonly \\(M_0\\). A *marked net* extends the Net tuple
with a particular marking \\(M\\).
$$\tag{Marked Net} N = \left\langle P,T,A,M \right\rangle$$
Transitions are active components. They model activities which can occur (the transition *fires*), thus changing the
state of the system (the marking of the Petri net). Transitions are only allowed to fire if they are *enabled*, which
means that all the preconditions for the activity must be fulfilled, i.e. there are enough tokens available in the input
places. For this check we use the undefined function \\(min\\) which can only be defined as we define the type of tokens
later.
$$\tag{Enabled Function} enabled\left(t \in T \right) = \forall p \in {}^{\bullet}t: min(A(p,t))$$
A net \\(N\\) is therefore enabled *iff* any transition in \\(N\\) is enabled.
$$enabled\left(N\right) \iff \exists t \in T: enabled\left(t\right)$$
When the transition fires, it removes tokens from its input places and adds some at all of its output places. The number
of tokens removed or added depends on the cardinality of each arc.
The firing of transitions in the marking \\(M_n\\) results in the new marking \\(M_{n+1}\\). The interactive firing of
transitions in subsequent markings is called the **token game**.
## Classification
This is a high-level classification of Petri Nets originally made by Monika Trompedeller in 1995, and is based on a
survey by L. Bernardinello and F. De Cindio from 1992. The classification has not been updated since then and is
therefore chiefly of historic interest. The classification is, however, useful for getting a quick overview of the main
differences between various kinds of Petri Nets.
* **Level 1**: nets characterized by places which can represent boolean values (\\(\mathbb{B}\\)), i.e., a place is
marked by at most one unstructured token.
* Condition/Event systems
* Elementary nets
* **Level 2**: nets characterised by Places which can represent positive integer values (\\(\mathbb{N^{+}}\\)), i.e.,
a place is marked by a number of unstructured tokens.
* Place/Transition systems
* (Ordinary) Petri nets
* Free choice systems
* S-Systems
* State Machines
* T-Systems
* Marked Graphs
* **Level 3**: nets characterised by Places which can represent high-level values, i.e., a place is marked by a
multi-set of structured tokens.
* Algebraic Petri nets
* Product nets
* Traditional High-Level nets
* Predicate/Transition Petri nets
* Colored Petri nets
* Well-Formed nets
* Regular nets
## Extensions
Note that the table below uses \\(\mathbb{B}\\) to represent the set of boolean values \\(\left\\{ \bot,\top \right \\}\\).
| Name | Abbreviation | Token Type | Arc Weight | Place Capacities | Timed | Stochastic | Level |
|-------------------|--------------|------------------------------|------------|------------------|-------|------------|-------|
| Elementary net | EN | \\(M(p)\in \mathbb{B}\\) | No | No | No | No | 1 |
| Petri net | PN | \\(M(p)\in \mathbb{N^{+}}\\) | Yes | No | No | No | 2 |
| Colored Petri net | CPN | \\(M(p)\in C\\) | Yes | Yes | No | No | 3 |
## Restrictions
Instead of extending the Petri net formalism, we can also look at restricting it, and look at particular types of Petri
nets, obtained by restricting the syntax in a particular way.
For example Ordinary Petri nets are the nets where all arc weights are 1 and all place capacity is infinite.
$$\tag{PN Restriction} \forall p\in P: K(p) = \infty \land \forall a\in A: W(a) = 1$$
Restricting further, the following types of ordinary Petri nets are commonly used and studied.
In a *state machine* (SM), every transition has one incoming arc, and one outgoing arc, and all markings have exactly
one token. As a consequence, there can not be **concurrency**, but there can be **conflict** (i.e. nondeterminism).
$$\tag{SM Restriction} \forall t\in T: |t^{\bullet}|=|{}^{\bullet} t|=1$$
In a *marked graph* (MG), every place has one incoming arc, and one outgoing arc. This means, that there can **not** be
**conflict**, but there can be **concurrency**.
$$\tag{MG Restriction} \forall p\in P: |p^{\bullet}|=|{}^{\bullet} p|=1$$
In a *free choice* net (FC), every arc from a place to a transition is either the only arc from that place or the only arc
to that transition, i.e. there can be **both concurrency and conflict**, but **not at the same time**.
$$\tag{FC Restriction} \forall p\in P: (|p^{\bullet}|\leq 1) \vee ({}^{\bullet} (p^{\bullet})=\\{p\\})$$
A free choice net is an *S-system* iff its underlying net is an S-net.
$$\tag{S-net} \forall t\in T: |{}^{\bullet}t| \le 1 \land |t^{\bullet}| \le 1$$
A free choice net is a *T-system* iff its underlying net is a T-net. In a T-System there is never any conflict because
there are no (forward) branched places.
$$\tag{T-net} \forall p\in P: | {}^{\bullet}p | \le 1 \land | p^{\bullet} | \le 1$$
*Extended free choice* (EFC) – a Petri net that can be **transformed into** an FC.
In an *asymmetric choice net* (AC), concurrency and conflict (in sum, **confusion**) may occur, but **not symmetrically**.
$$\tag{AC Restriction} \forall p_1,p_2\in P: (p_1{}^{\bullet} \cap p_2{}^{\bullet} \neq \emptyset) \to [(p_1{}^{\bullet} \subseteq p_2{}^{\bullet}) \vee (p_2{}^{\bullet} \subseteq p_1{}^{\bullet})]$$
*/
use ;
// ------------------------------------------------------------------------------------------------
// Public Types Common
// ------------------------------------------------------------------------------------------------
pub type NodeIdValue = u64;
///
/// A node identifier is a numeric value assigned by the Net implementation and which is guaranteed
/// unique across node types (and arcs if they are identified).
///
;
///
/// The trait implemented by Net nodes that have a Net-assigned identity.
///
///
/// A label is a human-readable and generally descriptive text that helps the readability of Net
/// representations.
///