Debian Codegraph @

doc/neato/neato.tex

raw
1 \documentclass[11pt]{article}
2 \usepackage{graphicx}
3 \usepackage{times}
4 \pagestyle{myheadings}
5 \def\dot{{\sc dot}}
6 \def\dotty{{\sc dotty}}
7 \def\neato{{\sc neato}}
8 \newcommand{\lastedited}{April 26, 2004}
9 \date{\lastedited}
10 \newcommand{\mymark}{\hfil \neato\ User's Manual, \lastedited \hfil}
11 \markboth{\mymark}{\mymark}
12 \begin{document}
13 \bibliographystyle{alpha}
14 % \keywords{Graph Layout, Network Visualization, Graph Browser}
15 \title{Drawing graphs with \neato}
16 \author{Stephen C. North}
17 \maketitle
18 \begin{abstract}
19 \noindent
20 \neato\ is a program that makes layouts of undirected graphs
21 following the filter model of \dot.
22 Its layout heuristic creates virtual physical models and runs an
23 iterative solver to find low energy configurations.
24 The intended applications are in telecommunication networks,
25 computer programming and software engineering.
26 Here is an example layout depicting an entity-relationship
27 database schema. It took 0.01 seconds of user time to generate
28 on a garden variety PC running Linux.
29 \par
30 \vspace*{.25in}
31 \centerline{ \includegraphics{ER} }
32 \end{abstract}
33
34 \newpage
35 \section{Introduction}
36 \neato\ is a utility that draws undirected graphs,
37 which are common in telecommunications and computer programming.
38 It draws a graph by constructing a virtual physical model
39 and running an iterative solver to find a low-energy configuration.
40 Following an approach proposed by Kamada and Kawai \cite{kk},
41 an ideal spring is placed between every pair of nodes such that
42 its length is set to the shortest path distance between the endpoints.
43 The springs push the nodes so their geometric distance in the layout
44 approximates their path distance in the graph.
45 This often yields reasonable layouts \cite{spremb}\cite{reingold-fructerman}.
46 (In statistics, this algorithm is also known as multidimensional scaling.
47 Its application to graph drawing was noted by Kruskal and Seery in the
48 late 1970s.)
49 \begin{figure}[b]
50 \begin{minipage}[b]{2in}
51 \begin{verbatim}
52 graph G {
53 run -- intr;
54 intr -- runbl;
55 runbl -- run;
56 run -- kernel;
57 kernel -- zombie;
58 kernel -- sleep;
59 kernel -- runmem;
60 sleep -- swap;
61 swap -- runswap;
62 runswap -- new;
63 runswap -- runmem;
64 new -- runmem;
65 sleep -- runmem;
66 }
67 \end{verbatim}
68 \end{minipage} \hspace{.5in} \
69 \parbox[b]{2.5in}{
70 \includegraphics[scale=.6]{process}
71 }
72 \caption{Process States in an Operating System Kernel (0.03 seconds)}
73 \label{fig:process}
74 \end{figure}
75
76 \neato\ is compatible with the directed graph drawing program
77 \dot\ in sharing the same input file format
78 and graphics drivers \cite{dotuserguide}.
79 Since the file format includes both undirected and directed graphs,
80 \neato\ draws graphs prepared for \dot, and vice versa.
81 Both programs have the same options for setting labels, colors, shapes,
82 text fonts, and pagination, and for generating code in common graphics
83 languages (PostScript, raster formats such as GIF and PNG, SVG,
84 FrameMaker MIF, and web click maps).
85 Both work with \dotty, an interactive graph viewer for X windows.
86 (The {\tt lneato} command script runs neato from an interactive window.)
87
88 Figs.~\ref{fig:process}--\ref{fig:IMR} are representative
89 examples of \neato's output.
90 The timings refer to user time on a 600 Mhz Pentium Linux server.
91 Fig.~\ref{fig:process} was derived from a hand-made drawing
92 in an operating system tutorial.
93 Fig.~\ref{fig:inet} shows the connectivity of a computer network.
94 Fig.~\ref{fig:typesharing} shows the sharing of programmer-defined types
95 between procedures in a C program. The program that was the source
96 of this graph parses a text file into an internal data structure.
97 The graph was extracted from a C program database. Its drawing shows
98 where interactions or conversions between types may occur. Finally,
99 Fig.~\ref{fig:IMR} shows relationships between IMRs (modification requests)
100 in an externally released software product.\footnote{Graph
101 courtesy of J. Hoshen, Bell Labs.} The labeled nodes are IMRs and the small circles
102 encode many-to-many dependencies.
103 \begin{figure}[h]
104 \centerline{\includegraphics{inet}} % y=4in
105 \vspace{.25in}
106 \caption{R\&D Internet Backbone (0.08 seconds)}
107 \label{fig:inet}
108 \end{figure}
109
110 \begin{figure}[h]
111 \centerline{\includegraphics{typeshar}} % xsize=4in
112 \caption{Type Sharing Between Procedures in a C Program (0.41 seconds)}
113 \label{fig:typesharing}
114 \end{figure}
115 \begin{figure}[h]
116 \centerline{\includegraphics{jho}} %xsize=4in
117 \caption{IMR Dependencies (6.75 seconds)}
118 \label{fig:IMR}
119 \end{figure}
120 \clearpage
121
122 \begin{figure}[h]
123 \begin{minipage}[b]{2in}
124 \begin{verbatim}
125 $ cat example.gv
126 graph G {
127 n0 -- n1 -- n2 -- n3 -- n0;
128 }
129 $ neato -Tps example.gv -o example.ps
130
131
132 \end{verbatim}
133 \end{minipage} \hspace{1.0in} \
134 \parbox[b]{2.5in}{
135 \ \\
136 \centerline{\includegraphics{G4_orig}}
137 }
138 \caption{Example Graph Drawing}
139 \label{fig:G4_orig}
140 \end{figure}
141
142 \section{Graph Drawing}
143 \subsection{Basic Commands}
144 The remainder of this memo gives a synopsis of \neato\ features.
145 Many of these should be familiar to users of \dot.
146 Fig.~\ref{fig:G4_orig} shows a graph file, its drawing,
147 and the command that was executed. A graph file has a
148 short header and a body consisting of nodes, edges, and
149 attribute assignments.
150 By default, nodes are drawn as ellipses labeled with node names.
151 Undirected edges are created by the \verb"--" operator.
152 Edges are drawn as straight lines and tend to be all about the same length.
153
154 \subsection{Drawing Options}
155 Table~\ref{table:attrs} lists the graph, node and edge
156 attributes that affect the layout.
157 The options to set labels, shapes, fonts, and sizes are convenient
158 for many kinds of layouts. The drawing in figure~\ref{fig:fancy}
159 illustrates some of these features.\footnote{Graph courtesy of
160 Hector Zamora, DEFINITY.}
161 Options to set the size of the drawing, pagination, and output graphics
162 language are also the same as in \dot.
163
164 \begin{figure}
165 \centerline{\includegraphics{fancy}} % ysize=5
166 \footnotesize
167 \begin{verbatim}
168 graph G {
169 node [shape=box,style=filled];
170 {node [width=.3,height=.3,shape=octagon,style=filled,color=skyblue] A1 A2 A3}
171 A -- A1 [label="l #6"];
172 A -- A2 [label="l #7"];
173 A -- A3 [label="l #8"];
174
175 {edge [style=invis]; A1 -- A2 -- A3}
176
177 edge [len=3]; /* applies to all following edges */
178 A -- B [label="l #1"]; A -- C [label="l #2"]; A -- D [label="l #3"];
179 A -- E [label="l #4"]; A -- F [label="l #5"]; B -- C [label="l #1"];
180 B -- E [label="l #2"]; B -- F [label="l #3"]; C -- D [label="l #1"];
181 D -- E [label="l #1"];
182 }
183 \end{verbatim}
184 \caption{Node and Edge Options}
185 \label{fig:fancy}
186 \end{figure}
187
188 \section{Adjusting Layouts}
189 Although layouts made by \neato\ are close to a local optimum
190 as defined by the forces the springs exert on the nodes,
191 fine tuning or generation of alternative layouts may improve readability.
192 Because \neato\ uses unconstrained optimization, it does not enforce
193 minimum separation constraints between nodes or between edges and
194 nonadjacent nodes, so in dense graphs nodes and edges can be too
195 close or overlap. There are three ways of trying to correct these errors:
196 \begin{obeylines}
197 1) change the initial configuration
198 2) adjust the solver parameters
199 3) edit the input edge lengths and weights.
200 \end{obeylines}
201
202 \subsection{Initial Configuration}
203 If no options are given,
204 \neato\ always makes the same drawing of a given graph file,
205 because its initial node placement and the solver are deterministic.
206 Random initial placement can yield different layouts.
207 It is sometimes reasonable to make at least several different
208 trial layouts, and accept the best one.
209 Random initial placement is requested by setting the value of the
210 graph attribute \verb"start".
211 If the value is a number, it is taken as a seed for the random number
212 generator. The layout is different for each seed, but still deterministic.
213 If the value is not a number, the process ID or current time is used.
214 Each run potentially yields a different drawing. For example:
215 \begin{verbatim}
216 $ neato -Tps -Gstart=rand file.gv > file.ps
217 \end{verbatim}
218
219 \subsection{Termination Threshold}
220 The solver is a Newton-Raphson algorithm that moves a node
221 with a maximal $\delta e$ on every iteration.
222 The solver terminates when $\delta e$ falls below some $\epsilon$.
223 The default ($.1$) is low enough that the layout is usually
224 close to a local minimum, but not so low that the solver runs
225 for a long time without making significant progress.
226 Smaller values of $\epsilon$ allow the solver run longer and
227 potentially give better layouts. Larger values can decrease
228 \neato's running time but with a reduction in layout quality.
229 This may be a desirable tradeoff for large graphs.
230 $\epsilon$ is set in the graph's \verb"epsilon" variable.
231 You can also directly limit the number of iterations.
232 It is convenient to do this on the command line:
233 \begin{verbatim}
234 $ neato -Tps -Gepsilon=.001 small.gv -o small.ps
235 $ neato -Tps -Gepsilon=1.5 big.gv -o big.ps
236 $ neato -Tps -Gmaxiter=1000 big.gv -o big.ps
237 \end{verbatim}
238
239 \subsection{Edge Lengths and Weights}
240 Since the layout depends on the input edge lengths and their weights,
241 these can sometimes be adjusted to good effect.
242 The length of an edge is the preferred distance between the endpoint nodes.
243 Its weight is the strength of the corresponding spring, and affects the cost
244 if it is stretched or compressed. Invisible edges can also be inserted to
245 adjust node placement. In figure~\ref{fig:fancy}, the length of some
246 edges was set to 3 to make them longer than the default.
247 Also, the two invisible edges affect A1, A2, and A3.
248
249 There is also a way to also give the initial or final coordinates of
250 individual nodes. The initial position, formatted as two comma-separated
251 numbers, is entered in a node's \verb"pos" attribute. If \verb"!" is given
252 as a suffix, the node is also pinned down.
253
254 \begin{figure}
255 \begin{minipage}[b]{2in}
256 \begin{verbatim}
257 graph G {
258 n0 -- n1 [len=2, style=bold];
259 n1 -- n2 -- n3 -- n0;
260 }
261
262 \end{verbatim}
263 \end{minipage} \hspace{1.0in} \
264 \parbox[b]{2.5in}{
265 \ \\
266 \includegraphics{G4_lenwt}
267 }
268 \caption{Example graph with an edge stretched}
269 \label{fig:G4_lenwt}
270 \end{figure}
271
272 \begin{figure}
273 \begin{minipage}[b]{2in}
274 \begin{verbatim}
275 graph G {
276 n0 [ pos = "0,0!" ];
277 n1 [ pos = "2,0" ];
278 n2 [ pos = "2,2!" ];
279 n0 -- n1 -- n2 -- n3 -- n0;
280 }
281
282
283 \end{verbatim}
284 \end{minipage} \hspace{.5in} \
285 \parbox[b]{3in}{
286 \ \\
287 \includegraphics{G4_pinned}
288 }
289 \caption{Example graph with nodes pinned}
290 \label{fig:G4_pinned}
291 \end{figure}
292
293 \begin{table}
294 \begin{tabular}[t]{|l|l|p{3.5in}|} \hline
295 Name & Default & \hfil Values \hfil \\ \hline
296 \multicolumn{3}{|c|}{Node Attributes} \\ \hline
297 {\tt shape} & {\tt ellipse} & {\tt ellipse}, {\tt box}, {\tt circle}, {\tt doublecircle}, {\tt diamond}, {\tt plaintext}, {\tt record}, {\tt polygon} \\
298 {\tt height},{\tt width} & {\tt .5,.75} & height and width in inches \\
299 {\tt label} & node name & any string \\
300 {\tt fontsize} & {\tt 14} & point size of label \\
301 {\tt fontname} & {\tt Times-Roman} & font family name, e.g. {\tt Courier, Helvetica} \\
302 {\tt fontcolor} & {\tt black} & type face color \\
303 {\tt style} & & graphics options, e.g. {\tt bold, dotted, filled} \\
304 {\tt color} & {\tt black} & node shape color \\
305 {\tt pos} & & initial coordinates (append {\tt !} to pin node) \\ \hline
306 \multicolumn{3}{|c|}{Edge Attributes} \\ \hline
307 {\tt weight} & {\tt 1.0} & strength of edge spring \\
308 {\tt label} & & label, if not empty \\
309 {\tt fontsize} & {\tt 14} & point size of label \\
310 {\tt fontname} & {\tt Times-Roman} & font family name \\
311 {\tt fontcolor} & {\tt black} & type face color \\
312 {\tt style} & & graphics options, e.g. {\tt bold, dotted, dashed} \\
313 {\tt color} & {\tt black} & edge stroke color \\
314 {\tt len} & 1.0 & preferred length of edge \\
315 {\tt dir} & {\tt none} & {\tt forward}, {\tt back}, {\tt both}, or {\tt none} \\
316 {\tt decorate} & & if set, draws a line connecting labels with their edges \\
317 {\tt id} & & optional value to distinguish multiple edges \\ \hline
318 \multicolumn{3}{|c|}{Graph Attributes} \\ \hline
319 {\tt start} & & seed for random number generator \\
320 {\tt size} & & drawing bounding box, in inches \\
321 {\tt page} & & unit of pagination, {\it e.g.} {\tt 8.5,11} \\
322 {\tt margin} & {\tt .5,.5} & margin included in {\tt page} \\
323 {\tt label} & & caption for graph drawing \\
324 {\tt fontsize} & {\tt 14} & point size of label \\
325 {\tt fontname} & {\tt Times-Roman} & font family name \\
326 {\tt fontcolor} & {\tt black} & type face color \\
327 {\tt orientation} & {\tt portrait} & may be set to {\tt landscape} \\
328 {\tt center} & & when set, centers drawing on {\tt page} \\ \hline
329 {\tt overlap} & true & may be set to {\tt false} or {\tt scale} \\ \hline
330 {\tt splines} & false & {\tt true} makes edge splines if nodes don't overlap \\ \hline
331 {\tt sep} & 0 & edge spline separation factor from nodes - try .1 \\ \hline
332 \end{tabular}
333 \caption{Drawing attributes}
334 \label{table:attrs}
335 \end{table}
336
337 \section{Eliminating Overlaps}
338 To improve clarity, it is sometimes helpful to eliminate
339 overlapping nodes or edges. One way to eliminate node overlaps
340 is just to scale up the layout (in terms of the center points
341 of the nodes) as much as needed. This is enabled by setting
342 the graph attribute {\tt overlap=scale}. This transformation
343 preserves the overall geometric relationships in the layout,
344 but in bad cases can require high scale factors. Another way
345 to eliminate node overlaps employs an interative heuristic.
346 On each iteration, a bounded Voronoi diagram of the node center points
347 is computed, and each node is moved to the center of its Voronoi cell.
348 This is repeated until all overlaps are eliminated. A side-effect
349 (perhaps unwanted) is that the adjusted layout tends to fill the
350 bounding rectangle of the Voronoi diagram. The heuristic is activated
351 by setting {\tt overlap=false}.
352
353 Edge overlaps (with nodes) can be prevented by drawing them
354 with spline curves (with {\tt splines=true}). Note that the spline
355 drawing heuristic is expensive and probably should not be attempted
356 on graphs that have more than a few dozen nodes.
357
358 Areas for future work include non-rectangular Voronoi boundaries,
359 faster edge routing heuristics, and techniques to prevent
360 unnecessary edge intersections.
361
362 \section{Acknowledgments}
363
364 \neato's layout heuristic follows the work of Kamada and Kawai \cite{kk}.
365 The implementation was originally part of the {\sc salem} 3D viewer
366 for mathematical structures written with David Dobkin and Nathaniel Thurston.
367 In converting \neato\ to a more traditional tool, the graphics code generator
368 was borrowed from \dot. This includes code contributed by John Ellson and
369 Emden Gansner. Steve Eick was an early user and offered some good
370 suggestions about ways to adjust layouts. Emden Gansner also contributed
371 the heuristics for eliminating node overlaps, based on a paper by
372 David Rappaport and Kelly Lyons.
373
374 \small
375 \bibliography{../dotguide/graphdraw}
376 \end{document}