Skip to content

Commit

Permalink
refined pso pseudo code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason2Brownlee committed Feb 1, 2012
1 parent ef397e5 commit 17d361e
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions book/a_swarm/pso.tex
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ \subsection{Procedure}
\SetKwData{CurrentBest}{$P_{p\_best}$}
\SetKwData{CurrentPosition}{$P_{position}$}
\SetKwData{CurrentVelocity}{$P_{velocity}$}
\SetKwData{CurrentCost}{$P_{cost}$}
% functions
\SetKwFunction{Cost}{Cost}
\SetKwFunction{StopCondition}{StopCondition}
Expand All @@ -103,9 +102,8 @@ \subsection{Procedure}
\For{$i=1$ $\KwTo$ \PopulationSize} {
\CurrentVelocity $\leftarrow$ \RandomVelocity{}\;
\CurrentPosition $\leftarrow$ \RandomPosition{\PopulationSize}\;
\CurrentCost $\leftarrow$ \Cost{\CurrentPosition}\;
\CurrentBest $\leftarrow$ \CurrentPosition\;
\If{\CurrentCost $\leq$ \GlobalBest} {
\If{\Cost{\CurrentBest} $\leq$ \Cost{\GlobalBest}} {
\GlobalBest $\leftarrow$ \CurrentBest\;
}
}
Expand All @@ -115,10 +113,9 @@ \subsection{Procedure}
\ForEach{\Particle $\in$ \Population} {
\CurrentVelocity $\leftarrow$ \UpdateVelocity{\CurrentVelocity, \GlobalBest, \CurrentBest}\;
\CurrentPosition $\leftarrow$ \UpdatePosition{\CurrentPosition, \CurrentVelocity}\;
\CurrentCost $\leftarrow$ \Cost{\CurrentPosition}\;
\If{\CurrentCost $\leq$ \CurrentBest} {
\If{\Cost{\CurrentPosition} $\leq$ \Cost{\CurrentBest}} {
\CurrentBest $\leftarrow$ \CurrentPosition\;
\If{\CurrentCost $\leq$ \GlobalBest} {
\If{\Cost{\CurrentBest} $\leq$ \Cost{\GlobalBest}} {
\GlobalBest $\leftarrow$ \CurrentBest\;
}
}
Expand Down

0 comments on commit 17d361e

Please sign in to comment.