Menu

#380 graphdrawing: error when using spring electrical layout with sublayouts

v1.0 (example)
closed-fixed
nobody
None
5
2018-12-23
2016-01-14
No

When laying out a graph via graphdrawing with the spring electrical layout, and the graph includes both sublayouts and "top-level" nodes (not in the sublayout) connected to each other, an error is thrown.

Here's a minimal example:

\documentclass{minimal}
\usepackage{tikz}

\usetikzlibrary{graphdrawing}
\usegdlibrary{force}
\usegdlibrary{trees}

\begin{document}
\tikz[spring electrical layout] {
    \node (a) {a};
    \node (b) {b};

  \begin{scope}[tree layout]
    \node (1) {1};
    \node (2) {2};
    \draw (1) edge (2);
  \end{scope}

  \draw (a) edge (1)
  (a) edge (b);
}
\end{document}

Compiling this throws the following error:

! LuaTeX error ...graphdrawing/lua/pgf/gd/interface/InterfaceToDisplay.lua:213: 
...eneric/pgf/graphdrawing/lua/pgf/gd/force/CoarseGraph.lua:411: attempt to comp
are number with nil
stack traceback:
    [C]: in function 'assert'
    ...graphdrawing/lua/pgf/gd/interface/InterfaceToDisplay.lua:213: in function 'resumeGraphDrawingCoroutine'
    ...graphdrawing/lua/pgf/gd/interface/InterfaceToDisplay.lua:182: in function 'runGraphDrawingAlgorithm'
    [\directlua]:1: in main chunk.
\pgfgdendscope ...lay.runGraphDrawingAlgorithm() }
                                                  \pgfutil@loop \ifpgfgdresu...
l.21 }

The error is resolved if the top-level layout is changed to spring layout, for example. Also, removing either of the two edges at the bottom (a--1, a--b) resolves the problem; all three edges must be present to cause the error. This occurs with both the Hu and Walshaw spring electric layout algorithms. Unless I grossly misunderstood the layout algorithms, I would expect this to work with spring electric as it does for the others.

Discussion

  • Brandon Invergo

    Brandon Invergo - 2016-01-15

    I've dug into it a bit more and it seems that somehow during the sublayout process, nodes lose their options. Of primary concern is electric charge, which is used to set node.weight in the two spring electric layout algorithms. Since that option is nil, node.weight is set to nil. This then breaks the graph-coarsening algorithm as well as the force calculations.

    Attached are some trivial patches that do not fix the underlying problem but at least allow such documents to compile.

     
  • Brandon Invergo

    Brandon Invergo - 2016-01-15

    Here's the other patch (only one attachment per post?)

     
  • Brandon Invergo

    Brandon Invergo - 2016-01-15

    Blech...sorry, I left the full paths in the patches.

     
  • Stefan Pinnow

    Stefan Pinnow - 2018-12-23
    • status: open --> closed-fixed
     
  • Stefan Pinnow

    Stefan Pinnow - 2018-12-23

    Thank you for reporting. The bug is fixed now.