![Pseudocode Example](https://writelatex.s3.amazonaws.com/published_ver/11752.jpeg?X-Amz-Expires=14400&X-Amz-Date=20240630T152152Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAWJBOALPNFPV7PVH5/20240630/us-east-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=e9f3b413de66f410842a9f63130feff364636394456b7a5c4223b5af4f9e9604)
Pseudocode Example
Author
IserlohnArchmage
Last Updated
5 years ago
License
Creative Commons CC BY 4.0
Abstract
An example showing how to use pseudocode in Algorithmcx.
![Pseudocode Example](https://writelatex.s3.amazonaws.com/published_ver/11752.jpeg?X-Amz-Expires=14400&X-Amz-Date=20240630T152152Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAWJBOALPNFPV7PVH5/20240630/us-east-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=e9f3b413de66f410842a9f63130feff364636394456b7a5c4223b5af4f9e9604)
An example showing how to use pseudocode in Algorithmcx.
\documentclass[a4paper,11pt]{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithm}
\caption{PPO}
\begin{algorithmic}[1]
\For {$iteration=1,2,\ldots$}
\For {$actor=1,2,\ldots,N$}
\State Run policy $\pi_{\theta_{old}}$ in environment for $T$ time steps
\State Compute advantage estimates $\hat{A}_{1},\ldots,\hat{A}_{T}$
\EndFor
\State Optimize surrogate $L$ wrt. $\theta$, with $K$ epochs and minibatch size $M\leq NT$
\State $\theta_{old}\leftarrow\theta$
\EndFor
\end{algorithmic}
\end{algorithm}
\begin{algorithm}
\caption{Game Theory Controller}
\begin{algorithmic}[1]
\For {Every time step}
\State Calculate target seeking command $\mathbf{x}_{tsCmd}$ (Eq.: 3.12)
\For {All map measurements from $\mathbf{x}_{Map}$}
\State Denormalize measurement (Eq.: 3.14)
\State Add margin of safety (Eq.: 3.15)
\State Calculate altitude difference $\Delta h_{ObsSafe_{j}}$ to aircraft (Eq.: 3.16)
\If {$\Delta h_{ObsSafe_{j}}>0$}
\State Add measurement to set of critical measurements $\mathcal{M}_{crit}$ (Eq.: 3.17)
\EndIf
\EndFor
\For {All measurements in $\mathcal{M}_{crit}$}
\State Calculate local obstacle avoidance vector (Eq.: 3.20)
\EndFor
\State Sum over all local avoidance vectors (Eq.: 3.22)
\State Transform to global coordinate frame to receive $\mathbf{x}_{oaCmd}$ (Eq.: 3.23)
\State Calculate obstacle avoidance weight $w_{oa}$ based on critical zone weight (Eq.: 3.24)
\State Calculate target seeking weight $w_{ts}$ as $1-w_{oa}$ (Eq.: 3.13)
\State Calculate command vector $\mathbf{x}_{HSaCmd}=w_{oa}\mathbf{x}_{oaCmd}+w_{ts}\mathbf{x}_{tsCmd}$ (Eq.: 3.11)
\EndFor
\end{algorithmic}
\end{algorithm}
\end{document}