是否可以将以下两个算法放在同一个文件中。我试了几次,但没有成功。谢谢你的帮助。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[ruled,vlined,noresetcount]{algorithm2e}
%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{algorithm,algpseudocode,amsmath}
\makeatletter
\newcounter{phase}[algorithm]
\newlength{\phaserulewidth}
\newcommand{\setphaserulewidth}{\setlength{\phaserulewidth}}
\newcommand{\phase}[1]{%
\vspace{-1.25ex}
% Top phase rule
\Statex\leavevmode\llap{\rule{\dimexpr\labelwidth+\labelsep}{\phaserulewidth}}\rule{\linewidth}{\phaserulewidth}
\Statex\strut\refstepcounter{phase}\textit{Phase~\thephase~--~#1}% Phase text
% Bottom phase rule
\vspace{-1.25ex}\Statex\leavevmode\llap{\rule{\dimexpr\labelwidth+\labelsep}{\phaserulewidth}}\rule{\linewidth}{\phaserulewidth}}
\makeatother
\setphaserulewidth{.7pt}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{algorithm}
\DontPrintSemicolon
\KwData{$S, C$}
\KwResult{$X$}
\Begin{
$X \leftarrow \emptyset$\;
\For{$C \neq \emptyset$}{
$A \leftarrow$ arbitrary element in $C$\;
$a \leftarrow$ arbitrary element in $a$\;
$X \leftarrow X \cup \{a\}$\;
$C \leftarrow C \setminus \{A \in C\ |\ A \cap X \neq \emptyset\}$\;
}
\Return{$X$}\;
}
\caption{Alg-1}
\end{algorithm}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{algorithm}
\caption{Selection algorithm}
\begin{algorithmic}[1]
\State initialization
\State $\var{ini} = 4$
\State $\var{init} = 0$
\phase{Drifting phase}
\Procedure {DriftingPhase}{}
\For{each source~$S$}
\State Broadcast IWD--
\For{each IWD}
\vspace{0.05in}
\State Compute $\func{soil}(i,j) = (1-\Pi\psi) \times \func{soil}(i,j)-\Pi\psi \Delta \func{soil}(i,j)$
\vspace{0.01in}
\State Compute $P_r = (i,j) = \frac{f(\func{soil}(i,j))}{\sum\nolimits_{k \notin \func{vc}(IWD)}{f(\func{soil}(i,k)}}$
\State $f(\func{soil}(i,j)) = \frac{1}{\func{soil}(i,j)}$
\EndFor
\EndFor
\EndProcedure
\phase{FindingRoute phase}
\Procedure{FindingRoute phase}{}
\For{each destination $D$ }
\State $\func{MPRset}(D) = \max\{P_r(z) \cup z \in R\}$
\State Send IWD-Rep $2$-hop away
\EndFor
\EndProcedure
\phase{Final phase}
\Procedure{finalPhase}{}
\For{each source $S$}
\State $\func{MPRset}(S) = \max\{P_r(z) \cup z \in R\}$
\EndFor
\State $\var{MPRRoute} = [S]$
\EndProcedure
\end{algorithmic}
\end{algorithm}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}