Algorithmic and declarative approaches to graph drawing

Graph Drawing
Algorithmic
g
and Declarative
Approaches
Peter Eades
University of Newcastle, Australia
University of Limerick, Ireland
1
Graph
G
ap Drawing
aw g
The classical graph drawing problem is to develop
algorithms to draw graphs.
The input is a
graph
h with
ith no
geometry
A - B, C, D
B - A, C, D
C - A, B, D, E
D - A, B, D, E
E - C,
C D
The output is a drawing of
the graph; the drawing
should be nice
C
?
A
B
E
D
2
Tokyo subway map
3
psfile
4
Graph Drawing
The output picture is used in a
system design/analysis tool.
The input graph is
some relational
information.
agnt(monkey, eat)
agnt(monkey
eat).
inst(eat, spoon).
obj(eat, walnut).
part of(walnut shell).
part_of(walnut,
shell)
matr(spoon, shell).
file edit insert layout
agnt
?
eat
_
monkey
obj
inst
spoon
X
walnut
part of
part_of
matr
shell
The graph drawing problem is to design
techniques to give good drawings of graphs.
5
Approaches
A graph drawing function
is an optimization
algorithm for specific
optimization goals.
Algorithmic
Person
A graph drawing function
consists of a set of rules for a
drawing, and a generic method
for obtaining a dra
drawing
ing that
satisfies the rules.
Declarative
Person
6
Graph Drawing
1. User requirements
2. Established techniques
3. Algorithmic and Declarative
Approaches
7
User requirements
There are 4 main requirements, from the user’s
user s point of
view (Tao Lin 1992):
1. readability: the drawing should be easy to understand.
2 conformance: the drawing should conform to the
2.
diagrammatic conventions of the application.
3. controllability: specific users need to control the
drawing functions.
4. efficiency: the drawing functions should be efficient.
8
Readability
The drawing should be easy to read, easy to understand,
easy to remember, beautiful.
agnt
monkey
eat
obj
obj
walnut
agnt
shell
h ll
inst
part_of
walnut
matr
spoon
less readable
eat
monkey
inst
spoon
part_of
matr
shell
more readable
9
Readability
Some measures of readability are available:
Avoid
edge crossings
monkey
eat
obj
agnt
shell
inst
part_of
walnut
matr
spoon
Avoid
edge bends
Avoid
long
g edges
g
less readable
10
Readability
There are many readability criteria for good diagrams:
• minimum
i i
edge
d
crossings,
• make edges as
straight as
agnt
obj
walnut
eat
possible,
• minimum edge
lengths,
monkey
inst
part_of
• maximum
i
resolution,
spoon
matr
t
shell
and many more.
11
Conformance
The graph drawing must conform to the rules of the
application domain. Specific domains have their own
diagramming conventions. Sometimes, these have
implications for graph drawing.
These are best expressed as constraints:
 left_of(A,B): node A should appear to the left of node B.
 above(A,B):
(
) node A should appear above node B.
 close_to(A,B): node A should appear close to node B.
 circle(A,B,
( , , …,, ):
) nodes A,B,
, , … , should appear
pp
around
in a circle.
 horizontal(A,B): nodes A and B should share a
