An Algorithm for Drawing Planar Graphs

Bor Plestenjak

IMFMTCS University of Ljubljana Jadranska SI Ljubljana Slovenia

email b orplestenjakfmfuniljsi

AN ALGORITHM FOR DRAWING PLANAR GRAPHS

SUMMARY

A simple algorithm for drawing connected planar graphs is presented It is derived from the

Fruchterman and Reingold spring emb edding algorithm by deleting all repulsive forces and xing

vertices of an outer face The algorithm is implemented in the system for manipulating discrete

mathematical structures Vega Some examples of derived gures are given

Key words drawing Forcedirected placement

INTRODUCTION

A graph G is planar if and only if it is p ossible to draw it in a plane without any edge intersections Every

connected planar graph admits a convex drawing ie a planar drawing where every face is drawn as

a convex p olygon We present a simple and ecient algorithm for convex drawing of a connected planar

graph In addition to a graph most existing algorithms for planar drawing need as an input all the faces of

a graph while our algorithm needs only one face of a graph to draw it planarly

Let G b e a connected planar graph with a set of vertices V fv v g and a set of edges E

1 n

fu v u v g Let W fw w w g V b e an ordered list of vertices of an arbitrary face in

1 1 m m 1 2 k

graph G which is chosen for the outer face in the drawing

The basic idea is as follows We consider graph G as a mechanical mo del by replacing its vertices with

metal rings and its edges with elastic bands of zero length Vertices of the outer face W are xed in a vertices

of a regular p olygon of a size k while all other vertices are let free Under the inuence of attractive forces in

bands free vertices will move until the system nally reaches an equilibrium The layout in the equilibrium

is a convex drawing

The algorithm is included in package Vega under the name SchlegelDiagram Vega is Mathematica

based system for manipulating graphs and other combinatorial structures such as groups maps etc devel

op ed by IMFMTCS Ljubljana Vega is mainly written in Mathematica however it also includes external

programs for time complex op erations eg the implementation of our algorithm

ALGORITHM

The algorithm is based on the forcedirected placement graph drawing algorithm by Fruchterman and Rein

gold In each step the algorithm calculates the eect of attractive forces on each and then moves

the vertex in the direction of the resultant force The displacement in step i is limited to some maximum

value cool i that we call temp erature and which satises lim cool i As the temp erature decreases

i!1

to zero smaller and smaller displacements are allowed and after some numb er of steps displacements are so

small that we can say that the layout freezes The algorithm ends after the prescrib ed numb er of iterations

and if the forces and the co oling function cool i are chosen prop erly the nal layout is so near to the

equilibrium that it is planar

AN ALGORITHM FOR DRAWING PLANAR GRAPHS

For the force b etween two adjacent vertices u and v we use the third order law

3

F C d

uv

where C is a constant and d kupos v posk is the distance We tested dierent order p owers and the

result is a compromise b etween go o d results and an ecient calculation

The algorithm consists of the following steps

Position all vertices of an outer face W in vertices of a regular p olygon of size k inscrib ed into the unit

circle and put all other vertices in the origin

For i to iter ations

a For all vertices v V set the resultant force F to zero

v

F

v

b For all edges u v E calculate the attractive force F and up date the resultant forces F and

uv u

F

v

3

F C v pos upos

uv

F F F

u u uv

F F F

v v uv

c For all vertices v V W move vertex v in the direction of the resultant force F for the size

v

of the force but not more than for the value of cool i

F

v

v pos v pos min jF j cool i

v

jF j

v

Constant C in has to b e in harmony with the maximum displacement Namely if C is to o large

then in every vertex is shifted for the maximum displacement irresp ective of the force size On the other

hand if C is to o small then the displacements are small and the algorithm do es not reach the equilibrium

in a prescrib ed numb er of steps

If the temp erature decreases to o slowly then displacements are to o large and to o many steps are needed

to reach the equilibrium Yet if the temp erature decreases to o fast then the layout freezes in a non planar

drawing

A suggested values for constant C and function cool i are

r

n

C

p

n

cool i

32

i

n

p

The expression is the average area b elonging to one vertex and therefore we take for the average

n n

in and distance b etween adjacent vertices This justies the presence of term n

AN ALGORITHM FOR DRAWING PLANAR GRAPHS

Figures to demonstrate how the algorithm works The graph is the icosahedral fullerene isomer of

C derived in Vega from the do decahedron using two leapfrog transformations We usually pick the

180

largest face for the outer face but since p entagons are arranged in a shap e of a do decahedron we cho ose a

p entagon in order to exhibit symmetry For C and cool i we apply and resp ectively It can b e seen

from these gures how the edges closer to the b order untwist rst and how they force those in the middle to

unfold until nally the layout b ecomes planar

Figure C after iterations Figure C after iterations Figure C after iterations

180 180 180

MODIFICATIONS

Periphericity If the algorithm is applied to a graph with a large numb er of faces eg a fullerene on

many vertices then it pro duces a drawing with large faces on the b order and large numb er of crowded small

faces in the middle of a gure

0 0

1 1

2 2

2 1

3 2

2 2

1 1

0 0

Figure Periphericity of a vertex

In order for the algorithm to terminate with approximately equally arranged faces we assume that the

co ecient C in is not equal for all bands Bands at the b order should b e stronger and bands in the

middle should b e weaker For this purp ose we intro duce a p eriphericity of a vertex as the path distance from

the vertex to the outer cycle The denition of the p eriphericity is more evident in Figure where vertices

AN ALGORITHM FOR DRAWING PLANAR GRAPHS

of a graph are lab eled according to their p eriphericities

The co ecient of the band b etween vertices u and v is a function of p eriphericities uper and v per

and we denote it by C uper v per Let maxper b e the maximum p eriphericity in the graph As we go

through all edges u v E the bands with uper v per should b e the strongest and the bands

with uper v per maxper should b e the weakest Best results are obtained when the co ecients

C uper v per form a geometric progression in the form

r

n maxper uper v per

expA C uper v per

maxper

For the constant A we prop ose A but other values can b e used as well pro ducing dierent planar

layouts

Figure C with A after Figure C with A after Figure C with A after

540 540 540

iterations iterations iterations

Figures to demonstrate the eect of dierent values of A The graph is the icosahedral fullerene

isomer of C In Figure A which equals the original algorithm In Figure A and faces in

540

the middle are more equally arranged The value A in Figure is to o large and the obtained drawing

has large faces in the middle that squeeze the rest of the faces In all three case the co oling function is

applied

Oscil lation After some initial numb er of steps the vertices b egin to oscillate b etween two states If

we compare the co ordinates with the co ordinates from two steps ago we can exit the algorithm when the

dierence for every vertex is b elow the prescrib ed constant This approach reduces the numb er of steps

without doing any real harm to the layout quality For the example we take the graph C and

180

3 4 5

with A For and the algorithm ends after and steps resp ectively

Dierences b etween layouts are not visible with the naked eye For instance the maximum dierence b etween

3

the co ordinates of the same vertex after and steps is

Nonplanar graphs Although the algorithm is derived for connected planar graphs it can b e applied

to other graphs as well For every graph we can x an arbitrary set of vertices on the regular p olygon apply

a mechanical mo del to a graph and search for an equilibrium Although the nal layout do es not need to b e

AN ALGORITHM FOR DRAWING PLANAR GRAPHS

planar it usually contains useful information ab out the symmetry and other prop erties of the graph

EXAMPLES

The following examples are all obtained using Vega We use Vega to determine faces of a planar graph using

a PQtree algorithm for planarity testing and emb edding in linear time implemented by J Marincek

Each face of a planar graph is a go o d choice for the outer face but usually we get nicer drawings if we cho ose

the largest face It is advisable to compare drawings for dierent choices of the outer face and then cho ose

5

the most suitable one For all examples in this section we use with A and When

present the term it in gure captions denotes the iteration in which the algorithm reached and exited

Figure and Figure are drawings of the Herschel graph The Herschel graph is a wellknown

example of a planar nonhamiltonian p olyhedron Notice how the dierent choice of the outer face aects

the layout

Figure Herschel graph Figure Herschel graph

n m it n m it

Next two gures represent the Tutte graph and the Grinb erg graph These two graphs are wellknown

examples of planar cubic connected nonhamiltonian graphs Figure is the gure of the Tutte graph

using the largest face for the outer face but nicer and more familiar gure is Figure where the outer face

has size Figure represents the Grinb erg graph

AN ALGORITHM FOR DRAWING PLANAR GRAPHS

Figure Tutte graph Figure Tutte graph Figure Grinberg graph

n m it n m it n m it

Next example presents a planar graph which is not connected Figure is the drawing determined

automatically by the algorithm while Figure is the gure calculated after we manually add two temp orary

