# A Comprehensive Survey of the Harmony Search Algorithm in Clustering Applications
## 2 Main Procedures of the HSA  
The HSA, which was designed in 2001, is launched by the way that on-screen musicians extemporaneously change the pitches of their instruments to create new harmonies, for example during jazz improvisation [23]. The most important steps of the HSA are displayed as pseudo-code in Figure 4. Let \(X\) denote the entire space of possible solutions. Each of the individual solutions \(x\in X\) depends on \(N\) decision variables. The optimization problem requires finding the maximum or minimum value of the fitness function esteem \(f_{X_{i}}\) for all the \(i=1...N\) variables.  
**(1) Initialize the HS parameters:**: The control parameters of the HSA are given their values in this step: the Harmony-Memory Considering Rate \(HMCR\) and the Pitch-Adjusting Rate (PAR), both lying between 0 and 1, will be utilized during the period of improvement (step 3 below), while the maximum number of generations (\(I_{max}\)) is compared to the max course of emphases [45]. \(HMS\) is the number of candidate solutions, discussed in the next step; it is obviously constrained to be less than or equal to the number of solutions in \(X\).
**(2) Initialize the harmony memory:**: From the possible solution space \(X\) we choose (i.e., stochastically generate) some number \(HMS\) of candidate solutions, analogous to the population solutions in genetic algorithms or PSO. Let \(x_{i,j}\) be the value of the \(j\)-th decision variable of the \(i\)-th solution. The Harmony Memory (HM) is the matrix having these values as elements:  
\[HM=\begin{bmatrix}x_{1}^{1}&...&x_{j}^{1}&...&x_{N-1}^{1}&x_{N}^{1}\\ x_{1}^{2}&...&x_{j}^{2}&...&x_{N-1}^{2}&x_{N}^{2}\\...&...&...&...&...&...\\ \vdots&\vdots&\vdots&\vdots&\vdots&\vdots\\ x_{1}^{HMS-1}&...&...&...&x_{N}^{HMS-1}\\ x_{1}^{HMS}&...&...&...&...&x_{N}^{HMS}\end{bmatrix} \tag{1}\]
**(3) Improvisation of a new solution:**: In this step, a new candidate solution is produced utilizing three operators, specifically harmony-memory consideration, pitch adjustment, and random selection, as shown in Equation (2).  
Figure 4: Pseudo-code of the basic Harmony Search (HS) Algorithm.  
\[Xi=(x_{i,1},x_{i,2},...,x_{i,j},...,x_{i,t}) \tag{2}\]  
The HS calculation produces a new, previously unused solution, as shown in Equation (3), improving the optimal solution in the HM by improvisation. (The pseudo-code of the processes generating the new solution is presented in Figure 5.)  
\[x_{new,j}\leftarrow\begin{cases}x_{new,j}\in\{x_{1,j},x_{2,j},...,x_{S,j}\};& \text{if $rand<HMCR$}\\ x_{new,j}\in\{0,1\};&\text{otherwise}\end{cases} \tag{3}\]  
where \(x_{new,j}\) is the value of the \(j\)-th decision variable of the new harmony (solution), and each variable is selected concurring with Equation (3). The probability that the candidate value of each variable is selected from the current candidate values within the current HM is HMCR.  
**(4) Updating the HM solutions:**: The produced solution is assessed by its fitness function. In the event that the fitness function esteem of the new solution is superior to that of the worst solution within the HM, the worst solution will be replaced in the HM by the new solution [46].
**(5) Check the stopping criterion:**: When the maximum number of iterations is reached, the HSA stops its procedure for improvements. Until then, steps (3) and (4) are executed to improvise new candidate solutions.  
```
1:Input: Harmony memory \(H\)M solutions
2:Output: A new solution.
3:for each j \(\in[1,t]\)do
4:if\(rand[0,1]\
otin HMCR\)then
5:\(x_{ij}=HM[i][j]wherej\in U(1,2,....,t)\)
6:if\(rand(0,1)\in PAR\)then
7:\(x_{ij}=x_{ij}\pm rand\times\)\(bw(i)\), where \(rand\in[0,1]\)
8:endif
9:else\(x_{ij}=LBi+rand\times(UBi-LBi)\)
10:endif
11:endfor
```  
**Algorithm 2** :Improvise a new solution