# Fog Computing Architecture for Load Balancing in Parallel Production with a Distributed MES
## 3 Materials and Methods
### Fog Computing as an Intelligent Intermediary Between MESs and Cloud
The time weight is obtained by multiplying \(x_{p}\) by the number of parts according to the type of part \(p\), the production time \(t_{p,m}\), according to the kind of part \(p\) in MPS\({}_{m}\), and the time weight \(\alpha\). The energy weighting is obtained in monetary units by considering the energy cost \(\gamma\) in kW/h, where \(e_{p,m}\) is the energy consumption according to the type of part \(p\) in MPS\({}_{m}\), and \(\beta\) is the weight of the energy consumed. It should be noted that (\(\alpha\), \(\beta\)) within the cost function behave as a \"trade-off;\" that is, they are adjustable  
Figure 4: Interoperable distributed architecture MESs-node and FC–Cloud. parameters that allow for the reflection of operational properties according to the logistical context of the companies. These values are not static but are defined by the plant manager based on actual conditions, such as variations in electricity rates, resource availability, failure rates, stock levels, environmental impact, and delivery requirements. In this case study, weights were assigned to energy consumption and the time it takes to manufacture a part, for example. In a scenario where the cost of energy rates increases, a greater weight could be assigned to energy weighting (\(\alpha>\beta\)), even if this leads to longer production times. This flexibility enables the load allocation to be tailored to specific strategic criteria for each industrial context. \[Cost_{m}=\underbrace{\sum_{p\in p}t_{p,m}\times x_{p}\times\alpha}_{Weighted\ time}+\underbrace{\sum_{p\in p}\left(\frac{e_{p,m}\times x_{p}}{1000} \times\gamma\right)}_{Weighted\ energy}\times\beta \tag{1}\]  
To avoid imbalance during FC node decision-making, a practical heuristic rule is established that adds up the costs above. This rule is characterized by a quick response and, above all, avoids complex calculations, a quality that prioritizes the performance of the FC node, which by default has limited resources. The heuristic rule facilitates the assignment of tasks to MESs based on a threshold that can be modified according to production needs. For example, if the cost of MES1 exceeds this limit, then the FC node will orchestrate the task to MES2 (Equation (2)), where \(C_{m}\) is the current load of the MPS\({}_{m}\) and \(C_{max}\) indicates the maximum capacity that the production lines can process using the MPSs. \[ \begin{split}&\textit{Assign to MES1 if : Cost}_{2}>\textit{heuristic threshold}\cdot Cost_{1}\ \wedge\ C_{1}+\sum x_{p}\leq C_{max}\\ &\textit{Assign to MES2 if : Cost}_{1}>\textit{heuristic threshold}\cdot Cost_{2}\ \wedge\ C_{2}+\sum x_{p}\leq C_{max}\end{split}  \tag{2}\]  
In case the heuristic threshold is executed and does not provide a clear answer for the allocation decision, which may occur when there is a balance in the costs of both MESs, the algorithm assigns the task to the MES with the lowest current load, see Equation (3); i.e., the algorithm asks, \"Where does the minimum cost occur?\" not \"What is the minimum cost?\" This ensures load balancing at the FC node. \[m^{*}=\underset{m\in\{1,2\}}{argmin}\ C_{m} \tag{3}\]  
where \(m^{*}\) represents the selected MES and \(argmin\ C_{m}\) is the argument of the minimum; that is, it looks for the MESm between (1 and 2) that has the lowest current load \(C_{m}\). Additionally, this algorithm is adaptable to incorporate several types of \(p\) pieces and to scale to the \(N\) MESs modules if required.