Advertisement
mayankjoin3

Untitled

Jun 19th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. \documentclass{article}
  2. \usepackage[linesnumbered,ruled,vlined]{algorithm2e}
  3.  
  4. \begin{document}
  5.  
  6. \begin{algorithm}[H]
  7. \SetAlgoLined
  8. \KwIn{Objective function \( f \), Harmony memory size \( HMS \), Harmony memory consideration rate \( HMCR \), Pitch adjustment rate \( PAR \), Number of improvisations \( NI \)}
  9. \KwOut{Best harmony found}
  10.  
  11. \SetKwFunction{FMain}{HarmonySearch}
  12. \SetKwProg{Fn}{Function}{:}{}
  13.  
  14. \Fn{\FMain{$f, HMS, HMCR, PAR, NI$}}{
  15. \tcp{Initialize Harmony Memory (HM)}
  16. \For{$i \leftarrow 1$ \KwTo $HMS$}{
  17. \textbf{let} HM[$i$] be a randomly generated harmony\;
  18. }
  19.  
  20. \tcp{Evaluate harmonies in HM}
  21. \For{$i \leftarrow 1$ \KwTo $HMS$}{
  22. HM[$i$].fitness $\leftarrow f($HM[$i$])\;
  23. }
  24.  
  25. \For{$iter \leftarrow 1$ \KwTo $NI$}{
  26. \tcp{Improvise a new harmony}
  27. \textbf{let} new\_harmony be an empty harmony\;
  28.  
  29. \For{$j \leftarrow 1$ \KwTo $n$ \tcp{for each decision variable}}{
  30. \eIf{rand() $< HMCR$}{
  31. \tcp{Memory consideration}
  32. $new\_harmony[j] \leftarrow$ a randomly selected value from HM\;
  33. \If{rand() $< PAR$}{
  34. \tcp{Pitch adjustment}
  35. $new\_harmony[j] \leftarrow new\_harmony[j] + \delta$\;
  36. \tcp{$\delta$ is a small adjustment value}
  37. }
  38. }{
  39. \tcp{Random selection}
  40. $new\_harmony[j] \leftarrow$ a randomly generated value within bounds\;
  41. }
  42. }
  43.  
  44. \tcp{Evaluate the new harmony}
  45. new\_harmony.fitness $\leftarrow f($new\_harmony$)$\;
  46.  
  47. \tcp{Update Harmony Memory}
  48. \If{new\_harmony.fitness is better than the worst harmony in HM}{
  49. Replace the worst harmony in HM with new\_harmony\;
  50. }
  51. }
  52.  
  53. \textbf{return} the best harmony in HM\;
  54. }
  55. \caption{Harmony Search Meta-Heuristic Algorithm}
  56. \end{algorithm}
  57.  
  58. \end{document}
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement