LateX--插入伪代码类型详解

1.算法伪代码流程图----循环带范围

#需要插入这个宏包
\usepackage[ruled,linesnumbered]{algorithm2e}

1.1.算法伪代码示例图1

在这里插入图片描述

\begin{algorithm}[H]
    \caption{How to write algorithms}
    \KwIn{this text}
    \KwOut{how to write algorithm with \LaTeX2e }
    
    initialization\;
    
    \While{not at end of this document}{
        read current\;
        
        \eIf{understand}{
            go to next section\;
            current section becomes this one\;
        }{
            go back to the beginning of current section\;
        }
    }
\end{algorithm}

1.2.算法伪代码示例图2

在这里插入图片描述

\begin{algorithm}
    \caption{identifyRowContext}
    \KwIn{$r_i$, $Backgrd(T_i)$=${T_1, T_2, \ldots, T_n}$ and similarity threshold $\theta_r$}
    \KwOut{$con(r_i)$}
    
    $con(r_i) = \Phi$\;
    
    \For{$j = 1; j \le n; j \ne i$}
    {
        float $maxSim = 0$\;
        $r^{maxSim} = \text{null}$\;
        
        \While{not end of $T_j$}
        {
            compute Jaro($r_i, r_m$) ($r_m \in T_j$)\;
            
            \If{$(Jaro(r_i, r_m) \ge \theta_r) \wedge (Jaro(r_i, r_m) \ge r^{maxSim})$}
            {
                replace $r^{maxSim}$ with $r_m$\;
            }
        }
        $con(r_i) = con(r_i) \cup \{r^{maxSim}\}$\;
    }
    \Return $con(r_i)$\;
\end{algorithm}

2.算法伪代码流程图----循环不带范围

#需要导入以下信息
\usepackage{algorithm}  
\usepackage{algpseudocode}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}  % Use Input in the format of Algorithm
\renewcommand{\algorithmicensure}{\textbf{Output:}} % Use Output in the format of Algorithm

在这里插入图片描述


\begin{algorithm}[h]
  \caption{Pseudocode of Simulated Annealing Algorithm} % 名称
  \begin{algorithmic}[1]
    \Require
      $x_0$: initial individual or state;
      $T_0$: a high enough initial temperature;
      $T_{min}$: the lowest limit of temperature;
    \Ensure
       optimal state or approximate optimal state;
       \State set $x_0 = x_{best}$, compute initial energy function $E(x_0)$;
       \While {$T > T_{min}$}
         \For{$i = 1$; $i<n$; $i++$ }
      \State perturb current state $x_i$ for a new state $x_{new}$ and compute energy function $E(x_{new})$;
      \State compute $\Delta$ = $E(x_{new}-E(x_{(i)})$;
      \If {$\Delta$$E<0$} \State $x_{best} = x_{new}$
      \Else \State the probability $P = exp(-dE/T_{(i)})$;
      \If {$rand(0,1) < P$ }\State $x_{best} = x_{new}$
      \Else \State $x_{best} = x_{best}$
      \EndIf
     \EndIf
     \EndFor
      \State $T = T * $ $ \alpha$, where $\alpha$ is decay factor  ;
    \EndWhile
  \end{algorithmic}
\end{algorithm}

3.算法伪代码流程图—不带行数数字

#需要导入以下宏包
\usepackage{algorithm,algorithmic}

在这里插入图片描述

\begin{algorithm}[!ht]
	\caption{Power method}
    \label{power1}
    \begin{algorithmic} % 控制是否有序号
        \STATE step 1: $a = b-1;$
        \STATE step 2: $c = a+b;$
        \STATE step 3: $a = a+b;$
        \STATE step 4: $b= a+b;$
        \STATE step 5: $f= a+b;$
    \end{algorithmic}
\end{algorithm}

4.参考文献

[1].https://zhuanlan.zhihu.com/p/266241159
[2].https://blog.csdn.net/frx_bwcx/article/details/120641816
[3].https://blog.csdn.net/lovehuishouzan/article/details/126797276
[4].https://blog.csdn.net/qq_44425179/article/details/131591951
[5].https://zhuanlan.zhihu.com/p/618711187
  • 21
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

温柔济沧海

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值