# XOR Binary Gravitational Search Algorithm with Repository: Industry 4.0 Applications
## 2 Gravitational Search Algorithm
### Basic Gravitational Search Algorithm  
Each solution in \(d\)-dimensional search space is represented by the position of an object and is represented as follows:  
\[X_{i}=(x_{i}^{1},x_{i}^{2},...,x_{i}^{j},...x_{i}^{d})\ \ i=1,...,N \tag{1}\]  
where \(x_{i}^{j}\) is the \(j\)th component of the position of object and \(N\) is the total number of objects. The mass of particles are updated and normalized at \(t\)th iteration as follows [13].  
\[M_{i}(t)=\frac{m_{i}(t)}{\sum_{k=1}^{N}m_{k}(t)} \tag{2}\]  
where \(m_{i}(t)\) is non-normalized mass value corresponding to \(i\)th particle at iteration number \(t\) which represents the quality of solution and is defined as follows [13].  
\[m_{i}(t)=\frac{f(X_{i}){-}f_{worst}(t)}{f_{best}(t){-}f_{worst}(t)} \tag{3}\]  
where \(f_{worst}(t)\) is the fitness function value corresponding to the worst particle and \(f_{best}(t)\) represents the best fitness function observed by any of the particles. Hence, in this case \(m_{i}(t)\) satisfies \(m_{i}(t){\in}[0,\ \ 1]\) and the value of mass of best solution is equal to \(one\) while the value of mass corresponding to worst solution is equal to \(zero\). The parameters \(f_{worst}(t)\) and \(f_{best}(t)\) are updated at every iteration as follows:  
\[f_{worst}(t)=max\{f(X_{i})\}_{i=1,...,N}\]  
\[f_{best}(t)=min\{f(X_{i})\}_{i=1,...,N} \tag{4}\]  
It is to be noted that in this case the best and worst particles are defined based on minimization problem. In maximization problems, the updating equations for \(f_{worst}\) and \(f_{best}\) swap their definition. Furthermore, \(k_{b}\) number of best solutions are selected at each iteration as the masses which attract other masses.  
The overall gravitational force acting on the \(i\)th particle is obtained as follows:  
\[F_{i}(t)=\sum_{j\in\{1,...,k_{b}\}}r_{j}G(t)\frac{M_{j}(t)M_{i}(t)(X_{j}(t){- }X_{i}(t))}{\|X_{i}(t){-}X_{j}(t)\|^{r_{p}}{+}\varepsilon} \tag{5}\]  
where \(k_{b}\) represents the number of best solution selected, \(\|.\|\) stands for Euclidean norm, \(\varepsilon\) is a small value added to prevent division by \(zero\), \(r_{p}\) is the power considered for the Euclidean distance between two particles, \(G(t)\) is the gravitational constant and \(r_{j}{\in}[0,\ \ 1]\) is a uniform random value. The gravitational constant is updated at each iteration using the following equation.  
\[G(t)= G_{0}exp\left(-\beta\frac{t}{t_{max}}\right) \tag{6}\]  
where \(G_{0}\) has a constant real value and \(t_{max}\) is the maximum value of the iterations of the algorithm. According to [PERSON]'s second law of motion, the acceleration of particles are calculated by dividing the applied force to \(i\)where \(A_{i}(t){\in}R^{d}\) is \(d\)-dimensional acceleration of the particles. It is further possible to update the velocity of objects using the following equation.  
\[V_{i}(t{+}1)=p_{i}\ \ V_{i}(t){+}A_{i}(t) \tag{8}\]  
where \(V_{i}(t){\in}R^{d}\) is \(d\)-dimensional acceleration of the particles at \(t\)th iteration and \(p_{i}{\in}[0,\ \ 1]\) is a uniform random number. Finally, the newer position of each particle is updated as follows:  
\[X_{i}(t{+}1)=X_{i}(t){+}V_{i}(t{+}1) \tag{9}\]