/Harmony-Search-algorithm

code to run the harmony search algorithm (HSA)

Primary LanguagePython

Harmony-Search-algorithm

Harmony Search is a metaheuristic algorithm that is inspired by the improvisation process of musicians. It is used for solving optimization problems, such as finding the global minimum or maximum of a function. The algorithm simulates the improvisation process by generating a set of "harmonies" (i.e., potential solutions) and iteratively improving them based on a set of rules.

I use 6 Points for TSP Problem

A A 0 A B 11 A C 15 A D 16 A E 9 A F 9 ///// B A 11 B B 0 B C 10 B D 15 B E 14 B F 10 ///// C A 15 C B 10 C C 0 C D 8 C E 13 C F 9 ///// D A 16 D B 15 D C 8 D D 0 D E 11 D F 10 ///// E A 9 E B 14 E C 13 E D 11 E E 0 E F 6 ///// F A 9 F B 10 F C 9 F D 10 F E 6 F F 0 ///// [0, 11, 15, 16, 9, 9], [11, 0, 10, 15, 14, 10], [15, 10, 0, 8, 13, 9], [16, 15, 8, 0, 11, 10], [9, 14, 13, 11, 0, 6], [9, 10, 9, 10, 6, 0]]

and finally print the results of best solution in excel file

THE STEP TO SOLVE ALGORITHM

1- Initialize the harmony memory with a set of randomly generated solutions. 2- Evaluate the fitness of each solution in the harmony memory. 3- Select a solution from the harmony memory as the current solution. 4- Generate a new solution by adjusting the current solution using a harmony-search-specific algorithm, such as random perturbation or pitch adjustment. 5- Evaluate the fitness of the new solution. 6- If the new solution is better than the current solution, replace the current solution with the new solution.

Repeat steps 3-7 for a set number of iterations or until a satisfactory solution is found