当前位置:   article > 正文

latex 常见伪代码_latex伪代码模板

latex伪代码模板

例一:最常见的 

  1. \def\SetClass{article}
  2. \documentclass{\SetClass}
  3. \usepackage[ruled,linesnumbered]{algorithm2e}
  4. \begin{document}
  5. \begin{algorithm}
  6. \caption{Simulation-optimization heuristic}\label{algorithm}
  7. \KwData{current period $t$, initial inventory $I_{t-1}$, initial capital $B_{t-1}$, demand samples}
  8. \KwResult{Optimal order quantity $Q^{\ast}_{t}$}
  9. $r\leftarrow t$\;
  10. $\Delta B^{\ast}\leftarrow -\infty$\;
  11. \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})$\;
  12. $\Delta B\leftarrow \Delta B^{Q}_{t,r}(I_{t-1},B_{t-1})/(r-t+1)$\;
  13. \If{$\Delta B\geq \Delta B^{\ast}$}{$Q^{\ast}\leftarrow Q$\;
  14. $\Delta B^{\ast}\leftarrow \Delta B$\;}
  15. $r\leftarrow r+1$\;}
  16. \end{algorithm}
  17. \end{document}

如图所示:

例二: 

  1. \def\SetClass{article}
  2. \documentclass{\SetClass}
  3. \usepackage[linesnumbered,lined,boxed,commentsnumbered]{algorithm2e}
  4. \begin{document}
  5. \IncMargin{1em}
  6. \begin{algorithm}
  7. \SetKwData{Left}{left}\SetKwData{This}{this}\SetKwData{Up}{up}
  8. \SetKwFunction{Union}{Union}\SetKwFunction{FindCompress}{FindCompress}
  9. \SetKwInOut{Input}{input}\SetKwInOut{Output}{output}
  10. \Input{A bitmap $Im$ of size $w\times l$}
  11. \Output{A partition of the bitmap}
  12. \BlankLine
  13. \emph{special treatment of the first line}\;
  14. \For{$i\leftarrow 2$ \KwTo $l$}{
  15. \emph{special treatment of the first element of line $i$}\;
  16. \For{$j\leftarrow 2$ \KwTo $w$}{\label{forins}
  17. \Left$\leftarrow$ \FindCompress{$Im[i,j-1]$}\;
  18. \Up$\leftarrow$ \FindCompress{$Im[i-1,]$}\;
  19. \This$\leftarrow$ \FindCompress{$Im[i,j]$}\;
  20. \If(\tcp*[h]{O(\Left,\This)==1}){\Left compatible with \This}{\label{lt}
  21. \lIf{\Left $<$ \This}{\Union{\Left,\This}}
  22. \lElse{\Union{\This,\Left}}
  23. }
  24. \If(\tcp*[f]{O(\Up,\This)==1}){\Up compatible with \This}{\label{ut}
  25. \lIf{\Up $<$ \This}{\Union{\Up,\This}}
  26. \tcp{\This is put under \Up to keep tree as flat as possible}\label{cmt}
  27. \lElse{\Union{\This,\Up}}\tcp*[h]{\This linked to \Up}\label{lelse}
  28. }
  29. }
  30. \lForEach{element $e$ of the line $i$}{\FindCompress{p}}
  31. }
  32. \caption{disjoint decomposition}\label{algo_disjdecomp}
  33. \end{algorithm}\DecMargin{1em}
  34. \end{document}

 

 

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号