# Plot a 4-regular directed network

I want to draw a directed network with 6 nodes, where, each node has 2 incoming and 2 outgoing edges. I want the nodes of the network along a circle. How can I achieve this using pgfpots?

• Hi and welcome. Can you make a freehand diagram of the desired result? Feb 10 '20 at 9:36
• In your drawing, some nodes have only one outgoing arrow. You said that all nodes should have two outgoing arrows and two incoming arrows. Is this still the case or do you want exactly the same result as in your drawing? Feb 10 '20 at 11:41
• My guess is that there's a directed edge missing from the upper left node to the upper right node... Feb 10 '20 at 11:56

Here is a graph created with Tikz using the circular and routing libraries which must be compiled with Lualatex.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary {graphs,graphdrawing}
\usegdlibrary {circular,routing}
\usetikzlibrary{arrows.meta,bending}
\begin{document}
\begin{tikzpicture}[>={Stealth[round,sep]}]
\graph [simple necklace layout, node distance=1.5cm,
necklace routing,
grow'=north,
math nodes,
edges={>={Stealth[round,sep,bend]}}]
{ x_1 -> x_2  -> x_3 -> x_4 -> x_5 -> x_6 -> x_1};

\graph [use existing nodes,
math nodes,
edges={bend right=15,>={Stealth[round,sep,bend]}}]{
x_1 -> x_3 -> x_5  -> x_1,x_2 -> x_4 -> x_6 -> x_2
};
\end{tikzpicture}
\end{document}


Here's a toy version in Metapost. No special graphing language, just plain MP and a roll-your-own connection function. I've coloured in the doubtful arrow, just in case the OP really did mean to leave it out. (To hide it completely you could draw it with white).

Here is the source. Compile with lualatex.

\documentclass[border=5mm]{standalone}
\usepackage{luatex85}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
path C;
C = fullcircle scaled 89;

vardef connection(expr a, b, deflection) =
a {b-a rotated deflection} .. b
cutbefore fullcircle scaled 18 shifted a
cutafter  fullcircle scaled 18.4 shifted b
enddef;

interim ahangle := 30;
numeric N, r, s;
N = 6;  % number of points
r = -8 / N;  % unit rotation
s = 6 - r;   % starting point on the circle

for i=1 upto N:
label("$x_{" & decimal i & "}$", point s + i * r of C);
drawarrow connection(point s + i * r of C, point s + i * r + r of C, +36);
drawarrow connection(point s + i * r of C, point s + i * r + 2r of C, -18)
withcolor if i=3: 1/2 [blue, white] else: black fi;
endfor

endfig;
\end{mplibcode}
\end{document}


Note that MP's notion of time on a circular path is very helpful here; I've relied on the fact that on a circle point 8 is the same as point 0, point 9 = point 1, and so on. I could not resist making it slightly general, so if you change it to have N=7 you will get:

And if you wanted fancy line crossings you could change the connection() to something like:

vardef connection(expr a, b, deflection) =
path p; p =
a {b-a rotated deflection} .. b
cutbefore fullcircle scaled 18 shifted a
cutafter  fullcircle scaled 18.4 shifted b;
undraw p withpen pencircle scaled 2; p
enddef;


to get this:

A version with Tikz.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\def\NumNodes{6}
\begin{tikzpicture}
\foreach \x [evaluate=\x as \ang using (\x-1)*360/\NumNodes+90] in {1,...,\NumNodes}{
\node[circle,inner sep=1pt](A\x) at (\ang:2){$x_{\x}$};
\draw[-latex] (\ang-10:2) arc (\ang-10:{\ang-360/\NumNodes+10}:2);
}
\foreach \x [evaluate=\x as \xx using {int(Mod(\x-3,\NumNodes)+1)}]in {1,...,\NumNodes}{
\draw[-latex] (A\x) to[bend right=20] (A\xx);
}
\end{tikzpicture}
\end{document}