Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \documentclass{article}
- \usepackage[linesnumbered,ruled,vlined]{algorithm2e}
- \begin{document}
- \begin{algorithm}[H]
- \SetAlgoLined
- \KwIn{Objective function \( f \), Harmony memory size \( HMS \), Harmony memory consideration rate \( HMCR \), Pitch adjustment rate \( PAR \), Number of improvisations \( NI \)}
- \KwOut{Best harmony found}
- \SetKwFunction{FMain}{HarmonySearch}
- \SetKwProg{Fn}{Function}{:}{}
- \Fn{\FMain{$f, HMS, HMCR, PAR, NI$}}{
- \tcp{Initialize Harmony Memory (HM)}
- \For{$i \leftarrow 1$ \KwTo $HMS$}{
- \textbf{let} HM[$i$] be a randomly generated harmony\;
- }
- \tcp{Evaluate harmonies in HM}
- \For{$i \leftarrow 1$ \KwTo $HMS$}{
- HM[$i$].fitness $\leftarrow f($HM[$i$])\;
- }
- \For{$iter \leftarrow 1$ \KwTo $NI$}{
- \tcp{Improvise a new harmony}
- \textbf{let} new\_harmony be an empty harmony\;
- \For{$j \leftarrow 1$ \KwTo $n$ \tcp{for each decision variable}}{
- \eIf{rand() $< HMCR$}{
- \tcp{Memory consideration}
- $new\_harmony[j] \leftarrow$ a randomly selected value from HM\;
- \If{rand() $< PAR$}{
- \tcp{Pitch adjustment}
- $new\_harmony[j] \leftarrow new\_harmony[j] + \delta$\;
- \tcp{$\delta$ is a small adjustment value}
- }
- }{
- \tcp{Random selection}
- $new\_harmony[j] \leftarrow$ a randomly generated value within bounds\;
- }
- }
- \tcp{Evaluate the new harmony}
- new\_harmony.fitness $\leftarrow f($new\_harmony$)$\;
- \tcp{Update Harmony Memory}
- \If{new\_harmony.fitness is better than the worst harmony in HM}{
- Replace the worst harmony in HM with new\_harmony\;
- }
- }
- \textbf{return} the best harmony in HM\;
- }
- \caption{Harmony Search Meta-Heuristic Algorithm}
- \end{algorithm}
- \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement