Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing sorting networks [closed]

What's a good way to draw sorting networks that look like those at the bottom of this post? A python package or LaTeX typsetting package would be much appreciated.

Sorting network with groupings Simple sorting network

like image 628
chausies Avatar asked Sep 02 '15 16:09

chausies


1 Answers

It is very possible that some more specific LaTeX packages exist to draw such networks, but you can start from having a look at TikZ package (manual). This is how I (quickly) reproduced the simpler of the two images in your question using TikZ:

\documentclass[tikz,border=5mm]{standalone}

\begin{document}

\begin{tikzpicture}
%\fill [gray!15] (1.5,1.5) -- (2.5,1.5) -- (2.5,2.5) -- (1.5,2.5) -- cycle;
\foreach \a in {1,...,4}
  \draw[thick] (0,\a) -- ++(5,0);
\foreach \x in {{1,2},{1,4},{2,1},{2,3},{3,1},{3,2},{3,3},{3,4},{4,2},{4,3}}
  \filldraw (\x) circle (1.5pt);
\draw[thick] (1,2) -- (1,4);
\draw[thick] (2,1) -- (2,3);
\draw[thick] (3,1) -- (3,2);
\draw[thick] (3,3) -- (3,4);
\draw[thick] (4,2) -- (4,3);
\end{tikzpicture}

\end{document}

enter image description here

The commented line (beginning with %) would give you a sample of light-gray rectangle on the background as in the first image of yours.

like image 108
MattAllegro Avatar answered Nov 10 '22 19:11

MattAllegro