# Model Predictive Control for Flexible Job Shop Scheduling in Industry 4.0 +
## 3 Model Generation
### Generation of the Discrete Time Petri Net Model
As it is assumed that no task in any job is already completed at initialization, the completion places are initialized unmarked whereas the necessity places hold one token indicating that the respective task needs to be executed once. ``` input :A set of machines \(\mathcal{M}\), a set of tasks \(\mathcal{T}\), a set of jobs \(\mathcal{J}\), a set of places \(\mathbb{P}\) output :A set of independent transitions \(\mathbb{T}_{I}\), a set of controlled transitions \(\mathbb{T}_{C}\), a set of arcs \(\mathbb{E}\)
1 forevery job \(J\in\mathcal{J}\)do
2 forevery task \(\tau\in\mathcal{T}_{I}\)do
3 forevery machine \(M\) with \(\tau\in\mathcal{T}_{M}\)do
4 if\(\mathcal{T}_{\tau}=\emptyset\)then
5 Add a starting transition \(T_{(0,M,0,\tau,I,S)}\) to \(\mathbb{T}_{C}\);
6 Add its input arcs \((P_{(0,\tau,I,N)},T_{(0,M,0,\tau,I,S)})\), \((P_{(M,0,0,I)},T_{(0,M,0,\tau,I,S)})\) and \((P_{(0,0,J,S)},T_{(0,M,0,\tau,I,S)})\) and its output arc \((T_{(0,M,0,\tau,I,S)},P_{(M,\tau,I,S,\tau)})\) to \(\mathbb{E}\);
7
8 end if
9 Add the production transitions \(T_{(M,M,\tau,I,P_{\tau})}\), \(q\in[1,k_{\mathbb{P}}(M,\tau)-1]\) to \(\mathbb{T}_{I}\);
10 Add their input arcs \((P_{(M,\tau,I,P_{\tau})},T_{(M,M,\tau,I,P_{\tau})})\) and their output arcs \((T_{(M,M,\tau,I,P_{\tau})},P_{(M,\tau,I,P_{\tau+1})})\) to \(\mathbb{E}\);
11 Add a finishing transition \(T_{(M,M,\tau,I,P_{\tau})}\) to \(\mathbb{T}_{I}\);
12 Add its input arc \((P_{(M,\tau,I,P_{\tau}(M,\tau,I,P)},T_{(M,M,\tau,I,F)})\) and its output arcs \((T_{(M,M,\tau,I,F)},P_{(M,\tau,I,B)})\), \((T_{(M,M,\tau,I,F)},P_{(M,\emptyset,I)})\) and \((T_{(M,M,\tau,I,F)},P_{(\emptyset,\tau,I,C)})\) to \(\mathbb{E}\);
13 forevery task \(\tau^{\prime}\in\mathcal{T}_{I}\)do
14 if\(\tau\
eq\tau^{\prime}\) and \(\tau^{\prime}\
otin\mathcal{T}_{\tau}\)and \(\{\tau^{*}\in\mathcal{T}_{I}:\tau\in\mathcal{T}_{\tau^{*}},\tau^{*}\in \mathcal{T}_{\tau^{\prime}}\}=\emptyset\)then
15 forevery machine \(M^{\prime}\) with \(\tau^{\prime}\in\mathcal{T}_{M^{\prime}}\)do
16 Add a starting transition \(T_{(M,M,\tau,\tau^{\prime},I,S)}\) to \(\mathbb{T}_{C}\);
17 Add its input arcs \((P_{(0,\tau^{\prime},I,N)},T_{(M,M,\tau,\tau^{\prime},I,S)})\), \((P_{(M,0,0,I)},T_{(M,M^{\prime},\tau,\tau^{\prime},I,S)})\) and \((P_{(M,\tau,I,B)},T_{(M,M^{\prime},\tau,\tau^{\prime},I,S)})\) and its output arc \((T_{(M,M,\tau,\tau^{\prime},I,S)},P_{(M,\tau^{\prime},I,B_{\tau})})\) to \(\mathbb{E}\);
18 forevery task \(\tau^{\prime\prime}\in\mathcal{T}_{\tau^{\prime}}\)do
19 Add the arcs \((P_{(0,\tau^{\prime},J,C)},T_{(M,M^{\prime},\tau,\tau^{\prime},I,S)})\) and \((T_{(M,M,\tau,\tau^{\prime},I,S)},P_{(0,\tau^{\prime},J,C)})\) to \(\mathbb{E}\);
20



task reserves the machine \(M\) that is used for its execution by consuming the token from the idle place \(P_{(M,0,0,I)}\). This guarantees that every machine is only used once at a time as required by Restriction (R6). By consuming the token from the necessity place \(P_{(0,\tau,I,N)}\), it is indicated that the task \(\tau\) will not be necessary any longer. The consumption of the token from the starting place \(P_{(0,0,I,S)}\) or the buffer place \(P_{(M,\tau,I,B)}\) reserves the semi-finished product of the job \(J\) and guarantees that only one task of every job is executed at a time, as required by Restriction (R7). Each starting transition that starts the execution of a task \(\tau^{\prime}\) consumes the token from all completion places \(P_{(0,\tau^{\prime\prime},J,C)}\) of the tasks \(\tau^{\prime\prime}\in\mathcal{T}_{\tau^{\prime}}\) that need to be finished before the task \(\tau^{\prime}\) can be started. Thereby it is guaranteed the task \(\tau^{\prime}\) can only be started once its precedence constraints according to Restriction (R1) are fulfilled. The tokens are immediately returned to the completion places such that their production status is preserved. Starting transitions create a token in the first production place \(P_{(M,\tau,I,P_{1})}\), indicating that the production starts.