1. Introduction
Harmony search is an optimization algorithm inspired by biological algorithms. The idea of harmony search comes from musicians constantly tuning their instruments to achieve a good harmony. The algorithm is developed by Zong Woo Geem et al. in 2001, and it has been widely used because of its easy application and fast convergence to the optimum solution.
The idea of the algorithm is based on a band playing together. A musician in the band tunes the instrument until a certain harmony is achieved. The orchestra, which plays in a bad harmony at first, adjusts the instrument tuning until they achieve a certain degree of good harmony. Every harmony that arises is a solution to the problem. The Harmony algorithm generates new solutions that are iteratively improving by making random changes to previous solutions, such as an orchestra.
2. The Algorithm
3. Applications of Harmony Search
Due to its easy applicability and efficiency, harmony search is used in many areas. For example, it can be used in course timetabling which is a very challenging task in any academic institution. The design of a water distribution network is another use for HSA. For the network to provide a smooth water supply at a low cost, it must be constructed with consideration for differences in pipe diameter, elevation, and separation. HSA is also used for power supply optimization, which involves supplying a lot of electricity at the lowest possible cost. All in all, Harmony search algorithm is used in many areas such as scheduling, civil engineering, electrical engineering.
4. Sample Problem
4.1 Problem Definition
We will use harmony search algorithm to find the nearest point to the target. The target is a random point in the 1st region of the 100x100 coordinate system.
4.2 Fitness Function
The fitness function is the formula of the distance between two points. The goal is to minimize the function.
4.3 Defining Parameters
Harmony memory stores the best harmonies. Harmony history stores the harmonies on every generation. Target point which is defined by problem definition is a tuple consisting of x and y coordinates. Harmony memory size is the maximum length of the harmony memory. Number of improvisations is the number of iterations to improve harmonies. Harmony memory considering rate is the probability of choosing an existing harmony from the memory. Pitch adjusting rate is the probability of making small changes to the selected harmony from the memory. Maximum x and maximum y are the boundary of the coordinate system.
4.4 Creating Initial Harmonies
Initial harmonies are randomly generated at the beginning of the algorithm. Fitness function is evaluated for each generated harmony.
4.5 Memory Consideration
Memory consideration function randomly selects a harmony from the harmony memory.
4.6 Pitch Adjustment
Pitch adjustment function slightly changes the harmony. It checks the boundary limits of the coordinate system and increases or decreases the coordinates by one, depending on chance.
4.7 Random Selection
Random selection function randomly creates a new harmony.
4.8 Update Harmony Memory
Update harmony memory function replaces the worst harmony in the memory to the new harmony if the new harmony is a better solution than the worst harmony.
4.9 The Driver Function
The algorithm is executed with this main function. First, the harmony memory is randomly initialized. Then, either a new harmony is created or randomly selected from memory. If the harmony is randomly selected from the harmony memory it can be slightly changed by the pitch adjustment function. After that, harmony memory is updated. The worst harmony is replaced by the current harmony if the current harmony is a better solution. As the last step of the loop, harmony history is updated if the current iteration is a new generation. Finally, the best harmony and the fitness is printed to the screen.
5 Results
The algorithm continuously improves the worst solution, ensuring that all solutions are close to the best and that all solutions are in harmony. As seen in the Figure 4.1, in the first iteration the solutions are distributed and inharmonious, but in the Figure 4.2 all the solutions are close to the target and overall harmony is provided.