edges that are colored gray When we delete temp orary edges we obtain Figure By comparing Figure

and Figure it is easy to see that some edges are overlapping in Figure

This trick can b e applied to every planar graph which is not connected First we add so many temp orary

edges that the graph b ecomes connected and then we use the algorithm which returns the convex drawing

Since the planar layout remains planar if we delete an arbitrary numb er of edges we simply delete all the

temp orary edges and end with a planar drawing of the original graph

The problem is how to add the temp orary edges automatically One of the solutions is to use the

dimensional sub division which adds a new vertex in the center of each face and joins it by edges with

all vertices of the face This transformation is implemented in Vega

Figure Graph with overlapping Figure Graph in Figure with Figure Graph in Figure with

edges added temporary edges out overlapping edges

Planar layouts of p olyhedra are often more surveyable as their three dimensional layouts An example

is the snub do decahedron depicted in a planar and in a three dimensional layout in Figure and Figure

resp ectively The graph in Figure is the medial Grinb erg graph derived from Grinb erg graph using

AN ALGORITHM FOR DRAWING PLANAR GRAPHS

transformations on maps implemented in Vega

Figure Planar layout of snub Figure D layout of snub Figure Medial Grinberg graph

dodecahedron it dodecahedron it

Figure displays the result of applying the algorithm to a wellknown nonplanar Petersen graph and

cho osing any cycle of length for the outer cycle Figures and are the results of the algorithm used on a

triangulation of a triangle In Figure a regular p olygon is chosen for the outer face and the gure do es not

have a triangular shap e The choice of three vertices of valence two in Figure pro duces a nontriangular

shap e again This problem can b e solved by allowing the user to x a set of vertices in an arbitrary two or

even three dimensional conguration

Figure Petersen graph Figure Triangulated triangle Figure Triangulated triangle

it

CONCLUSIONS

Planar layouts of planar graphs which are often more surveyable as corresp onding three dimensional layouts

can b e easily pro duced using this algorithm This particularly holds for p olyhedral graphs for instance

fullerenes

One of the b enets of the algorithm is its time complexity One step of the algorithm has time complexity

O jE j jV j while for instance one step of the algorithm by Fruchterman and Reingold has time complexity

AN ALGORITHM FOR DRAWING PLANAR GRAPHS

2

O jE j jV j A weakness of the algorithm is that it can b e used only for connected planar graphs This

means that planar graphs like trees can not b e drawn automatically using this algorithm

The algorithm oers many improvements One of them is to allow the user to x a set of vertices in an

arbitrary conguration The algorithm can also b e easily generalized to D layouts

Acknowledgement The author would like to thank Prof T Pisanski at IMFMTCS Ljubljana for his

supp ort and many useful suggestions

REFERENCES

WT Tutte Convex Representation of Graphs Pro c London Math So c

G Di Battista P Eades R Tamassia IG Tollis Algorithms for Drawing Graphs an Annotated

Bibliography Comput Geom

T Pisanski et al VEGA Version Quick reference manual and Vega graph gallery DMFAS IMFM

Ljubljana

T Pisanski et al Vega System for manipulating discrete mathematical structures URL

httpnnvegawwwijpsi

TMJ Fruchterman and EM Reingold Graph Drawing by Forcedirected Placement Software

Practice and Exp erience

PW Fowler and DE Manolop oulos An Atlas of Fullerenes Clarendon Press Oxford

T Pisanski and PW Fowler Leapfrog Transformation and Polyhedra of Clar Typ e J Chem So c

Faraday Trans

KS Bo oth Testing for Consecutive Ones Prop erty Interval Graphs and Graph Planarity using PQ

Tree Algorithms J Comp Syst Sci

J Marincek Kuratowsky Theorem for Surfaces of Small Genus in slovene diploma work Ljubljana

H S M Coxeter Regular Polytop es Dover New York

J A Bondy and U S R Murty with Applications American Elsevier

T Pisanski M Randic Bridges b ewtween Geometry and Graph Theory submitted

T Pisanski B Plestenjak and A Graovac NiceGraph Program and Its Applications in Chemistry

Croat Chem Acta

D Wells The Penguin Dictionary of Curious and Interesting Geometry Penguin Bo oks London

T K Stremp el Zur Erzeugung Klassizierung und Einb ettung kombinatorischer Manningfaltigkeiten

und Komplexe in german PhD Thesis D Diss TH Darmstadt Shaker Verlag Aachen