# Embedded PSO for Solving FJSP on Embedded Environment (Industry 4.0 Era)
## 5 Proposed Technique: Embedded Two-Level PSO-FJSP  
Our solution is an automatic adaptation of the asynchronous two-level PSO algorithm to CPU needs by other tasks that run in parallel (embedded two-level PSO E2L-PSO). Several variants can be envisaged, such as the suspension of certain threads or the reduction in the number of particles. The efficiency and reliability of the method always lie in the choice of particles to suspend. It is, therefore, necessary to designate the particles that return a fitness that is furthest away from the _Xnbest_ (global best) because the particles, which have the best solution, are probably closer to the global optimum. In this paper, we are inspired by the migration method of dividing the swarm into subsets. We divided the swarm into a \"leaders sub-swarm\", a \"worsts sub-swarm\" and two \"followers sub-swarms\". The migration process is as follows:  
* \"Leaders sub-swarm\" began with only one particle that has the best MS in the initialization phase. \"\(X_{L}\)\" is the maximum number of particles. * \"Worsts sub-swarm\" began with only one particle: the particle that has the worst MS in the initialization phase. \"\(X_{W}\)\" is the maximum number of particles. * Particles that have the best solutions are migrated from the \"followers sub-swarm\" to the \"leaders sub-swarm\". If the number of particles in this subset is equal to \"\(X_{L}\)\" then one of these particles must randomly migrate to a \"follower sub-swarm\" to empty the space for the new particle. * Particles that have the worst solutions are migrated from the \"followers sub-swarm\" to the \"worsts sub-swarm\". If the number of particles in this subset is equal to \"\(X_{W}\)\" then one of these particles must randomly migrate to a \"followers sub-swarm\" to empty the space for the new particle. In this paper, we chose to work with a swarm size reducing based solution. This solution allows us to release both the CPU time and the memory. Indeed, we remove particles from the \"worsts sub-swarm\". Algorithm 1 presents the steps of the adaptive  
Figure 3: Flowchart of the two-level particle swarm optimization—flexible job shop scheduling problem (PSO-FJSP). E2L-PSO, where \"_need_\" is an external variable contains the request to free memory or the CPU need. In this approach, the minimum number of particles in the swarm is defined at the start of the program. The last particle in every phase is the latest executed particle in the last iteration. The flowchart of the E2L-PSO is given in Figure 4.  
Two process are used in this algorithm: one for the stopping particle and one for waking up the particle. In the stopping process, if the number of active particles (\(p_{active}\)) is more than the number of particles to be stopped (\(p_{inactive}\)), and if the size of \"worsts sub-swarm\" is more than \(p_{inactive}\), then we should randomly put \(p_{inactive}\) particles in the \"worsts sub-swarm\" in the inactive mode. Alternatively, we should put (\"worsts sub-swarm\" size \(-1\)) particles in the inactive mode and a randomly put (\(p_{inactive}-size_{words-sub-swarm}\)) particles from the \"followers sub-swarm\" in the inactive mode. This process is represented in Algorithm 2. In the wake up process, if the number of particles in the inactive mode is more than zero, so we should put 50% of \(Total_{inactive}\) particles in an active mode by initializing according to the global best (\(X\)_nbest_) coordinates and put 50% in an active mode by randomly initializing. We should add it to the \"followers sub-swarm\". This process is presented in Algorithm 3. To resume, we can say that, compared to the two-level PSO presented in [32], our new proposed approach \"E2L-PSO\" adds four new processes:  
* After swarm initialization, we divide the swarm into a sub-swarm: \"leaders sub-swarm\", \"followers sub-swarm\" and \"worsts sub-swarm\". So our population work under swarms. * After each iteration, a migration method is added.