代码:
\documentclass[12pt, letterpaper]{article}
\usepackage[ruled,lined]{algorithm2e}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithm}[H]
\caption{RRT Algorithm}
\LinesNumbered
\KwIn{$\mathcal{M}$: map information\newline
$q_{init}$: start point\newline
$q_{goal}$: end point\newline
$d_q$: step size
}
\KwOut{$\mathcal{T}$: tree}
\textbf{Initialize:} $\mathcal{T}.addEdge(q_{init},q_{init})$;\\
\For{$i \in [1,n]$}{
$q_{rand} \gets Sample(\mathcal{M});$\\
$q_{near} \gets Near(q_{rand},\mathcal{T});$\\
$q_{new} \gets Steer(q_{rand},q_{near},d_q);$\\
$E_i \gets Edge(q_{new},q_{near});$\\
\If{$CollisionFree(\mathcal{M},E_i)$}{
$\mathcal{T}.addEdige(E_i)$;
}
\If{$q_{new}=q_{goal}$}{
break;
}
}
\end{algorithm}
\end{document}
结果: