赞
踩
- \def\SetClass{article}
- \documentclass{\SetClass}
- \usepackage[ruled,linesnumbered]{algorithm2e}
- \begin{document}
- \begin{algorithm}
- \caption{Simulation-optimization heuristic}\label{algorithm}
- \KwData{current period $t$, initial inventory $I_{t-1}$, initial capital $B_{t-1}$, demand samples}
- \KwResult{Optimal order quantity $Q^{\ast}_{t}$}
- $r\leftarrow t$\;
- $\Delta B^{\ast}\leftarrow -\infty$\;
- \While{$\Delta B\leq \Delta B^{\ast}$ and $r\leq T$}{$Q\leftarrow\arg\max_{Q\geq 0}\Delta B^{Q}_{t,r}(I_{t-1},B_{t-1})$\;
- $\Delta B\leftarrow \Delta B^{Q}_{t,r}(I_{t-1},B_{t-1})/(r-t+1)$\;
- \If{$\Delta B\geq \Delta B^{\ast}$}{$Q^{\ast}\leftarrow Q$\;
- $\Delta B^{\ast}\leftarrow \Delta B$\;}
- $r\leftarrow r+1$\;}
- \end{algorithm}
- \end{document}
如图所示:
例二:
- \def\SetClass{article}
- \documentclass{\SetClass}
- \usepackage[linesnumbered,lined,boxed,commentsnumbered]{algorithm2e}
- \begin{document}
- \IncMargin{1em}
- \begin{algorithm}
- \SetKwData{Left}{left}\SetKwData{This}{this}\SetKwData{Up}{up}
- \SetKwFunction{Union}{Union}\SetKwFunction{FindCompress}{FindCompress}
- \SetKwInOut{Input}{input}\SetKwInOut{Output}{output}
-
- \Input{A bitmap $Im$ of size $w\times l$}
- \Output{A partition of the bitmap}
- \BlankLine
- \emph{special treatment of the first line}\;
- \For{$i\leftarrow 2$ \KwTo $l$}{
- \emph{special treatment of the first element of line $i$}\;
- \For{$j\leftarrow 2$ \KwTo $w$}{\label{forins}
- \Left$\leftarrow$ \FindCompress{$Im[i,j-1]$}\;
- \Up$\leftarrow$ \FindCompress{$Im[i-1,]$}\;
- \This$\leftarrow$ \FindCompress{$Im[i,j]$}\;
- \If(\tcp*[h]{O(\Left,\This)==1}){\Left compatible with \This}{\label{lt}
- \lIf{\Left $<$ \This}{\Union{\Left,\This}}
- \lElse{\Union{\This,\Left}}
- }
- \If(\tcp*[f]{O(\Up,\This)==1}){\Up compatible with \This}{\label{ut}
- \lIf{\Up $<$ \This}{\Union{\Up,\This}}
- \tcp{\This is put under \Up to keep tree as flat as possible}\label{cmt}
- \lElse{\Union{\This,\Up}}\tcp*[h]{\This linked to \Up}\label{lelse}
- }
- }
- \lForEach{element $e$ of the line $i$}{\FindCompress{p}}
- }
- \caption{disjoint decomposition}\label{algo_disjdecomp}
- \end{algorithm}\DecMargin{1em}
- \end{document}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。