# Revised Gravitational Search Algorithms Based on Evolutionary-Fuzzy Systems
## 2 The Gravitational Search Algorithm
Moreover, the variable \(sigma\) in Algorithm 4 is calculated through the formula (20) where \(max(p_{r})\) and \(min(p_{r})\) are the max and min value of the initial random parameters \(p_{r}\). \[sigma=\frac{max(p_{r})-min(p_{r})}{10}; \tag{20}\]  
In our algorithm, the number \(l\) of population \(P\) is set to 100; the number of mutation \(m\) is equal to 20; and number of elitism is equal to two. The designed fuzzy controller is optimized through GA: the steps of the optimization algorithm are described in the Algorithm 5. GA optimizes the slope of the membership functions (four parameters for each membership function), to achieve the optimal membership functions. Because the membership functions number is 13, it follows that \(13\times 4=52\) parameters are optimized. Once the fuzzy controller is optimized, it may be used to adjust the parameter \(\alpha\) of GSA. The fuzzy gravitational search algorithm optimized by GA is described in Algorithm 6. ```
1:For all the \(i\) from \(l-mutation+1\) to \(l-mutationR\):
2:Compute a random number \(phi\) between \(-1\) and \(+1\). 3:Compute \(z=erfinv(phi)*(2^{0.5})\), where \(erfinv\) is the inverse error function. 4:Compute the parameter \(p\) with the formula \(p(i)=z\cdot(sigma)+parent(i)\), where \(sigma\) is calculated by (20). 5:Print the parameters \(p\). ```  
**Algorithm 4**  
**S1**. For all the \(i\) from \(l-mutation+1\) to \(l-mutationR\):  
**S1.1**. Compute a random number \(phi\) between \(-1\) and \(+1\). **S1.2**. Compute \(z=erfinv(phi)*(2^{0.5})\), where \(erfinv\) is the inverse error function. **S1.3**. Compute the parameter \(p\) with the formula \(p(i)=z\cdot(sigma)+parent(i)\), where \(sigma\) is calculated by (20). **S2**. Print the parameters \(p\). ```
**Algorithm 5**  
**S1**. Pass the optimization ranges of the membership functions to GA.  
**S2**. Select in a random way the initial optimal values of the parameters in the optimization ranges and calculate the termination criteria of GA. This criteria depends on number of generations and fitness function values. **S3**. If the termination criteria is achieved, go to **S10**. **S4**. For each \(j\)-th element of the population \(P\), with \(j=1,...,l\), compute the steps from **S4.1-S4.4**  
**S4.1**. Pass the optimal parameters to the fuzzy inputs/output of the controller. **S4.2**. Initialize, in a random way, the position \(X\) of the agents in the search space. The initialization procedure depends on the number of agents \(n\), the dimension of the test functions \(r\) and the allowable range \([up,down]\) for the search space. The positions \(X\)'s are calculated by generating \(n\times r\) random numbers between 0 and 1, and normalize them on the range \([up,down]\). In other terms, the positions are computed by the formula \(X(i,j)=rand(i,j)*(down-up)+down\), with \(i=1,...,n\) and \(j=1,...,r\). **S4.3**. Set the initial value \(\alpha(1)\) and for each iteration \(i\), with \(i=1,2,...,k\), compute the steps from **S4.3.1-S4.3.4**  
**S4.3.1**. Compute the fitness of the agents for a certain function. The fitness depends on the position of the agents and the dimension of the function. **S4.3.2**. The value of the fitness is necessary to calculate the mass of each agent \(m_{i}(t)\) for \(i=1,2,...,n\). (see (11)). On the other hand, \(m_{i}(t)\) depends on \(best(t)\) and \(worst(t)\) (Equations (13) and (14), respectively), which also depend on fitness. The gravitational constant \(G(t)\) is computed according to \(\alpha(1)\) at the first iteration, whereas, for the other iterations, \(G(t)\) is calculated according to the tuned value of \(\alpha\). **S4.3.3**. According to \(G(t)\), the total force in different directions is calculated. In particular, the algorithm computes the Euclidean distance between two agents \(R_{ij}(t)\) and the force acting on mass \(i\) from mass \(j\) at a specific time \(t\) (see (3)). Subsequently, the total force \(F_{i}^{d}(t)\) (see (6)) is computed.