我正在使用该包algorithm2e
,具体来说,\usepackage[ruled,vlined,linesnumbered,noresetcount]{algorithm2e}
创建了以下算法:
\documentclass[12pt]{article}
%
\usepackage{amsmath}
\usepackage{blindtext}
\usepackage{caption}
%\usepackage{algorithm,algorithmic}
\usepackage[ruled,vlined,linesnumbered,noresetcount]{algorithm2e}
\numberwithin{algorithm}{section}
%
\begin{document}
%
\section{Example of GA}
\label{sec_1}
\blindtext
\begin{algorithm}[h!]
\KwData{The fitness function $f$, a stop criterion.}
\KwResult{An approximation of $f^{*}$ and the point where is attained. }
\textbf{Initialization}\;
\begin{enumerate}[(a)]
\item $\mathrm{ExitLoop}\leftarrow \mathrm{false}$.
\item Generate an initial population $P$.
\item Evaluate the fitness at each point of $P$.
\item Best point selection on $P$, $p^{*}\leftarrow \arg \min\{f(p):p\in P\}$, and its value $f(p^{*})$.
\end{enumerate}
\nl \textbf{Loop}\;
\While{$\mathrm{ExitCondition}= \mathrm{false}$}{
\nl\textbf{Update the population}\;
\begin{enumerate}[(a')]
\item Using selection, crossover and mutation prefixed rules, generate \newline a new population $P'$
\item $P\leftarrow P'$.
\item Compute $p^{*}$ and $f(p^{*})$ as in (d).
\end{enumerate}
\nl \textbf{Decision}\;
\If{stop criterion is attained}{
$\mathrm{ExitLoop}\longleftarrow \mathrm{true}$\;
\Return{$p^{*}$ and $f(p^{*})$}\;
}
}
\caption{General scheme of a GA}
\label{alg_1_10}
\end{algorithm}
%
\end{document}
算法生成正确,但标题显示“算法 1:GA 的一般方案“, 代替 ”算法 1.1:GA 的一般方案“,这就是我想要的。
该命令\numberwithin{algorithm}{section}
生成以下错误:
! LaTeX Error: No counter 'algorithm' defined.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \numberwithin{algorithm}{section}
出了什么问题?