chap1.tex 9.06 KB
\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}