chap1.tex
9.06 KB
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
\documentclass[multi={tikzpicture},crop=true,border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,arrows.meta,petri}
\tikzset{
>=latex,
every place/.style={minimum size=6mm},
every transition/.style={minimum size=6mm},
token distance=6pt,
}
\tikzstyle{trans}=[transition]
\tikzstyle{state}=[draw=blue!50!gray!50!white,
fill=blue!70!gray!10!white,
line width=2pt,
cloud,cloud puffs=8,
inner sep=-1pt]
\tikzstyle{fire}=[arrows={-Straight Barb[scale=.6]},
shorten >=-2pt, shorten <=-1pt,
draw=blue!50!gray!50!white,
line width=2pt,
line cap=round,
rounded corners]
\def\matrix #1#2#3#4{%
$\begin{array}{c@{\hspace{5pt}}c}
#1 & #2 \\
#3 & #4
\end{array}$}
\begin{document}
% Les réseaux de Petri
% Chapitre 1. Quoi ?
% Où l'on apprend ce que sont les réseaux de Petri.
%%%
% Ceci est une place.
\begin{tikzpicture}
\node[place] (p) at (0,0) {};
\end{tikzpicture}
% Une place peut contenir des jetons (ici 3).
\begin{tikzpicture}
\node[place,tokens=3] (p) at (0,0) {};
\end{tikzpicture}
% Ceci est une transition.
% Une transition ne peut pas contenir de jetons, non non.
\begin{tikzpicture}
\node[trans] (t) at (0,0) {};
\end{tikzpicture}
% Ceci est un arc.
\begin{tikzpicture}
\draw[->] (0,0) -- (1,0);
\end{tikzpicture}
% Un arc peut être décoré par un nombre entier (valant au moins 1).
% Quand on ne met pas de nombre, c'est qu'il vaut 1.
\begin{tikzpicture}
\draw[->] (0,0) -- node[above]{2} (1,0);
\end{tikzpicture}
% Un arc relie une place à une transition, ou l'inverse.
\begin{tikzpicture}[xscale=1.2]
\node[place,tokens=3] (p) at (0,0) {};
\node[trans] (t) at (1,0) {};
\draw[->] (p) -- node[above]{2} (t);
\node[trans] (u) at (0,-1) {};
\node[place] (q) at (1,-1) {};
\draw[->] (u) -- (q);
\end{tikzpicture}
% Mais un arc ne relie jamais deux places ou deux transitions.
% Jamais, jamais.
\begin{tikzpicture}[xscale=1.2]
\node[place,tokens=3] (p) at (0,0) {};
\node[place] (q) at (1,0) {};
\draw[->] (p) -- node[above]{2} (q);
\node[trans] (t) at (0,-1) {};
\node[trans] (u) at (1,-1) {};
\draw[->] (t) -- (u);
\node[forbidden sign,line width=5pt,draw=red,inner sep=6mm] at (.5,-.5) {};
\end{tikzpicture}
% Ceci est un réseau de Petri que nous appellerons Carl.
% Carl a une transition, deux places (l'une a trois jetons, l'autre
% zéro), et deux arcs.
\begin{tikzpicture}[xscale=1.2]
\node[place,tokens=3] (p) at (0,0) {};
\node[trans] (t) at (1,0) {};
\draw[->] (p) -- node[above]{2} (t);
\node[place] (q) at (2,0) {};
\draw[->] (t) -- (q);
\end{tikzpicture}
% Les transitions consomment et produisent des jetons dans les places,
% selon ce qu'indiquent les arcs.
% La transition de Carl peut consommer deux jetons dans la place de
% gauche et en produire un dans celle de droite (le 1 n'est pas
% indiqué puisque c'est 1 justement).
% Si elle le fait, on dit qu'on tire la transition.
%%%
% Ici, Carl a tiré sa transition. Deux jetons ont disparu de la place
% de gauche, et un a été ajouté dans celle de droite. Comme indiqué
% par les arcs.
\begin{tikzpicture}[xscale=1.2]
\node[place,tokens=1] (p) at (0,0) {};
\node[trans] (t) at (1,0) {};
\draw[->] (p) -- node[above]{2} (t);
\node[place,tokens=1] (q) at (2,0) {};
\draw[->] (t) -- (q);
\end{tikzpicture}
% Maintenant, Carl ne peut plus tirer sa transition, car elle ne peut
% pas consommer deux jetons dans la place de gauche qui n'en contient
% qu'un. Donc Carl est bloqué. (Pauvre Carl.)
%%%
% Voici un autre réseau de Petri, appelons le Adam. Comme il a
% beaucoup de places et de transitions, on leur donne des noms: a, b,
% c, d pour les places, et t, u, v, w pour les transitions.
\begin{tikzpicture}[scale=1.2]
\node[place,tokens=3] (a) at (0,0) {};
\node[left] at (a.west) {$a$};
\node[trans] (t) at (1,0) {$t$};
\draw[->] (a) -- node[above]{2} (t);
\node[place] (b) at (2,0) {};
\node[right] at (b.east) {$b$};
\draw[->] (t) -- (b);
\node[trans] (u) at (2,-1) {$u$};
\draw[->] (b) -- (u);
\node[place] (c) at (2,-2) {};
\node[right] at (c.east) {$c$};
\draw[->] (u) -- (c);
\node[trans] (v) at (1,-2) {$v$};
\draw[->] (c) -- (v);
\node[place] (d) at (0,-2) {};
\node[left] at (d.west) {$d$};
\draw[->] (v) -- node[above]{2} (d);
\node[trans] (w) at (0,-1) {$w$};
\draw[->] (d) -- (w);
\draw[->] (w) -- (a);
\end{tikzpicture}
% Adam a trois jetons dans sa place a, et aucun ailleurs. On appelle
% ça son marquage, c'est-à-dire le nombre de jetons dans chaque place.
% On peut le dessiner dans un petit nuage bleu.
\begin{tikzpicture}[scale=1.2]
\node[state] (s) at (1,-1) {\matrix 3000};
\node[place,tokens=3] (a) at (0,0) {};
\node[left] at (a.west) {$a$};
\node[trans] (t) at (1,0) {$t$};
\draw[->] (a) -- node[above]{2} (t);
\node[place] (b) at (2,0) {};
\node[right] at (b.east) {$b$};
\draw[->] (t) -- (b);
\node[trans] (u) at (2,-1) {$u$};
\draw[->] (b) -- (u);
\node[place] (c) at (2,-2) {};
\node[right] at (c.east) {$c$};
\draw[->] (u) -- (c);
\node[trans] (v) at (1,-2) {$v$};
\draw[->] (c) -- (v);
\node[place] (d) at (0,-2) {};
\node[left] at (d.west) {$d$};
\draw[->] (v) -- node[above]{2} (d);
\node[trans] (w) at (0,-1) {$w$};
\draw[->] (d) -- (w);
\draw[->] (w) -- (a);
\draw[|->,yellow,very thick,shorten >=-10pt] (a) -- (s.north west);
\draw[|->,yellow,very thick,shorten >=-10pt] (b) -- (s.north east);
\draw[|->,yellow,very thick,shorten >=-10pt] (c) -- (s.south east);
\draw[|->,yellow,very thick,shorten >=-10pt] (d) -- (s.south west);
\end{tikzpicture}
% Adam peut tirer sa transition t, ce qui enlèvera deux jetons dans a
% et en ajoutera un dans b. On obtient alors ce marquage.
\begin{tikzpicture}
\node[state] {\matrix 1100};
\end{tikzpicture}
% On peut représenter cette évolution entre deux marquages par un
% graphe.
\begin{tikzpicture}[scale=2]
\node[state] (0) at (0,0) {\matrix 3000};
\node[state] (1) at (1,0) {\matrix 1100};
\draw[fire] (0) -- node[above] {$t$} (1);
\end{tikzpicture}
% Et on peut prolonger ce graphe en tirant u, v, puis w.
\begin{tikzpicture}[scale=2]
\node[state] (0) at (0,0) {\matrix 3000};
\node[state] (1) at (1,0) {\matrix 1100};
\draw[fire] (0) -- node[above] {$t$} (1);
\node[state] (2) at (2,0) {\matrix 1001};
\draw[fire] (1) -- node[above] {$u$} (2);
\node[state] (3) at (3,0) {\matrix 1020};
\draw[fire] (2) -- node[above] {$v$} (3);
\node[state] (4) at (4,0) {\matrix 2010};
\draw[fire] (3) -- node[above] {$w$} (4);
\end{tikzpicture}
% À partir du dernier marquage atteint, on peut encore tirer w, et on
% retrouve alors le marquage départ.
\begin{tikzpicture}[scale=2]
\node[state] (0) at (0,0) {\matrix 3000};
\node[state] (1) at (1,0) {\matrix 1100};
\draw[fire] (0) -- node[above] {$t$} (1);
\node[state] (2) at (2,0) {\matrix 1001};
\draw[fire] (1) -- node[above] {$u$} (2);
\node[state] (3) at (3,0) {\matrix 1020};
\draw[fire] (2) -- node[above] {$v$} (3);
\node[state] (4) at (4,0) {\matrix 2010};
\draw[fire] (3) -- node[above] {$w$} (4);
\draw[fire] (4) |- node[near end,above] {$w$} +(-1,.5) -| (0);
\end{tikzpicture}
% Mais, hop hop hop, pas si vite... Au lieu de tirer w, on aurait
% aussi pu tirer t puisqu'il y a deux jetons dans a. Du coup, on
% obtient un branchement dans notre graphe.
\begin{tikzpicture}[scale=2]
\node[state] (0) at (0,0) {\matrix 3000};
\node[state] (1) at (1,0) {\matrix 1100};
\draw[fire] (0) -- node[above] {$t$} (1);
\node[state] (2) at (2,0) {\matrix 1001};
\draw[fire] (1) -- node[above] {$u$} (2);
\node[state] (3) at (3,0) {\matrix 1020};
\draw[fire] (2) -- node[above] {$v$} (3);
\node[state] (4) at (4,0) {\matrix 2010};
\draw[fire] (3) -- node[above] {$w$} (4);
\draw[fire] (4) |- node[near end,above] {$w$} +(-1,.5) -| (0);
\node[state] (5) at (1,-1) {\matrix 0110};
\draw[fire] (4) |- node[pos=.05,right] {$t$} +(-1,-1.5) -| (5);
\end{tikzpicture}
% On continue : à partir de chaque marquage, on tire toutes les
% transitions possibles. Et on obtient ce qu'on appelle le graphe de
% marquages.
\begin{tikzpicture}[scale=2]
\node[state] (0) at (0,0) {\matrix 3000};
\node[state] (1) at (1,0) {\matrix 1100};
\draw[fire] (0) -- node[above] {$t$} (1);
\node[state] (2) at (2,0) {\matrix 1001};
\draw[fire] (1) -- node[above] {$u$} (2);
\node[state] (3) at (3,0) {\matrix 1020};
\draw[fire] (2) -- node[above] {$v$} (3);
\node[state] (4) at (4,0) {\matrix 2010};
\draw[fire] (3) -- node[above] {$w$} (4);
\draw[fire] (4) |- node[near end,above] {$w$} +(-1,.5) -| (0);
\node[state] (5) at (1,-1) {\matrix 0110};
\draw[fire] (4) |- node[pos=.05,right] {$t$} +(-1,-1.5) -| (5);
\draw[fire] (5) -- node[left] {$w$} (1);
\node[state] (6) at (2,-1) {\matrix 0011};
\draw[fire] (5) -- node[above] {$u$} (6);
\draw[fire] (6) -- node[left] {$w$} (2);
\node[state] (7) at (3,-1) {\matrix 0030};
\draw[fire] (7) -- node[left] {$w$} (3);
\draw[fire] (6) -- node[above] {$v$} (7);
\end{tikzpicture}
% Revoyons cette action au ralenti...
% On remarque qu'Adam, contrairement à Carl, n'a aucun blocage.
% (C'est un réseau épanoui.)
%%%
% Notre chapitre 1 est maintenant terminé.
% À bientôt pour le chapitre 2: pourquoi ?
\end{document}