算法排版
- 宏包
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
2.代码
\begin{frame}[plain,t]
\frametitle{The uncapacitated facility location problem}
\vspace{3ex}
\xiaowuhao
\begin{algorithm}[H]
\scriptsize
\label{alg10}
\caption{Algorithm for the uncapacitated facility location problem}
% \KwIn{input parameters A, B, C}%输入参数
% \KwOut{output result}%输出
$v \leftarrow 0 $,$ w\leftarrow 0 $\;
$ S\leftarrow D $\;
$T \leftarrow \varnothing $\;
\While{$ S\neq \varnothing $}{
//While not all clients neighbor a facility in $ T $\;
Increase ${v}_{j}$ for all $ j\in S $ and $ {w}_{ij} $ for all $ i\in N(j) $,$ j\in S $ uniformly until some $i \in T$ or some $ i\notin T $ has a tight dual inequality\;
\If{some $ j\in S $ neighbors some $ i\in T $}{
$ S\leftarrow S-\{j\} $\;
}
\If{$ i\notin T $ has a tight dual inequality}{
$ T\leftarrow T\cup \{i\} \qquad $// facility $ i $ is added to $ T $\;
$ S\leftarrow S-N(i) $\;
}
}
$ {T}^{\prime}\leftarrow \varnothing $ \;
\While{$ T\neq \varnothing $}{
Pick $ i\in T;{T}^{\prime}\leftarrow {T}^{\prime}\cup \{i\} $\;
//Remove all facilities $ h $ if some client $ j $ contributes to $ h $ and $ i $\;
$ T\leftarrow T-\{ h\in T:\exists j\in D,{w}_{ij}>0 $ and $ {w}_{hj}>0 \} $\;
}
\end{algorithm}
\end{frame}
3.效果