horizontal line.
12
Conformance
Examples:
• In a call graph, the left-right order of nodes called from
function A should be the same as the order of the calls in
th source code.
the
d
• In a family tree females should be to the left of males.
main()
{
readdata( … );
validate(( … );
printf( … );
}
main
readdata
printf
validate
13
Controllability
Specific users at specific times need to control the
layout of the graph.
Again, the user’s control can be expressed as the
imposition of constraints:
• center(A): node A should appear near the center of
the page.
• closer(A,B,C): node A should be closer to C than B.
Constraints for user control are not very different from
constraints
t i t for
f conformance.
f
The
Th main
i difference
diff
is
i
that user control constraints cannot be hard coded.
14
Efficiency
Efficiencyy requirements
q
vary:
y
 Interactive systems require a response
within a fraction of a second.
 Users may wait for several minutes for
large printed diagrams.
In terms of computational complexity, algorithms
should have complexity O(n2).
15
Established techniques
• The Sugiyama algorithm
• TRIP
• Springs and cost function
techniques
16
The Sugiyama algorithm
A layered network is a directed
acyclic graph whose nodes are
partitioned into layers L1, L2, ...,
Lk.
These networks are drawn so that:
 the nodes of layer Lm lie on
the line y=m.
 edges
g are monotonic in the y
direction.
The flow is represented from the
top to the bottom.
L6
L5
L4
L3
L2
L1
17
The Sugiyama algorithm
Layered networks are often used to represent
dependency relations.
Sugiyama et al. developed a simple algorithm for
drawing
g layered
y
networks in 1979.
The algorithm aims for
readability:
eadab y
• few edge crossings
• edges as straight as
possible
• nodes spread evenly
over the page
quadrilateral
trapezium
rectangle
t
l
parallelogram
p
g
di
diamond
d
square
18
Sugiyama algorithm: 4 steps
1. Eliminate directed cycles
1
cycles.
2. Place each node into a layer.
3 Order the nodes within
3.
ithin each
layer to avoid edge crossings.
4 Straighten the long edges
4.
edges.
Each step has a corresponding
optimization problem.
We will just look at steps 2 and 3.
19
Sugiyama Step 2: Layering
Step 2
 Input: an acyclic directed graph
 Output: an assignment of nodes to layers, such that all
edges are directed downward.
A - B,
B C
C, D
B - C, D, G
C - E, G
D-E
E - F, G, H
FGH-
A
B
step 2
C
D
E
F
G
H
20
Sugiyama Step 2: Layering
Step 2
 There are several alternative layering algorithms.
 The best algorithm uses linear programming: it
minimizes the total y extent of the edges.
A - B,
B C
C, D
B - C, D, G
C - E, G
D-E
E - F, G, H
FGH-
A
B
step 2
C
D
E
F
G
H
21
Step 3: re-arranging each layer
1
2
3
2
4
5
6
1
4
3
5
6
7
7
step 3
8
10
9
11
13
9
12
14
21 edge
d crossings
i
8
10
11
13
12
14
5 edge crossings
22
Step 3: the sweep
free
free
fixed
1
3
free
fixed
fixed
L6
4
L5
5
6
fixed
free
free
fixed
2
7
8
10
L4
9
11
13
L3
12
14
L2
L1
Step 3 uses a “layer-byl
layer
sweep”,
” ffrom bottom
b tt
to top.
At each stage of the
sweep we:
sweep,
 hold one layer fixed,
and
 re-arrange the nodes
in the layer
y above to
avoid edge crossings.
23
Step 3: re-arranging each layer
1
3
4
fixed
5
6
8
free
2
10
L3
9
11
12
L2
7
8
10
9
12 L2
11
13
L3
9
10
8
11
L3
12
L2
14
24
Step 3: re-arranging each layer
The problem of finding an optimal solution, even for two
layers with one layer fixed, is NP-hard.
f
free
fixed
Li+1
Li
Heuristics
Barycentre algorithm: place each free node at the
barycentre (average position) of its fixed neighbors.
Median algorithm: place each free node at the
barycentre (average position) of its fixed neighbors.
g
are efficient,, and p
perform well in p
practice.
Both algorithms
25
Remarks
The Sugiyama algorithm works quite
well in practice.
It has been adopted in most graph
drawing
gp
packages.
g
© Tom Sawyer
Software
26
Sugiyama technique: Remarks
Sugiyama algorithm
1. readability:
2. conformance:
3. controllability:
4. efficiency:
Excellent.
Poor.
Poor.
Good.
27
TRIP
Kamada ((1989)) implemented
p
ap
pipeline
p
of three steps,
p in
an attempt to provide a general visualization system.
text 1
logical
g
objects
and
relations
l ti
(Prolog)
2
geometric
g
objects
and
relations
l ti
3
picture
(Prolog)
The system is TRIP: TRanslation Into Pictures.
28
TRIP
text
1
logical
objects&
j
relations
2
geometric
objects&
relations
3
picture
1. Analysis
 text -> logical objects and relations
2. Visual mapping
 logical objects -> geometric objects
 logical
g
relations -> g
geometric relations
 encodes requirements of visualization in a constraintstyle prolog
3. COOL
 geometric objects and relations -> picture
 constraint resolution
29
TRIP pipeline step 1: Analysis
Step 1: Analysis
• The
Th text
t t is
i analyzed
l
d iinto
t logical
l i l objects
bj t and
d relations.
l ti
Text
Mike is the boss of
Mary Mark and
Mary,
Marcia.
Mike is male, Mary
and Marcia are
female.
Mike, Marcia, and
Mary are clerks, and
Markk is the
h secretary.
1
Logical Objects and Relations
Boss(Mike,Mary),
Boss(Mike Mark)
Boss(Mike,Mark),
Boss(Mike,Marcia),
Male(Mike), Female(Mary),
Male(Mark), Female(Marcia),
Clerk(Mike),
(
) Clerk(Marcia),
(
)
Clerk(Mary), Secretary(Mark).
30
TRIP pipeline step 2: visual mapping
Step 2. The visual mapping
Step 2
Circle(X, Red) :- Male(X), Clerk(X).
Box(X, Blue) :- Male(X), Secretary(X).
Line(X, Y)
:- Boss(X, Y).
Left_of(X, Y) :- Boss(Z, X), Boss(Z, Y),
Clerk(X), Secretary(Y).
Above(X, Y) :- Boss(X, Y).
Line(X,Y)
:- Boss(X,Y).
31
TRIP pipeline step 2: visual mapping
Step 2. The visual mapping: output
2
Male(Mike), Female(Mary), Male(Mark), Female(Marcia),
Cl k(Mik ) Cl
Clerk(Mike),
Clerk(Marcia),
k(M i ) Cl
Clerk(Mary),
k(M ) Secretary(Mark),
S
t (M k)
Circle(Mike, Red), Circle(Mary, Red), Box(Mark, Blue),
Circle(Marcia Red),
Circle(Marcia,
Red)
Left_of(Marcia, Mark), Left_of(Mary, Mark),
Boss(Mike Mary),
Boss(Mike,
Mar ) Boss(Mike
Boss(Mike, Mark)
Mark), Boss(Mike
Boss(Mike, Marcia)
Marcia),
Line(Mike, Mary), Line(Mike, Mark), Line(Mike, Marcia).
Ab (Mik M
Above(Mike,
Mary),
) Ab
Above(Mike,
(Mik M
Mark),
k)
Above(Mike,Marcia)
32
TRIP pipeline step 3: COOL
Mike
3
Mary
Marcia
Mark
Step 3
St
3: COOL
• COOL is a constraint resolution system.
• All but
b t the
th lowest
l
t llevell graphics
hi primitives
i iti
are h
handled
dl d
by COOL.
• COOL handles overconstrained systems by least
squares approximations.
• Rendering the output of COOL is simple
simple.
33
TRIP: Remarks
The visual mapper (Step 2) of TRIP is easy to adjust
to a specific application. It can be adjusted, for
instance:
 To encode conformance criteria (to conform to
th di
the
diagrammatic
ti conventions
ti
off th
the
application), for example:
– diagrammatic conventions for family trees
trees,
– diagrammatic conventions for conceptual
graphs.
graphs
 To allow specific users to control the drawing
functions (controllability).
34
TRIP: Remarks
But TRIP drawings fail on many readability criteria
 It is difficult to express global readability goals
(such as minimizing crossings, minimize
bends, or minimize area) in TRIP.
TRIP depends crucially on constraint resolution.
 TRIP was relatively
l ti l slow
l
(f an interactive
(for
i
i
graphics system).
 Constraint ssystems
stems sometimes ha
have
e strange
results.
35
TRIP: Remarks
TRIP
1. readability:
2. conformance:
3. controllability:
4. efficiency:
Poor.
Excellent.
Excellent.
Poor.
36
Spring techniques
Spring techniques are quite popular.
1. Place forces between p
pairs of nodes; for
example:
– spring forces for edges
– gravitational repulsion for nonedges
2. Find a zero force configuration.
1.
2.
37
Spring techniques
© Sander
38
Spring techniques
Spring algorithms can be viewed as cost function
techniques:
q
1. Define a cost function which measures ugliness.
g which minimizes the cost function.
2. Find a drawing
For spring algorithms, the ugliness is energy.
high energy
(ugly)
low energy
(beautiful)
39
Spring techniques
Spring techniques can be constrained in various ways.
N il can be
Nails
b used
d tto h
hold
ld
a node in place.
Magnetic fields and magnetized
springs can be used to align nodes
in various ways.
Attractive forces can be
used to keep clusters
together.
These constraints (and others) can be used for
conformance and controllability.
40
Cost function techniques
More g
generally,
y cost function techniques
q
have two p
parts:
1. A model: a cost function which measures ugliness.
g
ugliness 1c1 + 2c2 + … + kck,
where ci measures one aspect
p
of the ugliness
g
of the
drawing, and i is a weight.
2. A method to find a drawing which minimizes the cost
function, that is, minimizes ugliness.
41
Cost function techniques
The second part (the method) can be:
 a continuous optimization technique (if the cost
function is continuous and smooth)
smooth), or
 an Integer Linear Programming technique (if the
cost function and constraints are linear)
linear), or
 a Soft Computing technique (if all else fails).
