-
Notifications
You must be signed in to change notification settings - Fork 0
Algorithms
Thomas Couchoud edited this page Mar 7, 2019
·
3 revisions
La classe de document polytech
inclut la package algorithm2e
.
Cette classe est configurée pour vous permettre d'écrire vos algorithmes directement en anglais. Les possibilités offertes par ce package sont très importantes, il vous est donc recommandé de consulter la documentation associée. Vous pouvez notamment si les mots clés existants ne vous suffisent pas en ajouter.
Un exemple :
\begin{algorithm}
\caption{Exploitation of the food sources by the onlookers}
\label{cha:OtherNatureInspiredAlgorithms:algo:abc-exploit}
\tcc{Compute the probabilities from interests}
\For{$i=1$ \KwTo $\left\vert\mathbb{S}\right\vert$}{
$p_i=\frac{q(f(s_i))}{\sum\limits_{s\in\mathbb{S}}q(f(s))}$
}
\tcc{Onlookers exploit the food sources}
\For{$i=1$ \KwTo $\mathcal{N}_\text{onlooker}$}{
$x_i\gets\mathcal{R}(\llbracket1:\left\vert\mathbb{S}\right\vert\rrbracket \sim \mathcal{P})$
\tcc*[r]{$s_{x_i}$ is the food source chosen}
\tcc*[r]{by the bee according to $\mathcal{P}$}
$s_n\gets\mathcal{U}(\mathbb{S}-\{s_{x_i}\})$
\tcc*[r]{Choose the influencing food source}
$k\gets\mathcal{U}(\llbracket1:D\rrbracket)$
\tcc*[r]{Choose the modified coordinate}
$w_i\gets s_{x_i}$ \\
$w_{i,k}\gets s_{x_i,k}+\mathcal{U}([-1:1])*(s_{x_i,k}-s_{n,k})$ \tcc*[r]{Mutate the solution}
}
\tcc{Update the food sources and their counters}
\For{$i=1$ \KwTo $\mathcal{N}_\text{onlooker}$}{
\eIf(\tcc*[f]{The new solution is more interesting}){$f(w_i)<f(s_{x_i})$}{
$e_{x_i}\gets0$ \\
$s_{x_i}\gets w_i$ \\
\If(\tcc*[f]{The best solution is improved}){$f(w_i)<f(s^*)$}{
$s^*\gets w_i$
}
}(\tcc*[f]{The new solution is worse}){
$e_{x_i}\gets e_{x_i}+1$
}
}
\end{algorithm}