18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Drawing Graphs Nicely<br />

crossings or edge length, and thus significantly improve the drawing.<br />

A good, general-purpose heuristic for drawing graphs models the graph as a system of springs and then<br />

uses energy minimization to space the vertices. Let adjacent vertices attract each other with a force<br />

proportional to the logarithm of their separation, while all nonadjacent vertices repel each other with a<br />

force proportional to their separation distance. <strong>The</strong>se weights provide incentive for all edges to be as<br />

short as possible, while spreading the vertices apart. <strong>The</strong> behavior of such a system can be approximated<br />

by determining the force acting on each vertex at a particular time and then moving each vertex a small<br />

amount in the appropriate direction. After several such iterations, the system should stabilize on a<br />

reasonable drawing. <strong>The</strong> input and output figures above demonstrate the effectiveness of the spring<br />

embedding on a particular small graph.<br />

If you need a polyline graph drawing algorithm, my recommendation is that you study several of the<br />

implementations presented below, particularly graphEd and GraphViz, and see whether one of them can<br />

do the job. You will have to do a significant amount of work before you can hope to develop a better<br />

algorithm.<br />

Once you have a graph drawn, this opens another can of worms, namely where to place the edge/vertex<br />

labels. We seek to position the labels very close to the edges or vertices they identify, and yet to place<br />

them such that they do not overlap each other or important graph features. Map labeling heuristics are<br />

described in [WW95]. Optimizing label placement can be shown to be an NP-complete problem, but<br />

heuristics related to bin packing (see Section ) can be effectively used.<br />

Implementations: Georg Sander maintains a comprehensive WWW page on graph drawing at<br />

http://www.cs.uni-sb.de/RW/users/sander/html/gstools.html. This is well worth checking out and<br />

probably should be your first stop in hunting down programs for graph drawing.<br />

<strong>The</strong> best ftp-able package of graph drawing algorithms is GraphEd, by Michael Himsolt. GraphEd<br />

[Him94] is a powerful interactive editor that enables the user to construct and manipulate both directed<br />

and undirected graphs. It contains a variety of graph and tree drawing algorithms, including planar<br />

drawings, polyline drawings, upward drawings of directed acyclic graphs (DAGs), and spring<br />

embeddings, and allows variations in node, edge, and label styles. Sgraph is an interface to GraphEd to<br />

support user-specific extensions written in C. It includes a modest library of algorithms for planarity<br />

testing, maximum flow, matching, and connectivity testing. GraphEd can be obtained by anonymous ftp<br />

from forwiss.uni-passau.de (132.231.20.10) in directory /pub/local/graphed. GraphEd is free for<br />

noncommercial use. Graphlet is a more recent project by the same group, available at http://www.fmi.unipassau.de/Graphlet.<br />

GraphViz is a popular graph drawing program developed by Stephen North of Bell Laboratories. It<br />

represents edges as splines and can construct useful drawings of quite large and complicated graphs. I<br />

recommend it, even though licensing considerations make it impossible to include on the <strong>Algorithm</strong><br />

Repository or CD-ROM. A noncommercial license is available from http://portal.research.bell-<br />

file:///E|/BOOK/BOOK4/NODE168.HTM (3 of 4) [19/1/2003 1:31:12]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!