In general, there is a trade-off between generality and
efficiency: the more general the model, the less
efficient the method.
42
Cost function techniques
Tutte (1960)
• The model uses rubber bands and nails.
• The method uses Gaussian elimination.
Kamada-Kawai (about 1987)
• The model uses springs
p g ((and integrates
g
with TRIP).
)
• The method is from classic Numerical Analysis, and is
relativelyy fast.
Frick ((about 1994))
• The model uses forces.
• The method uses some randomization,, similar to
simulated annealing. It is relatively fast.
43
Cost function techniques
Marks (early 1990s)
• The model copes with geometric constraints called
“Vi
“Visual
lO
Organization
i ti F
Features”.
t
”
• The method is a genetic algorithm.
Davidson-Harel (1992)
• The
Th model
d l uses a few
f
forces
f
plus
l edge
d crossings.
i
• The method is simulated annealing.
The Davidson-Harel technique showed the worst
aspects of soft computing: very high computational
cost for very little effect
effect.
… two interesting techniques: Mendonca (1991),
(1991) and
Branke-Utech (1998)
44
Cost function techniques
Mendonca
• Model: forces plus edge crossings
• Method: simulated annealing
Mendonca aimed to create good drawings of ER / NIAM
diagrams.
Flexibility in Mendonca’s technique.
ugliness 1c1 + 2c2 + … + kck
 It is easy to adjust 1, 2, … k to the needs of a
