[Tex/LaTex] How to draw this graph using the tikz `graphdrawing` library

graphstikz-graphdrawingtikz-pgf

I tried many times but failed to draw the graph below using the tikz graphdrawing library. I am quite confused, especially by its "layouts" concepts.

Problem: How to draw the graph below using graphdrawing.

mst-example

Code with graphdrawing stuff commented:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning}
% \usetikzlibrary{graphs, graphdrawing}
% \usegdlibrary{layered, force}

\begin{document}
\begin{tikzpicture}[node distance = {1.0cm and 1.5cm}, v/.style = {draw, circle}]
  % \graph [spring layout, nodes = {}, horizontal = A to C]
  % {
  %   A -- C -- E,
  %   B -- {D -- F}
  % };

  \node (a) [v] {A};
  \node (c) [v, right = of a] {C};
  \node (e) [v, right = of c] {E};

  \draw (a) to node[above] {1} (c);
  \draw (c) to node[above] {3} (e);

  \node (b) [v, below = of a] {B};
  \node (d) [v, right = of b] {D};
  \node (f) [v, right = of d] {F};

  \draw (b) to node[below] {1} (d);
  \draw (d) to node[below] {4} (f);

  \draw (a) to node[left] {2} (b);
  \draw (c) to node[below] {2} (b);
  \draw (c) to node[right] {2} (d);
  \draw (e) to node[below] {3} (d);
  \draw (e) to node[right] {1} (f);
\end{tikzpicture}
\end{document}

Best Answer

I think you're trying to use graphdrawing when you actually should be using the normal graph instead. The graphdrawing library is for when you have stuff that follows a structural logic but the graph itself is not of a fixed nature. Quoting Till Tantau:

You do not specify where, exactly, the nodes and edges should be. This is something you leave to a graph drawing algorithm. The algorithm gets your description of the graph as an input and then decides where the nodes should go on the page.

The graph you're proposing, to me, looks like you want to specify where the nodes are, but you want to do it in a concise and powerful way. Quoting Till again:

There is nothing in the graph library that you cannot do using the normal \node and the edge commands. Rather, its purpose is to offer a concise and powerful way of specifying which nodes are present and how they are connected.

Here it is how you draw your graph using the graph library (no need for Lua):

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{graphs, graphs.standard, quotes}% quotes library is for the [""] edges

\begin{document}
\begin{tikzpicture}[node distance = {1.0cm and 1.5cm}, v/.style = {draw, circle}]
  \graph[nodes={circle, draw}, grow right=2.25cm, branch down=1.75cm]{
    A -- ["1"] C -- ["3"] E,
    B -- ["1",swap] D -- ["4",swap] F,
    B -- ["2"] A,
    C -- ["2"] {D,B},
    D -- ["3",swap] E -- ["1"] F
  };
\end{tikzpicture}
\end{document}