# IoT-Driven Intelligent Scheduling Solution for Industrial Sewing Based on Real-RCPSP Model
## 5 The Real-RCPSP Problem Applying in Automated Production Planning
### Planning Production Operations Using the Real-RCPSP Problem  
To coordinate production in each sewing line, we apply the Real-RCPSP problem using the digitized sewing line dataset in Table 5. Because Real-RCPSP is classified as an NP-Hard problem and cannot be solved in polynomial time, evolutionary algorithms are needed to determine the optimal schedule for each dataset. In this paper, we use the GA [3;4] and PSO [5;6] algorithms to schedule the execution of garment contracts (each contract is considered a project). GA is a traditional evolutionary algorithm that has been widely applied to solve complex problems. This algorithm undergoes evolution through many generations, with each generation going through selection, crossover, and mutation, thereby creating better individuals in subsequent generations. However, as a somewhat traditional algorithm, it has not seen many improvements and is not truly effective. This paper chooses the GA algorithm to experiment to verify the execution time of a garment contract according to the production plan established based on experience (represented by the PT column in Table 3) with the schedule generated by the GA algorithm. Details are presented in Algorithm 1. ```
Input:\(\text{t}_{\text{max}}\): the max of evolutionary generations Output the best particle: \(\text{P}_{\text{best}}\) Begin \(\text{P}_{\text{all}}\) = Load dataset and initial population \(\text{P}_{\text{best}}\) = \(\text{P}_{0}\) for (int gen = 0; gen < \(\text{t}_{\text{max}}\); gen++) { // Evaluate fitness of the population  foreach (var \(\text{P}_{\text{i}}\) in \(\text{P}_{\text{all}}\)) fitness(i) = f(P\({}_{\text{i}}\));  List<Individual> list = Selection(P\({}_{\text{all}}\));
``` \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline \multirow{2}{*}{**Datasets**} & \multirow{2}{*}{**TNG PT**} & \multicolumn{4}{c}{**GA**} & \multirow{2}{*}{**Deviation**} & \multirow{2}{*}{**\%**} \\ \cline{3-3} \cline{5-6}  & & **Avg** & & **Best** & & **Std** \\ \hline TNG1 & 409 & 309 & 302 & 4.5 & 107 & 26.16\% \\ TNG2 & 325 & 271 & 248 & 22.3 & 77 & 23.69\% \\ TNG3 & 296 & 265 & 251 & 11.1 & 45 & 15.20\% \\ TNG4 & 392 & 300 & 292 & 6.3 & 100 & 25.51\% \\ TNG5 & 1174 & 988 & 970 & 16.2 & 204 & 17.38\% \\ TNG6 & 1052 & 974 & 964 & 9.5 & 88 & 8.37\% \\ TNG7 & 871 & 854 & 842 & 11.7 & 29 & 3.33\% \\ TNG8 & 996 & 880 & 858 & 20.4 & 138 & 13.86\% \\ \hline \hline \end{tabular}
\end{table} 
Table 5: Experiment results of GA algorithm. ```
List<Individual> offspring = Crossover(list); \(\text{P}_{\text{all}}\) = Mutate(offspring); \(\text{P}_{\text{all}}\) = LocalSearch(\(\text{P}_{\text{all}}\)); // Caculate the \(\text{P}_{\text{best}}\)  foreach (var \(\text{P}_{\text{i}}\) in \(\text{P}_{\text{all}}\))  if (f(\(\text{P}_{\text{i}}\)) < f(\(\text{P}_{\text{best}}\))) \(\text{P}_{\text{best}}\) = P\({}_{\text{i}}\); } return \(\text{P}_{\text{best}}\) end Where: f: objective function
```  
**Algorithm 1**_Cont._  
To improve the efficiency of the schedule generated by the Real-RCPSP problem, this paper experiments with a more modern algorithm, PSO. This algorithm typically yields better results than GA due to improvements by using two parameters in the evolutionary process: velocity vector and position vector. Using these two vectors helps PSO improve the convergence speed of the algorithm. The evolutionary calculation of PSO is performed through Equations (11) and (12) below.