1

I have the text for the following algorithm, but I am unable to format it, with the numbers and spacing as in the image:

enter image description here

$COVERABILITY-GRAPH((S,T,F,M_0))$\\
$(V,E,v_0):=(\{M_0\},\emptyset,M_0);$\\
Work:set:=$\{M_0\}$\\
\textbf{while} Work $\neq \emptyset$\\
\textbf{do} select $M$ from Work;\\
Work:=Work$\setminus\{M\};$\\
\textbf{for} $t\in$enabled(M)\\
\textbf{do} $M':=$fire($M,t);$\\
$M':=$AddOmegas($M,t,M',V,E$)\;\
\textbf{if} $M'\not \in V$\\
\textbf{then} $V:=V\cup \{M'\}$\\
Work:=Work$\cup\{M'\};$\\
$E:=E\cup\{(M,t,M')\}$\\
\textbf{return}$(V,E,v_0)$

and also

$ADDOMEGAS(M,t,M',V,E)$\\
\textbf{for}$M''\in V$\\
\textbf{do if} $M''<M'$ and $M''\xrightarrow{*}_{E} M$\\
\textbf{then} $M':=M'+((M'-M'').\omega);$\\
\textbf{return} $M';$
Mensch
  • 65,388

2 Answers2

2

One possibility is the following code, but please see that I leave the exact formatting of the used variables in your algorithm to you. You did not explain the code, so please check the formatting, for example if Work is a variable you can better format it with \mathit{Work}.

I used the packages

\usepackage{algorithm}% <=================http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% <========== http://ctan.org/pkg/algorithmicx

Using other packages results in other coding, so please read the documentations (please follow the given links in the comments).

With the following code

\documentclass{article}

\usepackage{algorithm}% <=================http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% <========== http://ctan.org/pkg/algorithmicx


\begin{document}
\begin{algorithm}
  \begin{algorithmic}[1] % numbering starts with 1
\Procedure {COVERABILITY-GRAPH}{$S$,$T$,$F$,$M_0$}%                     \Comment{my name is Xyz}
\State $(V,E,v_0):=(\{M_0\},\emptyset,M_0)$ % :=  --> \gets
\State $Work:$ set $:=\{M_0\}$
  \While {$Work \neq \emptyset$}
    \State select $M$ from $Work$
    \State $Work:=Work\setminus\{M\}$
    \For {$t\in$ enabled(M)}
      \State $M':=$ fire($M,t);$
      \State $M':=$ AddOmegas($M,t,M',V,E$)
      \If {$M'\not \in V$}
        \State $V:=V\cup \{M'\}$
      \EndIf
      \State $E:=E\cup\{(M,t,M')\}$
    \EndFor
  \EndWhile
  \State \Return $(V,E,v_0)$
\EndProcedure

\Procedure {ADDOMEGAS}{$M,t,M',V,E$}
  \For {$M''\in V$}
    \If {$M''<M'$ \textbf{and} $M''\rightarrow{*}_{E} M$}
      \State $M':=M'+((M'-M'')\omega)$
    \EndIf
  \EndFor
  \State \Return $M'$
\EndProcedure
 \caption{COVERABILITY}\label{alg:COVERABILITY}
\end{algorithmic}
\end{algorithm}

\end{document}

you get the following result:

resulting alg

Mensch
  • 65,388
0

Something like this?

\documentclass{article}
\usepackage{mathtools}
\usepackage{algorithm}
 \usepackage[noend]{algpseudocode}
 \usepackage{setspace, etoolbox, caption}
 \AtBeginEnvironment{algorithmic}{\setstretch{1.25}\let\textbf\textsf\vspace{0.4ex}}

\begin{document}

Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.
 \begin{algorithm}
\caption{ \textsc{Coverability-Graph} ($ (S,T,F,M₀) $)}
\begin{algorithmic}[1]
\State $(V,E,v₀) ∶= q(\{M₀\},\emptyset,M₀)$;
 \State \textit{Work}: set $ ∶= q\{M₀\}$;
 \While{$ \mathit{Work}\ne\emptyset $}
 \State select $M$ from $\mathit{Work}$;
 \State $\mathit{Work} ∶= q \mathit{Work}∖\{M\}$;
 \For{$t ∈ \mathsf{enabled}(M)$}
 \State $M' ∶= q \mathsf{fire}(M, t)$;
 \State $M' ∶= q \mathsf{AddOmegas}(M, t, M',V, E)$;
 \If{$M' ∉ V$}
 \State $V ∶= q V ∪ \{M'\}$;
 \State $\mathit{Work} ∶= q\mathit{Work} ∪ \{M'\}$;
 \EndIf
 \State $E ∶= q E ∪ \{(M, t, M')\}$;
 \EndFor
 \EndWhile
 \State
 \Return $(V, E, v₀)$;
\end{algorithmic}
\end{algorithm}

\end{document} 

enter image description here

Bernard
  • 271,350