# Model Predictive Control for Flexible Job Shop Scheduling in Industry 4.0 +
## 3 Model Generation
### Generation of the Discrete Time Petri Net Model
The production transitions \(T_{(M,M,\tau,\tau,J,P_{i})}\), which are created in the lines 8 and 9, implement the production process as a sequence of production steps, similar to Figure 1a, as illustrated in Figure 3. They move tokens from one production place \(P_{(M,\tau,I,P_{i})}\), \(q\in[1,k_{\mathrm{P}}(M,\tau)-1]\) to the next production place \(P_{(M,\tau,J,P_{i+1})}\) and are implemented as independent transitions. The finishing transitions \(T_{(M,M,\tau,\tau,J,F)}\) are created in lines 10 and 11 and have the form of a splitting similar to Figure 1c. They are considered to be independent as well. They consume the token from the last production place and return a token to the idle place \(P_{(M,0,0,I)}\) of the machine \(M\) that finishes the production and store the semi-finished product in its output buffer \(P_{(M,\tau,I,B)}\). Finally, they set the task \(\tau\) completed by creating a token in the completion place \(P_{(0,\tau,I,C)}\). The state space description of the Petri Net in the form of the Equations (3) and (4) is created as introduced in Section 3.2. First, the initial state \(x^{0}\) is initialized by assigning the initial markings of all places to it. The effects of the production and finishing transitions are represented in the matrix \(A\). Starting from an identity matrix \(I\), for every production transition \(T_{(M,M,\tau,\tau,I,P_{i})}\) the diagonal entry corresponding to its input place \(P_{(M,\tau,J,P_{i})}\) is set to zero and a one is introduced in the same column in the line corresponding to its output place \(P_{(M,\tau,I,P_{i+1})}\). The result is similar to matrix \(A_{(a)}\) in Example 1. For every finishing transition \(T_{(M,M,\tau,\tau,J,F)}\), the diagonal entry corresponding to its input place \(P_{(M,\tau,I,P_{i}(M,\tau))}\) is set to zero and ones are introduced in the same column in the lines corresponding to its output places \(P_{(M,\tau,I,B)}\), \(P_{(M,0,0,I)}\), and \(P_{(0,\tau,I,C)}\). The result is similar to matrix \(A_{(c)}\) in Example 1. Figure 3: Illustration of the production sequences for the execution of task \(\tau^{\prime}\) of job \(J\) on machine \(M^{\prime}\) as it is generated in the Algorithms 1 and 2, with \(a=(M,M^{\prime},\tau,\tau^{\prime},J)\) and \(b=(M^{\prime},M^{\prime},\tau^{\prime},\tau^{\prime},J,P)\). The tokens in the sequence are depicted as they are initialized in Algorithm 1. As at initialization no task \(\tau\) or \(\tau^{\prime\prime}\) is already completed, the places \(P_{(M,\tau,J,B)}\) and \(P_{(0,\tau^{\prime\prime},J,C)}\) are not marked and the transition \(T_{(M,M^{\prime},\tau,\tau^{\prime},J,S)}\) is not enabled. For every starting transition \(T_{(M,M^{\prime},\tau,\tau^{\prime},J,S)}\), a column is added to the matrix \(B\) through the matrices \(B^{+}\) and \(B^{-}\) as defined in Equation (1). The new columns in \(B^{+}\) and \(B^{-}\) are initialized with zeros. In \(B^{-}\) a one is introduced in the lines corresponding to the input places \(P_{(0,\tau^{\prime},J,N)}\), \(P_{(M^{\prime},0,0,I)}\), and \(P_{(M,\tau,I,B)}\). The precedence relations among different tasks, which are considered through arcs from the completion places of other tasks \(\tau^{\prime\prime}\), lead to further ones in the lines corresponding to possibly multiple places of the form \(P_{(0,\tau^{\prime\prime},J,C)}\). In \(B^{+}\) a one is introduced in the line corresponding to the first production place \(P_{(M^{\prime},\tau^{\prime},I,P_{1})}\) and further ones are introduced in the lines corresponding to the completion places \(P_{(0,\tau^{\prime\prime},J,C)}\) of the precedence relation, in order to keep their marking constant. Note that directly creating the matrix \(B\) and omitting the matrices \(B^{+}\) and \(B^{-}\) would make the completion places obsolete and cancel out their effect. Additionally, the matrix \(B^{-}\) is required to formulate the non-negativity constraint (3). The input vector \(u\) has one entry for every starting transition.