specific
p
application
pp
area ((conformance),
), or a specific
p
user (controllability).
y
can learn appropriate values for
 Further, the system
1, 2, … k, in a feedback control loop.
45
Cost function methods
Mendonca: drawing NIAM / ER diagrams
graph
graph
d
drawing
i
Soft computing
p
g
method (S.A.)
editor

learning
method
graph
drawing
46
Cost function methods
Mendonca: remarks
 The methods are extremely expensive
computationally.
t ti
ll
 The number of experiments was small, but
perhaps demonstrated the feasibility of
using soft computing techniques to handle
user controllability without explicit user
interaction.
47
Cost function methods
Branke-Utech: Find a technique
q for drawing
g layered
y
networks, better than the Sugiyama technique.
 Model: cost function is
1c1 + 2c2
where
c1= a measure of the quality of the layering,
c2= number of edge crossings,
1, 2 are constants.
 Method: a g
genetic algorithm.
g
48
Two techniques for layered digraphs
Sugiyama technique
successively solves four
optimization problems:
1. Eliminate directed
cycles.
l
2. Place each node
into a layer
layer.
3. Order the nodes
within each layer to
avoid edge
g
crossings.
4. Straighten the long
edges.
Branke-Utech technique
Using
g G.A’s, the
optimization problems in
Steps 2 and 3 are solved
t
together.
th
This gave much better
(more readable) results for
small graphs (less than 50
nodes).
However, the
p
resources
computational
are excessive, making it
impractical.
49
Cost function techniques: remarks
The Brake-Utech technique illustrates some
advantages and disadvantages of Soft
Computing:
p
g
 The flexibility of Soft Computing can give
