## 4 Harmony Search Algorithm and Its Variants
### Harmony Search Algorithm  
The Harmony Search (HS) algorithm was first introduced in early 2000 by [PERSON] et al. in [38]. The HS algorithm is inspired by the musical process of musicians in the search for a fantastic harmony by aesthetic estimation. The variables \(x(j)\) are represented by musical instruments and the fantastic harmony is the desired optimal solution, where \(x(j)\in[LB(j),UB(j)]\), \(j=1,2,...,n\) and \(n\) is the number of variables. Every musical practice represents another iteration limited to a maximum Number of Improvisations (\(NI\)) and the quality of the results are evaluated based on the pitches of the instruments.  
First an initial group of harmony vectors \(\textbf{X}_{i}=\left\{x_{i}(1),x_{i}(2),\ldots,x_{i}(n)\right\}\) are randomly generated as:  
\[x_{i}(j)=\left(UB(j)-LB(j)\right)\times r+LB(j) \tag{19}\]  
where \(UB(j)\) and \(LB(j)\) are the upper and lower bonds for the \(j^{\text{th}}\) variable and \(r\) is a random uniform number between 0 and 1.  
The harmony vectors are then combined to form the Harmony Memory (HM) with a total of \(HMS\) vectors to store the best harmony improvisation vectors based on their cost function which is stored in HM as well as:  
\[HM=\left[\begin{array}{c}\textbf{X}_{1}\\ \textbf{X}_{2}\\ \vdots\\ \textbf{X}_{i}\\ \vdots\\ \textbf{X}_{HMS}\end{array}\right]=\left[\begin{array}{ccccc}x_{1}(1)& \ldots&x_{1}(j)&\ldots&x_{1}(n)&f(\textbf{X}_{1})\\ x_{2}(1)&\ldots&x_{2}(j)&\ldots&x_{2}(n)&f(\textbf{X}_{2})\\ \vdots&\vdots&\vdots&\vdots&\vdots\\ x_{i}(1)&\ldots&x_{i}(j)&\ldots&x_{i}(n)&f(\textbf{X}_{i})\\ \vdots&\vdots&\vdots&\ddots&\vdots\\ x_{HMS}(1)&\ldots&x_{HMS}(j)&\ldots&x_{HMS}(n)&f(\textbf{X}_{HMS})\end{array}\right] \tag{20}\]  
where \(HMS\) is the Harmony Memory Size.  
To improvise new harmony vectors \(\textbf{X}_{new}\), three rules are considered; the memory consideration, the pitch adjustment, and the random selection. The new vector could be selected from the vectors of the HM by testing a random number \(r_{1}\) for memory consideration based on the Harmony Memory Consideration Rate (\(HMCR\)), and further will be pitch adjusted using a predefined Bandwidth (\(BW\)) based on the Pitch Adjustment Rate (\(PAR\)), otherwise it is randomly selected as explained in Figure 7.  
Once the new harmony vector \(\textbf{X}_{new}\) is generated, the harmony memory HM will be updated based on the fitness of the new vector and the worst existing vector \(\textbf{X}_{w}\). The new vector \(\textbf{X}_{new}\) will then replace the worst vector \(\textbf{X}_{w}\) in HM if its fitness value is better.  
Finally, the HS algorithm can be summarized by the steps detailed in the pseudocode of Algorithm 1:  
```
1. Define parameters of HS algorithm: \(n\), \(HMS\), \(HMCR\), \(PAR\), \(BW\), \(NI\).
2. Initialize HM with random harmony vectors using (19) and calculate the cost function of each vector.
3. Improvise a new Harmony vector \(\textbf{X}_{new}\) based on the three rules of Figure 7.
4. Update the HM with \(\textbf{X}_{new}\) if \((f\left(\textbf{X}_{new}\right)<f\left(\textbf{X}_{w}\right))\) as \(\textbf{X}_{w}=\textbf{X}_{new}\).
5. If the maximum number of improvisations \(NI\) is reached then stop the program and return the best harmony vector \(\textbf{X}_{B}\). Otherwise, go back to step 3.
```  
**Algorithm 1**Harmony Search Algorithm  
\(HMCR\) maintains the balance between the exploration and exploitation; on the other hand, \(PAR\) is responsible for the refinement of the solutions by a distance BW. Therefore, the setting of these three parameters greatly influences the efficiency of the algorithm.