I'm trying to draw decision diagrams (DD) in an automated fashion. A DD is a DAG, where all nodes are partitioned in layers. Edges typically go from a node in layer l to another node in layer l+1. Each edge has a label, and there can be multiple edges between the same pair of nodes. Two example DDs can be found below. These are drawn by manually specifying all coordinates of all nodes. Since I need to draw a large number of those, I'd like to automate this. Therefore I'm using the layout manager of tikz. Here's an example:
\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,quotes}
\usegdlibrary{layered}
\begin{document}
\begin{tikzpicture}[rounded corners]
\graph [layered layout,
edge quotes={fill=white,inner sep=1pt,font=\scriptsize,pos=0.2},
nodes={circle,draw,inner sep=.1,outer sep=0, minimum size=.35cm},
level sep=1cm
]
{
r ->["a"] 1,
r ->["b"] 0,
r ->["c"] 2,
r ->["d"] 3,
3 ->["e"] 4,
1 ->["f"] 4,
1 ->["g"] 6,
0 ->["h"] 4,
0 ->["i"] 5,
0 ->["j"] 6,
2 ->["k"] 6,
4 ->["l"] t,
5 ->["m"] t,
6 ->["n"] t;
};
\end{tikzpicture}
\end{document}
The above code works pretty well, especially since I can specify each arc individually. Next I'm looking for a way to do the following:
- how to specify the vertical space between layers? Answer: use
level sep=2cm
- how to draw multiple edges between the same pair of nodes? In the right most figure, you see nodes with 2 edges, e.g. v2,v4. There can be more than 2 edges between the same pair of nodes. The edges must be drawn non-overlapping. E.g. what if I had 10 edges with different labels between the same pair of nodes?
- Next to the left most graph, there are labels pi_1, pi_2. These labels are vertically aligned and are next to the edges. How do I add those?
Note: I'm not looking to exactly replicate the graphs in the figure. Something else that is aesthetically pleasing is good enough.
positioning
(3) is also not difficult to achieve. However, drawing such weighted graphs is very painful with pure TikZ.