[Tex/LaTex] Show parallelism of Algorithm

algorithms

I want to show that a certain part in a algorithm is working parallel.
So I thought about something like a big bracket around the lineS/state in my algorithm.

In the following picture I added the bracket with Photoshop:

enter image description here

Is there a way to this with the algorithm/algorithmic package in Latex?

Source-Code:

\begin{algorithm}
\caption{Parallele Tourkonstruktion}
\label{ParallelTour}
\textbf{Eingabe:} Datenobjekt mit $v$ Städten sowie einer Distanzmatrix $D$ und Pheromonmatrix $S$, \texttt{vector} $M$ mit $m$ Ameisen
\\\textbf{Ausgabe:} Route $r$ mit der kürzesten gefunden Distanz $d_s$
\begin{algorithmic}[1]
\State $j := 0$
\While{$j < v$}
\For{\textbf{each} Ameise $m_i \in M$}
\State Starte in einer zufälligen Stadt $v_0$
\State Ermittle die nächste Stadt $v_i$ und gehe dorthin
\State $r_{m_i} := v_i$
\State $d_m := d_m + D_{i-1,i}$
\State Aktualisiere Pheromonmatrix $S$
\EndFor
\State $j := j + 1$
\EndWhile
\State $d_s = \infty$
\For{\textbf{each} Ameise $m_i \in M$}
\If{Tourlänge $d_m < d_s$}
\State $d_s := d_m$
\EndIf
\EndFor
\end{algorithmic}
\end{algorithm}

Best Answer

You can set a \smashed math construction to span the five rows within the for each:

enter image description here

\documentclass{article}

\usepackage{algorithm,mathtools}
\usepackage[noend]{algpseudocode}
\usepackage[utf8]{inputenc}

\newcommand{\isassigned}{\vcentcolon=}

\begin{document}

\begin{algorithm}
  \caption{Parallele Tourkonstruktion}
  \textbf{Eingabe:} Datenobjekt mit $v$ Städten sowie einer Distanzmatrix $D$ 
    und Pheromonmatrix $S$, \texttt{vector} $M$ mit $m$ Ameisen \\
  \textbf{Ausgabe:} Route $r$ mit der kürzesten gefunden Distanz $d_s$
  \begin{algorithmic}[1]
    \State $j \isassigned 0$
    \While{$j < v$}
      \For{\textbf{each} Ameise $m_i \in M$}
        \State Starte in einer zufälligen Stadt $v_0$
        \State Ermittle die nächste Stadt $v_i$ und gehe dorthin
        \State $r_{m_i} \isassigned v_i$ 
          \hspace{17em}\smash{$\left.\rule{0pt}{2.7\baselineskip}\right\}\ \mbox{in parallel}$}
        \State $d_m \isassigned d_m + D_{i-1,i}$
        \State Aktualisiere Pheromonmatrix $S$
      \EndFor
      \State $j \isassigned j + 1$
    \EndWhile
    \State $d_s = \infty$
    \For{\textbf{each} Ameise $m_i \in M$}
      \If{Tourlänge $d_m < d_s$}
      \State $d_s \isassigned d_m$
      \EndIf
    \EndFor
  \end{algorithmic}
\end{algorithm}

\end{document}

If you want the construction to cover the for each as well, then you can use

% ...
      \For{\textbf{each} Ameise $m_i \in M$}
        \State Starte in einer zufälligen Stadt $v_0$
        \State Ermittle die nächste Stadt $v_i$ und gehe dorthin
        \State $r_{m_i} \isassigned v_i$ 
          \hspace{17em}\raisebox{.5\baselineskip}[0pt][0pt]{$\left.\rule{0pt}{3.2\baselineskip}\right\}\ \mbox{in parallel}$}
        \State $d_m \isassigned d_m + D_{i-1,i}$
        \State Aktualisiere Pheromonmatrix $S$
      \EndFor
% ...

enter image description here

Related Question