good results.
 But the computational cost can be high.
50
Cost function techniques: Remarks
1. readability:
2. conformance:
3. controllability:
4. efficiency:
Springs
Average
Average
Average
Average
….
….
….
….
….
Soft Computing
Good
Good
Good
Poor
51
Aside: Other Graph Drawing techniques
a b
d h
i
f
c
e
g
Several tree
drawing
algorithms
g
a
b
d
h
c
e
i
f
g
Three
dimensional
methods
52
Other Graph Drawing Methods
The GIOTTO
method
Graph grammar
methods
53
Algorithmic and Declarative Approaches to Layout
There are two basic approaches to graph drawing:
 Algorithmic Approach: eg, Sugiyama method,
GIOTTO mostt tree
GIOTTO,
t
drawing
d
i methods,
th d visibility
i ibilit
methods, ...
 Declarative Approach: eg,
eg TRIP,
TRIP graph
grammar approaches, some soft computing
methods, ...
Both have advantages and disadvantages . . .
54
Algorithmic and declarative approaches
Sugiyama,
Springs
GIOTTO
readability
conformance
controllability
efficiency
****
*
*
****
**
**
**
**
Soft
Comp
TRIP
***
***
***
*
*
****
****
*
D l ti
Declarative
Algorithmic
Note: Soft computing may offer a good compromise between
algorithmic and declarative approaches
approaches.
55
Algorithmic Approach
Algorithmic Approach: a graph drawing function is an
optimization algorithm for specific optimization goals.
Advantages
• efficient
• mathematical
guarantees of
effectiveness
• good for readability
Disadvantages
• fixed, hard coded optimization
p
goals
• often bound to graph-theoretic
classes (eg trees, directed
graphs, planar graphs)
• often
ft bound
b
d to
t specific
ifi
diagrammatic conventions
• often requires specialist training
56
Algorithmic and Declarative Approaches to Layout
Declarative Approach: a graph drawing function consists
p
y g requirements,
q
, and a
of a method for specifying
generic method for obtaining a drawing according to
the requirements.
Advantages
• user controllable
• conformance to
different applications
is easy
Disadvantages
• slow,
slow sometimes very
slow
• mathematical guarantees
are mostly impossible
• some techniques perform
badly with global
readability goals
57
Integration
Some systems integrate algorithmic/declarative approaches,
for example, TreeSnake (Tao Lin 1992):
user
user
user
user
user
user
user
user
Constraints for controllability
Domain1
Domain2
Domain3
Constraints for conformance
Algorithm1
Algorithm2 Algorithm3
Algorithm4
Al
Algorithmic
i h i toolkit
lki
58
Integration
TreeSnake
user
user
user
user
user
user
user
user
Constraints for controllability
The user controls the drawing
g via constraints.
Domain1
Domain2
Domain3
Constraints for conformance
A domain modeller customizes the algorithm
toolkit with a set of constraints.
Algorithm1
Algorithm2
Algorithm3
Algorithm4
Algorithmic toolkit
An algorithm specialist encodes an algorithm
toolkit, with constraint handling ability.
59
Algorithmic and declarative approaches
TreeSnake demonstrated a healthy integration of algorithmic
and declarative techniques.
q
TreeSnake
readability
d bilit
conformance
controllability
efficiency
****
****
****
****
TreeSnake had many limitations, for example:
 It only covers rooted trees.
 The constrain system was very limited.
However, it did demonstrate the feasibility of integration.
60
Final remarks
Algorithmic and declarative approaches to Graph
Drawing both have advantages and disadvantages.
 Iff efficiency
ff
problems can be overcome, then
perhaps Soft Computing could offer a reasonable
compromise between the two approaches
approaches.
 Integration of constraint handling and classical
algorithmics could offer another compromise.
compromise
61