Sjtuthesis: How to use algorithm2e in the template

Created on 16 Feb 2019  ·  9Comments  ·  Source: sjtug/SJTUThesis

如果简单在thesis.tex中添加\usepackage[options]{algorithm2e},会出现问题。请问如何在该模板中优雅地使用algorithm2e包呢?

typquestion

Most helpful comment

当然可以用,不过你要自己改模版类。下一版我准备用 algorithm2e 替换掉 algorithmsalgorithmicx

All 9 comments

不好意思,这个问题我也不清楚,可能 @AlexaraWu 大佬知道怎么做

排版算法的话,模版中已经内置了 algorithms 包和 algorithmicx 包,具体如何使用请参照示例文档。

其实就是想知道能不能用,或者怎么用algorithm2e。虽然algorithms和algorithmicx也能用,但毕竟algorithm2e能够排版出更美观的算法流程图,自己投稿的论文都用的是algorithm2e,但是直接迁移过来发现会出问题。

当然可以用,不过你要自己改模版类。下一版我准备用 algorithm2e 替换掉 algorithmsalgorithmicx

正在 develop 分支上做 algorithm2e 的适配。

@shuoooo 能否分享一些您日常使用 algorithm2e 的设置和样例(越复杂越好),以供开发时参考。

正在 develop 分支上做 algorithm2e 的适配。

@shuoooo 能否分享一些您日常使用 algorithm2e 的设置和样例(越复杂越好),以供开发时参考。

\usepackage[ruled,vlined,linesnumbered]{algorithm2e}

\begin{algorithm}[t] \small
\label{allocation}
\caption{Channel Selection and Payment Calculation ($a_i$)}
%\tcp{Collect preemptive neighbors' msgs}
$\mathbb{N}'_i\gets\varnothing$, $\mathbb{AC}_i \gets \mathbb{C}$, $p_i=0$\;

\ForEach{$a_j \in \mathbb{PN}_i$}
{\label{receive2_begin}
    Receive $\text{MSG}_j$ from agent $a_j$\;
    \ForEach{$\text{MSGP}_k = <\text{PAY},k>$ in $\text{MSG}_j$}{
        $\mathbb{N}'_i\gets\mathbb{N}'_i\cup\{a_k\}$\;
    }
    Extract $\text{MSGC}_j = <\text{CHL},j,\mathbb{C}^*_j>$ from $\text{MSG}_j$\;
    $\mathbb{AC}_i \gets \mathbb{AC}_i \backslash \mathbb{C}^*_j$\;\label{receive2_end}
}
%\tcp{Select channel(s)}
\If{$|\mathbb{AC}_i| \geq  d_i$}{\label{allocation2_begin}
    $\mathbb{C}^*_i \gets \first(\mathbb{AC}_i,d_i)$\;

    $\text{MSGC}_i \gets <\text{CHL},i,\mathbb{C}^*_i>$,
    $\text{MSGP}_i \gets <\text{PAY},i>$\;\label{msgp}
}\lElse{
    \label{allocation2_end} $\mathbb{C}^*_i \gets \varnothing$\;
}
%\tcp{Payment determining channel reselection}
\ForEach{$a_k\in\mathbb{N}'_i$}
{\label{reselection_begin}
    $\mathbb{AC}_{i|-k}\gets \mathbb{C}$\;
    \ForEach{$a_j\in \mathbb{PN}_i$}
    {\label{avail_resel_begin}
        Extract $\text{MSGR}_{j,k} = <\text{RPY},j,k,\mathbb{C}_{j|-k}>$ from $\text{MSG}_j$\;
        \lIf{$\text{MSGR}_{j,k}$ exists}{
            $\mathbb{AC}_{i|-k}\gets \mathbb{AC}_{i|-k} \setminus \mathbb{C}_{j|-k}$\;
        }\lElse{
            $\mathbb{AC}_{i|-k}\gets \mathbb{AC}_{i|-k} \setminus  \mathbb{C}^*_j$\;
        }\label{avail_resel_end}
    }
    \lIf{$|\mathbb{AC}_{i|-k}| \geq  d_i$}{\label{resel_begin}
        $\mathbb{C}_{i|-k} \gets \first(\mathbb{AC}_{i|-k},d_i)$\;
    }\lElse{
        $\mathbb{C}_{i|-k} \gets \varnothing$\;
    }\label{resel_end}
    $\text{MSGR}_{i,k} \gets <\text{RPY},i,k,\mathbb{C}_{i|-k}>$\;
    $\text{MSGR}_i \gets \text{MSGR}_i ~||~ \text{MSGR}_{i,k}$\; \label{encap_resel}
    $\text{MSGP}_i \gets \text{MSGP}_i ~||~ \text{MSGP}_k$\; \label{reselection_end}
}

Send $\text{MSG}_i \gets \text{MSGC}_i ~||~ \text{MSGP}_i ~||~ \text{MSGR}_i$ to $\mathbb{N}_i$\;\label{send_msg}
%\tcp{Collect feedback neighbors' msgs}

\If{$\mathbb{C}^*_i\neq\varnothing$}{
    Sort agents in $\mathbb{FN}_i$ in decreasing order of bids as $\overline{\mathbb{FN}}_i$\;\label{pay_sort}
    \ForEach{$a_j \in \overline{\mathbb{FN}}_i$}{\label{cal_pay_begin}
        Receive $\text{MSG}_j$  from agent $a_j$\;
        Extract $<\text{RPY},j,i,\mathbb{C}_{j|-i}>$ from $\text{MSG}_j$\;
        $\mathbb{AC}_i \gets \mathbb{AC}_i \setminus \mathbb{C}_{j|-i}$\;
        \lIf{$|\mathbb{AC}_i| < d_i$}{
            $p_i \gets b_j \times d_i$; \textbf{break}\;
        }\label{cal_pay_end}
    }
}
\textbf{Return} $\mathbb{C}^*_i$ and $p_i$;
\end{algorithm}

\first 这个命令是哪个宏包提供的?

\first 这个命令是哪个宏包提供的?

额。。这个可以忽略。。自己定义的

develop 分支上加了 algorithm2e 的设置。主要是设置了编号、索引样式与原来的保持一致。现在因为用了 ctexhook,调用相应宏包才会加载其设置,所以 algorithm 的设置也保留了。

Was this page helpful?
0 / 5 - 0 ratings