给小白的。这个latex错误没有关系,让她在那就行了。
因为algorithmic和algorithm package出来之前,大家是用algorithmicx这个package的,algorithmicx里面就定义了algorithmic环境,而新的algorithmic和algorithm里面也有algorithmic环境,所以两个定义的冲突了。
为什么不直接卸载algorithmicx这个package?因为其他比较老的package依赖它。我卸载过,结果很多必须的package不能用,没办法还得装回来。
详见:https://tex.stackexchange.com/questions/26921/command-algorithmic-already-defined
所以如果你的编辑器报了algorithmic already defined的错,你可以:
1.只用\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}三兄弟。
语法示例如下:
\renewcommand{\algorithmicrequire}{\textbf{Input:}} % Use Input in the format of Algorithm
\renewcommand{\algorithmicensure}{\textbf{Output:}} % Use Output in the format of Algorithm
% Server & Local action
\begin{algorithm}[H]
\caption{ Server Action}
\label{alg:Server Action}
\begin{algorithmic}[1]
\Require $D_i$,$f_i$,$key_i$\\
\Ensure global model or $f_i$ itself
\State wait until each $D_i$ is sent
\State $D_i=Decrypt(D_{i}^{'})$
\State $D$=Aggregate($D_1$,$D_2$,$D_3$,...,$D_n$)
\State F=Train($D_{train}$)
\State meanwhile
\State wait until every $f_i$ is sent and F training process is finished.
\For{$i=0$;$i<n$;$i++$}
\State calculate $error_i$
\EndFor
\State calculate $error_F$
\If {$error_i$<$error_F$}
\Return F to $client_i$;
\Else \
\Return $f_i$ to $client_i$;
\EndIf
\end{algorithmic}
\end{algorithm}
尽管我用的tex studio还是会在\State \EndIf这些明亮上红色标出,但是编译已经没有错误的输出了,可以exit normally。