# Solution of Orifice Hollow Cathode Plasma Model Equations by Means of Particle Swarm Optimization
## 3 Particle Swarm Optimization Methodology
### PSO General Model
So, the cost function \(J\) is evaluated for each individual as the sum of the residuals \(\epsilon\),  
\[J_{z}^{q}=\|\epsilon_{I}\|+\|\epsilon_{Pow,\epsilon}\|+\|\epsilon_{ion, \epsilon}\|+\|\epsilon_{press,\epsilon}\|+\|\epsilon_{Pow,\rho}\|+\|\epsilon_{ ion,\rho}\|+\|\epsilon_{press,\rho}\| \tag{29}\]  
where:  
* \(\epsilon_{I}=\text{RHS}-\text{ LHS}\) of Equation (14), (current);
* \(\epsilon_{Pow,\epsilon}=\text{RHS}-\text{ LHS}\) of Equation (15) (emitter power);
* \(\epsilon_{ion,\epsilon}=\text{RHS}-\text{ LHS}\) of Equation (13) (emitter ions);
* \(\epsilon_{press,\epsilon}=\text{RHS}-\text{ LHS}\) of Equation (16) (emitter pressure);
* \(\epsilon_{Pow,\rho}=\text{RHS}-\text{ LHS}\) of Equation (5) (orifice power);
* \(\epsilon_{ion,\rho}=\text{RHS}-\text{ LHS}\) of Equation (4) (orifice ions);
* \(\epsilon_{press,\rho}=\text{RHS}-\text{ LHS}\) of Equation (6) (orifice pressure). where \(J_{z}^{q}\) is the cost function evaluated for the \(z\)-th individual at the \(q\)-th iteration. Furthermore, all the residuals, as defined above, have been divided into their reference variable (i.e., discharge current, power, and so on) in order to obtain dimensionless residuals with the same order of magnitude. This operation allows the optimization code to operate with different variables, but all with the same weight. Now, all these first cost functions \(J_{z}^{q}\) are assigned as the PB of each individual, so:  
\[PB_{z}^{q}=J_{z}^{q} \tag{30}\]  
while the GB has to be selected as the one with the minimum value in the entire swarm; hence:  
\[GB^{q}=min\left(J_{z}^{q}\right) \tag{31}\]  
With thisatter step, the swarm initialization can be said concluded, and the real optimization process can start. So, to update the state of all the individuals, using the information coming from the exploration, and hence from the swarm, the new velocities can be calculated with the ultimate form:  
\[V_{z}^{q+1}=C1*V_{z}^{q}+C2*rand*(PB_{z}^{q}-X_{z}^{q})+C3*rand*(GB^{q}-X_{z}^{ q}) \tag{32}\]  
where \(z\) is the \(z\)-th individual and \(q\) is the \(q\)-th iteration, C1-C2-C3 are constants in the range between 0 and 2, \(X\) refers to the variable whose velocity is being calculated, and \(rand\) is a random operator that assumes values between 0 and 1, as mentioned above. Now, the individuals' state can be updated with the velocity in order to start effectively the domain exploration:  
\[X_{z}^{q}=X_{z}^{q-1}+V_{z}^{q} \tag{33}\]  
This updated state is considered a temporary state since it has to be checked with respect to the original domain as defined at the beginning of this section. In fact, it could happen that the updated state results to be out of the domain bounds because of its movement due to the applied velocity. In this case, the state is corrected assigning the boundary value that it was trying to violate during the update. With the updated state, also the cost function can be updated in order to compare the values with the ones calculated at the iteration before \(J_{z}^{q-1}\). If \(J_{z}^{q}\) results to be smaller than the iteration before for one or more individuals, then its own Personal Best would be updated, and so:  
\[PB_{z}^{q}=min\left(J_{z}^{q-1},J_{z}^{q}\right) \tag{34}\]The same happens for the Global Best, where its own value is compared with all the PB of the entire swarm. If ateast one individual has found a better solution \(PB_{2}^{q}\), with respect to the GB of the iteration before \(GB^{q-1}\), the Global Best would also be updated, so:  
\[GB^{q}=min\Big{(}GB^{q-1},PB_{z}^{q}\Big{)} \tag{35}\]  
This criterion is fundamental to this optimization technique since it allows us to drive the individuals close to the promising region of the domain where better solutions are found. From this point ahead, the cycle is continuously repeated until the stop criterion is satisfied.