Spring Graph Layout Method - Maple Help

Spring Graph Layout Method

Options

 • constantonly=truefalse
 If the constantonly=true option is given then a pure constant repulsive force for the vertices. This layout style is equivalent to spring for Maple 15 and earlier versions.
 • initial=Array, Matrix, list, name, or string
 The initial option is used to specify the initial vertex location before solving the spring system.  By default it is random and uses randomly chosen points. The name structured will start the vertex in a structured grid.  The names of other layout methods can be used to use their previously computed output stored in the Graph data structure. Finally, a list, Array, or Matrix of point locations may be given.
 • iterations=posint
 The maximum number of iterations that will be used to solve the ODE system. Default is 20000. The actual number of iterations used will be displayed if infolevel[GraphTheory] is set to 2 or higher.
 • legacy=truefalse
 If set to true, an older version of the spring code will be called rather than the compiled C code used by default.  This code just supports the constant force only model and doesn't support the iterations option.
 • frames=posint
 The number of frames of animation returned from the layout. The default is 50.  If the option animate was not provided to DrawGraph this option will be ignored.

Description

 • The spring layout method is so named because it simulates a physical model where the vertices are modeled as protons repelling each other and the edges are modeled as springs attracting adjacent vertices. This leads to a dense system of nonlinear ODEs to be solved and so this option becomes quite expensive beyond 100 vertices. At present the spring option requires that the graph be connected.
 • This layout method works in two and three dimensions and for animations.

Examples

 > $\mathrm{with}\left(\mathrm{GraphTheory}\right):$
 > $\mathrm{with}\left(\mathrm{SpecialGraphs}\right):$
 > $\mathrm{with}\left(\mathrm{RandomGraphs}\right):$
 > $G≔\mathrm{Graph}\left(\mathrm{undirected},\left\{\left\{1,2\right\},\left\{1,4\right\},\left\{2,3\right\},\left\{3,4\right\}\right\}\right)$
 ${G}{≔}{\mathrm{Graph 1: an undirected unweighted graph with 4 vertices and 4 edge\left(s\right)}}$ (1)
 > $\mathrm{DrawGraph}\left(G,\mathrm{layout}=\mathrm{spring}\right)$

The following use animations to illustrate using different initial points

 > $P≔\mathrm{PetersenGraph}\left(\right)$
 ${P}{≔}{\mathrm{Graph 2: an undirected unweighted graph with 10 vertices and 15 edge\left(s\right)}}$ (2)
 > $\mathrm{DrawGraph}\left(P,\mathrm{layout}=\mathrm{spring},\mathrm{animate}\right)$
 > $\mathrm{DrawGraph}\left(P,\mathrm{layout}=\mathrm{spring},\mathrm{animate},\mathrm{layoutoptions}=\left[\mathrm{initial}=\mathrm{structured},\mathrm{frames}=15\right]\right)$
 > $\mathrm{DrawGraph}\left(P,\mathrm{layout}=\mathrm{spring},\mathrm{animate}=15\right)$
 > $H≔\mathrm{HypercubeGraph}\left(3\right)$
 ${H}{≔}{\mathrm{Graph 3: an undirected unweighted graph with 8 vertices and 12 edge\left(s\right)}}$ (3)
 > $\mathrm{DrawGraph}\left(H,\mathrm{layout}=\mathrm{spring},\mathrm{dimension}=3\right)$