# Model Predictive Control for Flexible Job Shop Scheduling in Industry 4.0 +
## 3 Model Generation
### Generation of the Discrete Time Petri Net Model
In order to achieve a good performance with respect to a given cost function \(c\), the system needs to be influenced in a way such that the resulting cost summed up over time is minimal. In the sense of MPC, we formulate this goal as a finite horizon optimal control problem over the prediction horizon \(N\), which is repeatedly solved in a rolling horizon fashion [14]. It is initialized at each time instant \(k\) with the most accurate knowledge about the system, which is the state \(x(k)\) that we assume to be known or measured. This assumption is justified by the concept of the digital twin introduced in Section 1. The optimization problem to determine the MPC control law at time instant \(k\) is formulated as

\[\underset{u(\cdot|k)}{\text{minimize}} \sum_{k=0}^{N-1}c\left(x(\bar{k}|k),u(\bar{k}|k)\right) \tag{6a}\] \[\text{subset to} x\left(\bar{k}+1|k\right)=Ax\left(\bar{k}|k\right)+Bu\left(\bar{k}|k\right)\] (6b) \[0\leq x\left(\bar{k}|k\right)-B^{-}u(\bar{k}|k)\] (6c) \[u\left(\bar{k}|k\right)\in\mathbb{N}^{m}\] (6d) \[x(0|k)=x(k). \tag{6e}\]

During the prediction, the PN dynamics (4) and the non-negativity of the states (3) need to be respected in the constraints (6b) and (6c). The planned input vectors \(u(\bar{k}|k)\) are only allowed to have non-negative integer values (6d), whereby also the predicted states \(x(\bar{k}|k)\) remain vectors of of non-negative integers and the tokens in the PN are moved in the intended direction. The optimization variables in the MPC problem are the inputs \(u(\bar{k}|k)\) of the planned input trajectory \(u(\cdot|k)=(x(0|k),\ldots,u(N-1|k))\). They allow to choose a new firing count vector \(u(\bar{k}|k)\) at every future time instant \(k+\bar{k}\) and represent potential decisions taken for the production process. The minimizer of (6a) in the MPC problem is the optimal input trajectory \(u^{*}(\cdot|k)\). The resulting optimal predicted state trajectory, which results from applying the inputs \(u^{*}(\cdot|k)\) starting from the initial state \(x(k)\), is denoted \(x^{*}(\cdot|k)\). The sum of the predicted cost is only minimized over a finite prediction horizon \(N\in\mathbb{N}_{>0}\) in Equation (6a). This is not only the common case in MPC, but also reasonable under the assumption that the production system changes over time due to unknown or uncertain external influences. Due to such disturbances, the predictions for the distant future are unlikely to be accurate. From the optimal input trajectory \(u^{*}(\cdot|k)\), only the first input \(u^{*}(0|k)\) is applied to the system, before the optimization is repeated with the newly measured state \(x(k+1)\) at the next time instant. The resulting nominal closed loop dynamics can be expressed as

\[x(k+1)=Ax(k)+Bu^{*}(0|k)=x(1|k),\qquad x(0)=x^{0}, \tag{7}\]

where a feedback mechanism is introduced through the repeated solution of the optimization problem (6). This inherent feedback mechanism is one of the key features of the presented approach compared with scheduling techniques from literature [22; 23]. It is necessary as, due to external influences and non-modeled effects, the state \(x(1|k)\), which was predicted for time \(k+1\) starting from \(x(k)\) and applying \(u^{*}(0|k)\), might be different from the true state \(x(k+1)\). Therefore, for the real closed loop it might be \(x(k+1)\
eq x(1|k)\). In order to provide a proof that the proposed MPC scheme leads to a desirable solution of the scheduling problem defined in Section 2, we first need to show important properties. Repeatedly applying the optimal input determined through a finite horizon optimal control problem such as (6) does not naturally lead to an optimal closed loop performance [58], which in our case is the completion of all jobs in the production problem in the best possible way. In fact, quite the opposite can be the case, and the MPC might not even start a single task if the MPC problem (6) is not formulated carefully and does not fulfill some required conditions.