# Model Predictive Control for Flexible Job Shop Scheduling in Industry 4.0 +
## 3 Model Generation
### Generation of the Discrete Time Petri Net Model
To arrive at this description, the JSON files are parsed with a simple Matlab script and the relevant information are deduced. We consider the resource constraints (R5), meaning that not all machines can execute every task, and the precedence constraints (R1) among the tasks of the same job and the production times \(t_{\text{P}}(M,\tau)\), which are already given as a number of production steps \(k_{\text{P}}(M,\tau)\) in the JSON files. From the problem description deduced from the JSON files, the Petri Net descriptions are generated with the Algorithms 1 and 2 implemented in Matlab, and their state space descriptions are used to formulate the MPC problems (16). For simulation of the manufacturing systems with the MPC in closed loop, we use Matlab R2019b on a ThinkPad L390 Yoga with an Intel(r) Core(tm)i5-8265U CPU. As solver for the MILP (16) we use intlinprog, which is a standard solver for mixed integer linear programs in Matlab. The problems are initialized with all tasks of all jobs being necessary and none of them being completed. As no cost function is given in the JSON file, we choose a linear cost function \(c(x,u)=c_{x}^{\top}x+c_{u}^{\top}u\) that weights every token in a starting places with 2, every token in a production places with 5, every token in a buffer places with 1, every token in a necessity places with 1, and every token in a completion places with 0. The cost of firing any transition is 1. This cost function fulfills the condition (18) for every operation \(O\). In every starting state \(x^{O,S}\), a necessity place is marked with one token, and in every resulting state \(x^{O,C}\) that can be reached by executing the operation \(O\) through firing a transition \(u_{T}\in\mathbb{U}_{O,S}\), this token is moved to a completion place. This results in a cost decrease of \(c(x^{O,S},0)-c(x^{O,C},0)=1\) between the states \(x^{O,S}\) and \(x^{O,C}\). With Corollary 1, for every operation \(O\) there exists an extended prediction horizon \(N_{O}^{+}\) for which it is guaranteed to be completed. Therefore, if a sufficiently large extended prediction horizon \(N^{+}\) is used, the MPC (16) is guaranteed to complete the production problem in closed loop according to Corollaries 2 and 3. The small-sized scheduling problem \"sops1.json\" has \(n_{M}=3\) machines, \(n_{\tau}=9\) tasks and \(n_{I}=2\) jobs. The MPC (16) is parametrized with the prediction horizon \(N=1\) and the extended prediction horizon \(N^{+}=400\). The simulation time that the MPC needs to complete the scheduling problem \"sops1.json\" in closed loop is approximately 13 s and the resulting makespan is 274 time steps. The Gantt chart of the resulting closed loop schedule is given in Figure 4.

The medium-sized scheduling problem \"mops1.json\" has \(n_{M}=8\) machines, \(n_{\tau}=39\) tasks and \(n_{I}=5\) jobs. The MPC is parametrized with the prediction horizon \(N=1\) and the extended prediction horizon \(N^{+}=500\). It takes approximately 35 min to simulate the MPC in closed loop for the 786 time steps that it needs to complete the production problem. The Gantt chart of the closed loop schedule determined by the MPC is shown in Figure 5.

Figure 4: Gantt chart of the closed loop schedule for the small sized scheduling problem “sops1.json” [37], resulting from the application of the MPC (16). The simulation results are not directly comparable to the ones presented by [PERSON] et al. [37]. We do not consider the particularities of their setup; we consider a different optimization criterion and additionally we simulate the production system in closed loop, meaning that we solve many different optimization problems, whereas [PERSON] et al. [37] only determine one optimal schedule for the initial problem. The resulting average computation time of a single MPC optimization problem is slightly less than 50 milliseconds for the \"sops1.json\" and approximately 2.6 s for the \"mops1.json\".