# Parallel Hybrid Particle Swarm Algorithm for Workshop Scheduling Based on Spark
## 3 Parallelized Hybrid Particle Swarm Algorithm Based on Spark
### Parallel Hybrid Particle Swarm Algorithm
3 Set initial values for: max_iter, N; i, in
4 Initialize and solve the particle swarm's own optimal m and global optimal value n according to the default order of the workpiece;
5 forii in rang(max_iter); /*The particles and the global optimal particles are cross-operated*/ fori in rang(N);
7 Cross operation between each particle and the global optimal particle;
8 Update N;
9 Solve the objective function after crossover: k = fitness(N);
10 Output the optimal new_n value of the most global particle swarm; its own optimal value new_m /*Update m, n*/
11 If new_n < n then n = new_m;
13 endfor /*The particle and its own optimal history particle perform cross operation*/ fori in rang(N);
15 Each particle crosses with its own optimal history particle
16 Update N;
17 Solve the objective function after crossover: k = fitness(N);
18 Output the optimal new_n value of the most global particle swarm; its own optimal value new_m /*Update m, n*/Figure 2: The main process of parallelized hybrid particle swarm optimization. ### Detailed Design of the Algorithm

#### 3.2.1 Coding Scheme Design

The research problem is mixed mixed mixed-flow workshop scheduling, in which there are job workshops and flow workshops and the coding methods in genetic coding are compared. The three workshops are designed with a unified coding. After the coding design is completed, the workshops are independently optimized and dispatched. First, determine the minimum production ratio of the number of products produced according to actual needs. According to the minimum production ratio, determine the minimum production ratio for the product-assembly workshop, component-assembly workshop and parts-processing workshop, then perform independent coding. In the workshop, letters and numbers are used to represent products, components and parts. The same letters represent the same products, components and parts. If we need to put into production, the P, Q and R products are 2, 1 and 2; the number of required components X and Y is 2 and 3; the parts required for parts processing A, B and C are 2, 1 and 2. Then, the coding method in the product-assembly workshop can be (P1, P2, Q1, R1, R2); the coding of the component-assembly workshop is (X1, X2, Y1, Y2, Y3); the coding of the part processing workshop is (A1, A2, A3, B1, C1, C2, C3). #### 3.2.2 Crossover and Mutation

Enter the number of artifacts to generate N (total number of particles) random artifact sequences. After crossover and mutation with the global optimal value and its own optimal value, respectively, filter and update the one that can produce a better target value particle. In this step, the crossover and mutation operations can be regarded as random walk operations on the permutation group of the workpieces arranged in order. The mutation is a single-step walk of exchange and the crossover can be a walk formed by a combination of multiple basic exchanges. This step is similar to the speed update in the classic PSO. Whether to perform a walk is only True or False in this algorithm. This step simulates the weighting factor [27] in the classic PSO. Crossing with the local (self) and global optimal values, respectively, simulates the two velocity terms in the classic PSO. Both the mutation and crossover operations have a certain degree of randomness, which ensures that a single particle can jump out of the local optimal solution possibility. #### 3.2.3 Parallelization of Hybrid Particle Swarm Algorithm

Pyspark is a tool of Spark and a library of sparkAPI written in python provided by Spark. Parallelization is achieved through Pyspark. First, the PSO coding is converted into a parallel RDD, then the process of solving the objective function is applied to all the particles through the Map operation provided by Spark. The time for each particle to be transformed into the objective function is summarized to obtain the optimal result.