# Embedded PSO for Solving FJSP on Embedded Environment (Industry 4.0 Era)
## 4 Used PSO-FJSP Variant  
Despite the fact that any metaheuristics can theoretically be applied to the FJSP, PSO is substantially easier to install and control because of its fewer parameters. PSO uses a population of particles that move around in the search space according to simple mathematical formulae expressing the particle's position and velocity to find good, if not optimal, solutions to a problem. Each particle has a subset of particles with which it can communicate; this subset is known as swarm topology, and it can be a completely linked topology, a ring topology, a Von Neumann topology, and so on. A particle's best-known position in the search space, as well as the best-known positions of its neighbors, directs its movements. A particle \(p\) obtains a new position vector, \(X_{p}(t+1)\), and a new velocity vector, \(V_{p}(t+1)\), at each instant, calculated as follows:  
\[V_{p}(t+1)=wV_{p}(t)+c_{1}R_{1}(Xbest_{p}(t)-X_{p}(t))+c_{2}R_{2}(Xnbest_{p}(t) -X_{p}(t)) \tag{7}\]  
\[X_{p}(t+1)=X_{p}(t)+V_{p}(t+1) \tag{8}\]  
where \(w\) is a parameter called the \"inertia weight\"; \(c_{1}\) and \(c_{2}\) are two parameters called the \"cognitive factor\" (or self-recognition factor) and \"social factor\" (or social-component factor), respectively; \(R_{1}\) and \(R_{2}\) are two square diagonal matrices in which the entries on the main diagonal are random numbers in the interval [0, 1] The best location attained by a particle \(p\) up to time \(t\) is called \(Xbest_{p}(t)\). The neighborhood best, also known as \(Xnbest_{p}(t)\), is the best location that \(p\)'s neighbors have discovered. The second level utilizes an adaptive inertia weight (Equation (9)), whereas the first level uses a time-varying inertia weight (Equation (10)):  
\[w_{p}(t)=\left\{\begin{array}{l}w_{min}+\frac{(w_{max}-w_{min})(pBest(t-1)- minBest(t))}{avgBest(t)-minBest(t)},\ if\ pBest\leq avgBest(t)\\ w_{max}\end{array}\right.,\text{\emph{otherwise}} \tag{9}\]  
\[w(t)=w_{min}+(w_{max}-w_{min})\frac{t}{I_{1}} \tag{10}\]  
\[c_{1}(t)=0.5\ (w_{p}(t)+1)^{2} \tag{11}\]  
\[c_{2}(t)=min(4,2(w_{min}+1))-0.5\ (w_{p}(t)+1)^{2}-0.000001 \tag{12}\]  
where \(avgBest(t)\) (resp. \(minBest(t)\)) is the average (minimum) objective value at the current iteration, \(w_{max}=0.9\) and \(w_{min}=0.4\).  
The two-level PSO-FJSP attempts to shrink the search space even further and increase the exploration capability. The two-level PSO-FJSP nestedly executes a PSO twice: the top level investigates multiple operations-to-machines mappings, while the lower level investigates various schedules for a given mapping. As a result, before moving on to another mapping, numerous schedules of the same mapping are evaluated sequentially.  
Particles are coded as follows: The location vector \(X_{p,m}\) of an upper-level particle \(p\) of \(|O|\) elements models one operations-to-machines mapping. The indices of \(X_{p,m}\) and the operations of the jobs have a one-to-one prefixed correspondence. A lower-level particle has a position vector \(X_{p,s}\) of \(|O|\) elements, which models the order of operations mapped to each machine. Between the indices of \(X_{p,s}\) and machines, there is a one-to-one prefixed correspondence.  
Let \(S_{1}\) and \(I_{1}\) (\(S_{2}\) and \(I_{2}\)) represent the number of particles and iterations utilized in level one (level two), respectively. The values assigned to \(S_{1}\) and \(I_{1}\) are determined by the degree of flexibility of an FJSP instance. The smaller values of \(S_{1}\) and \(I_{1}\) are the lower flexibility degree. The values allocated to \(S_{2}\) and \(I_{2}\) may be fixed or adaptive to the lower bound value found. If the gap between the current best objective value and the lower bound is large (small), then \(S_{2}\) and \(I_{2}\) are set high (low). The two-level PSO-FJSP flowchart is shown in Figure 3.