A Hybrid Harmony Search Algorithm with Distribution Estimation for Solving the 0-1 Knapsack Problem
Algorithm 7
The HHSEDA algorithm for the 0-1 knapsack problem.
(1)
Initialize the algorithm and problem parameters.
(2)
The harmony memory library should be initialized according to the feasible solution initialization method and the requirement of knapsack capacity to be met.
(3)
Calculate the fitness value after initialization.
(4)
for i = 1 to J1 do
(5)
Find the worst and best harmony in the harmony memory database as p
(6)
Calculate fitness values and sort them
(7)
For i = 1: K% select the dominant population
(8)
The number of K populations with the highest fitness value was selected
(9)
end
(10)
For j = 1: N%% Generates new harmonies based on Guided Improvisation
(11)
Count the number of bags selected in each column
(12)
if rand < HMCR
(13)
r = ceil (HMS ∗ rand) Randomly select the harmonic vector
(14)
if rand < PAR
(15)
If rand < probability
(16)
Update the corresponding harmonies
(17)
end
(18)
end
(19)
else Random mutation produces new harmonies
(20)
end
(21)
end for
(22)
The total capacity of the newly produced harmony is calculated
(23)
If the knapsack capacity requirement is met, the greedy selection is made under the constraint
(24)
If the knapsack capacity requirement is not met, the harmony is repaired