## 3 Methodology--Mathematical Modelling and Heuristic Optimization Method
#### 3.2.1 Black Hole Optimization-Based Clustering
\begin{table}
\begin{tabular}{c c c c c c c} \hline \hline \multirow{2}{*}{**Tasks**} & \multicolumn{2}{c}{**Relation**} & \multirow{2}{*}{**Loading**} & \multirow{2}{*}{**Tasks**} & \multicolumn{2}{c}{**Relation**} & \multirow{2}{*}{**Loading**} \\ \cline{2-2} \cline{5-7}  & **From** & & & & **From** & **To** & \\ \hline
**6** & 1 & 4 & 3 & **4** & 16 & 20 & 3 \\
**2** & 31 & 35 & 8 & **11** & 7 & 14 & 7 \\
**10** & 14 & 20 & 9 & **12** & 23 & 27 & 9 \\
**3** & 28 & 29 & 2 & **9** & 2 & 4 & 5 \\
**8** & 22 & 33 & 8 & **5** & 32 & 36 & 9 \\
**1** & 6 & 11 & 4 & **7** & 3 & 8 & 2 \\ \hline \hline \end{tabular}
\end{table} 
Table 6: Results of clustering. \begin{table}
\begin{tabular}{c c c c c c} \hline \hline \multirow{2}{*}{**Tasks**} & \multicolumn{2}{c}{**Relation**} & \multicolumn{2}{c}{**Time Frame Limit**} & \multirow{2}{*}{**Loading**} \\ \cline{2-2} \cline{5-7}  & **From** & & **To** & **Lower** & **Upper** \\ \hline
1 & 6 & 11 & 9:10 & 9:50 & 4 \\
2 & 31 & 35 & 9:00 & 10:00 & 8 \\
3 & 28 & 29 & 9:15 & 10:10 & 2 \\
4 & 16 & 20 & 9:35 & 10:20 & 3 \\
5 & 32 & 36 & 10:15 & 10:35 & 9 \\
6 & 1 & 4 & 9:05 & 9:35 & 3 \\
7 & 3 & 8 & 9:32 & 10:00 & 2 \\
8 & 22 & 33 & 9:40 & 10:25 & 8 \\
9 & 2 & 4 & 9:45 & 10:30 & 5 \\
10 & 14 & 20 & 9:20 & 9:55 & 9 \\
11 & 7 & 14 & 9:55 & 10:30 & 7 \\
12 & 23 & 27 & 9:12 & 9:45 & 9 \\ \hline \hline \end{tabular}
\end{table} 
Table 5: Input parameters of the sensitivity analysis. Figure 12: Clustered and sequenced supply-demands in scenario 1. If the objective function of the extended clustering and routing problem is the minimization of the empty routes, then the energy efficiency can be minimized, but the time frame deviance is too high and some supply-demands cannot be performed within the lower and upper limit of the predefined time frame. The minimization of the length of empty routes can be performed in the case of one route, which means that the available loading capacity of AGV must be higher than in the case of scenarios 1 and 2. In the case of scenario three, the total length of the empty routes is 2948.7 m, while the required AGV's capacity is 69 LU and the total time frame deviance is 192 min. The key functionality of the algorithm has been explained. Figures 14 and 15 show the pseudocode of the algorithm because the details of the software engineering part would be interesting for anyone aiming to replicate the implementation. **Input:** number of stars, objective function, constraints, sign restrictions, termination criteria  
**Output:** optimal clustering  
//Initialization  
1 generate feasible solutions randomly in the n-dimensional search space (30)  
//Pre-evaluation  
2 for each star, evaluate the objective function (1-4, 31)  
//Loop until the termination criteria satisfy  
**While** (termination criteria satisfy) **do**  
//Selection of the black hole  
3 select the best star that has the best value to become a black hole (32)  
//Hawking radiation  
4 change the position of the black hole (33)  
//movement of stars towards the black hole  
5 move the stars towards the black holes (35) while constraints (equations 5-8) are taken into consideration  
//Check the position of stars  
Six if a star is inside the event horizon  
absorb the star and generate a new one in the search space  
end if  
//Evaluation  
7 for each star, evaluate the objective function (1-4, 31)  
**End of while**  
**Figure 14.** Pseudocode of the implementation of black hole algorithm for clustering of supply-demand in the extended phase of logistics resource optimization. Figure 13. Clustered and sequenced supply-demands in scenario 2. Results from the Scenario Analysis of Extended and Real-Time Logistics Resource Optimization in Matrix Production  
Within the frame of this chapter, a scenario analysis demonstrates the application possibilities of the above described mathematical model and validates the applied heuristic optimization algorithm. The scenario is simplified to make examples as perspicuous as possible.