伪代码的垂直线

伪代码的垂直线
\documentclass[two column,conference]{IEEEtran}
\usepackage{algorithm}
\begin{document}
\begin{algorithm}
    \caption{HD}
    \label{array-sum}
    1: Initialization of parameters \\
    2: Randomly generate population using Eq. 28\\
    3: \textbf{for} u=1:k \\
    4: \textbf{for} s=1:i$_{c}$\\
    5:  Randomly generated X$_{s}^{u}$ in da\\
    6: \textbf{end for} \\
    7: \textbf{end for}\\
    8: End of initialization step\\
    9: \textbf{While} Maximum number of iteration reached \textbf{do}\\
    10:  Construction and assessment of new candidate\\
    11: \textbf{if} ($rand (0,1)\leq$ cpu)\\
    12: Choose random no \\
    13: \textbf {if} ($rand (0,1 ) \leq$ cpu) \\
    14:  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    15: \textbf{end if} \\
    16: \textbf{else} \\
    17: Evaluate fitness function a: F(a) using Eq. 17\\
    27: End of the construction and assessment step\\
    28: Construction and assessment of new candidate: a   \\
    29: if (F(y) has best value than the worst member \\
    30: Replace DA member with new candidate: a\\
    31: else\\
    32: Discard x\\
    33: \textbf{endif}\\
    34: End of update\\
    35: Until a preset termination criterion is met\\
    36: end \textbf{while}\\
\end{algorithm}
\end{document}

我想为循环和 if 语句绘制垂直线。请帮帮我,而且我没有使用任何特定的包

答案1

您必须加载algorithm2e才能轻松完成此操作:

\documentclass[two column,conference]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage[ruled, lined, longend, linesnumbered]{algorithm2e}

\begin{document}

\begin{algorithm}
    \caption{HD}
    \label{array-sum}
     Initialization of parameters\;
     Randomly generate population using Eq. 28\;
   \For{u=1:k}{%
     \For{s=1:i$_{c}$}{%
     Randomly generated X$_{s}^{u}$ in da \;
            }
            }
     End of initialization step\;
     \While{Maximum number of iteration reached}{
    Construction and assessment of new candidate\;
    \eIf{($rand (0,1)\leq$ cpu)}{%
     Choose random no \;
     \textbf {if} ($rand (0,1 ) \leq$ cpu) \\
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     \textbf{end if}
     }{%
     Evaluate fitness function a: F(a) using Eq. 17 \;
     End of the construction and assessment step\;
     Construction and assessment of new candidate: a \;
     \eIf {(F(y) has best value than the worst member}{
     Replace DA member with new candidate: a
     }{%
     Discard x}%
        }%
     End of update\;
     Until a preset termination criterion is met}
\end{algorithm}

\end{document} 

在此处输入图片描述

相关内容