# Dynamic Optimization of Data Packet-based Communication for PLC Visual Monitoring
## 2 Dynamic Optimization of Data Packet-based Communication for PLC Visual Monitoring
### Descriptions of Data Packet-based Communication
To simplify the protocol design of the transmission, the load data size in a single packet can be bounded by the multiplication of the number of successive sub-networks \(P\) by its maximum data length \(L\) of sub-networks:  
\[S_{i}\leq S=PL \tag{8}\]  
Due to the complexity of industrial environments, there are sometimes transmission errors and packet losses. The probability that the \(i\)th packet needs to be re-transmitted is:  
\[p_{i}\leq p=\big{[}1-(1-\delta)^{d+PL}\big{]} \tag{9}\]  
If retransmission is needed under the constraints of Equations (6)-(9), the expected transmission time is then formulated as:  
\[E(T_{i})=T_{i}/(1-p_{i})\approx\big{[}T^{0}+(d+PL)/\rho\big{]}/\big{\{}1- \big{[}1-(1-\delta)^{d+PL}\big{]}\big{\}} \tag{10}\]  
With respect to the optimization model (4), a relaxed function for visual monitoring in the PLC communication design can now be transformed as:  
\[ \begin{array}{c}\min_{P}J(P)\triangleq\big{[}T^{0}+(d+PL)/\rho\big{]}(1- \delta)^{-(d+PL)}\cdot N/P\\ st.\;\;T^{0}+\frac{d+PL}{\rho}\leq T^{R},\;P\in\{1,2,\ldots,N\}\end{array}  \tag{11}\]  
Obviously, the objective function isn't in a strictly mathematical form duo to the ceiling function, and it is hardly possible to achieve the optimality through standard nonlinear optimization packages. However, an analytical solution will often fulfill the requirement in engineering practice. Let's consider a corresponding unconstrained minimization problem:  
\[\min_{P}F(P)\triangleq\big{[}T^{0}+(d+PL)/\rho\big{]}(1-\delta)^{-(d+PL)}\cdot N /P \tag{12}\]  
Through calculating the first-order derivative, its optimal solution can be located at:  
\[P^{0}=\frac{1}{2L}\bigg{[}-\big{(}d+T^{0}\rho\big{)}+\sqrt{\big{(}d+T^{0}\rho \big{)}^{2}+4(d+T^{0}\rho)L/ln^{-L}(1-\delta)}\bigg{]} \tag{13}\]  
\(P^{0}\) is not necessarily an integer. However, an integer solution should be obtained for industry applications. **Lemma 1. ** The optimized integer solution for the unconstrained optimization problem (12) is shown as follows:  
\[P^{\prime}=\left\{ \begin{array}{c}\big{[}P^{0}\big{]},\;if\;F\big{(}\big{[} P^{0}\big{]}\big{)}\leq F\big{(}\big{[}P^{0}\big{]}\big{)}\\ \big{[}P^{0}\big{]},\;otherwise\end{array} \right. \tag{14}\]Proof. : \(F(P)\) is monotonic decreasing, when \(P<P^{\prime}\); while it is monotonic increasing, when \(P>P^{\prime}\). Thus \(P^{\prime}\) gives the minimum solution. Next, let's consider the solution for the optimization problem (11). **Lemma 2**. : An optimized minimum solution of J(P) is given as  
\[P^{*}=Arg\underset{P\in D}{\text{min}}(P) \tag{15}\]  
Here the candidate set \(D\) is identified analytically below. Proof. : It is evident that \(F(P)\) is a lower bound of \(J(P)\), i.e., \(J(P)\geq F(P)\) for any positive \(P\). For a composite number \(N\), we define:  
\[D^{N}\triangleq\left\{P\left|\left[\frac{N}{P}\right]=\left[\frac{N}{P} \right],\ \forall P\in\{1,2,\ldots,N\}\right.\right. \tag{16}\]  
Similarly, for a prime number \(N\), we can obtain that \(\left[\frac{N}{P}\right]=\left[\frac{N+1}{P}\right]\), for \(P\in\{2,\ldots,N-1\}\). It means that \(J(P)\) remains the same for \(N\) or \(N-1\). Hence when \(N\) is a prime number, we assume that:  
\[D^{N}\triangleq D^{N+1}\cap[2,\ N-1] \tag{17}\]  
The objective \(J(P)\) and \(F(P)\) regarding \(N+1\) can be alternatively considered within \([2,\ N-1]\). It is worth noting that \(J(P)=F(P)\) for any \(P\in D^{N}\). Hence, the monotonicity for \(J(P)\) is the same as that of \(F(P)\) in the domain \(D^{N}\). Let's introduce:  
\[\left\{ \begin{array}{l}P^{\prime}_{L}=\ Arg\text{max}\Big{(}P\leq P^{\prime}, \ P\in D^{N}\Big{)}\\ P^{\prime}_{U}=\ Arg\text{min}\Big{(}P\geq P^{\prime},\ P\in D^{N}\Big{)}\end{array} \right. \tag{18}\]  
Referring to the monotonicity of \(F(P)\), it can be drawn that the minimum of \(J(P)\) lies within \(\left[P^{\prime}_{L},\ P^{\prime}_{U}\right]\). In addition, for a given integer \(c\), we define \(D^{N}_{c}\triangleq\left\{P\middle|\left[\frac{N}{P}\right]=c,\ P\in\{1,2, \ldots,N\}\right|\).