当前位置: 首页 > news >正文

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

文章目录

    • 1.算法伪代码流程图----循环带范围
      • 1.1.算法伪代码示例图1
      • 1.2.算法伪代码示例图2
    • 2.算法伪代码流程图----循环不带范围
    • 3.算法伪代码流程图---不带行数数字
    • 4.参考文献

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;\Ensureoptimal 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
http://www.lryc.cn/news/285311.html

相关文章:

  • 《Python数据分析技术栈》第06章使用 Pandas 准备数据 04 DataFrames
  • wayland(xdg_wm_base) + egl + opengles 最简实例
  • MySQL部署
  • 【ARM 嵌入式 编译系列 3.7 -- newlib 库文件与存根函数 stubs 详细介绍】
  • 【C++】结构体
  • web架构师编辑器内容-拖动元素改变元素的位置和大小的完成
  • 基于CNN的水果识别-含数据集训练模型
  • Hadoop基本概论
  • 2023年12月 Scratch 图形化(一级)真题解析#中国电子学会#全国青少年软件编程等级考试
  • burp靶场--访问控制【越权】
  • C#使用DateTime.Now静态属性动态获得系统当前日期和时间
  • 华为机考入门python3--(0)模拟题2-vowel元音字母翻译
  • 【轮式平衡机器人】——角度/速度/方向控制分析软件控制框架
  • HYBBS 表白墙网站PHP程序源码 可封装成APP
  • 【设计模式】适配器和桥接器模式有什么区别?
  • C语言应用层程序热补丁
  • 【代码随想录+力扣hot100】双指针
  • 【Java程序员面试专栏 专业技能篇】MySQL核心面试指引(三):性能优化策略
  • qnx 上screen + egl + opengles 最简实例
  • python基础学习-02
  • 服务调用Ribbon,LoadBalance,Feign
  • 一条sql是如何运行的
  • SystemC学习笔记(三) - 查看模块的波形
  • 计算机网络(第六版)复习提纲5
  • JavaScript 学习笔记(WEB APIs Day3)
  • Springboot自动装配:三个注解、Selector、spring.factories文件、@ConditionalOnProperty注解
  • 软件工程应用题汇总
  • P1789 【Mc生存】插火把(C语言)
  • 计算机网络(第六版)复习提纲6
  • 安卓平板局域网内远程控制工控机方法