Chapter 9
(Layered drawings of digraphs) u v
By: Waldo & Ludo
Chapter 9 (Graphically)
1. The hierarchical approach:
DiGraph G Cyclic
Cycle Removal
(9.4)
Handled by :
Waldo aCyclic
Layer assignment
(9.1)
Crossing reduction
(9.2)
(9.3)
X coordinate assignment
Ludo
Waldo
Layered drawing of G
Important requirements of layering:
1. The layered digraph should be compact.
2. The layering should be proper.
3. The number of dummy vertices should be small
The layering algorithm:
1. No labels are set
2. Assign labels (integer), such that s < v < t
3. Assign vertices to a layer, such that layer of t <= v <= s
selecting vertices to label
1.
When choosing a vertex v all preceding vertices u (u,v) should be labeled and minimized.
Minimization is accomplished by looking at the most significant labels.
Example {6} < {3,7}; {1,2,9} < {2,3,9}; etc.
For more on this definition see page 274 of the book
Phase one (assign labels)
7
9 10
12
1
4
2
3
8
11
13
6
5
selecting vertices to add to a layer
1.
When choosing a vertex u all vertices v (u,v) should be placed in a layer lower than u.
7
9
Phase two (assign layers)
1
4
10
12
2
11
13
3
8
6
5
1
3
5
8
10
12
13
L
4
L
3
L
2
L
1
L
7
L
6
L
5
2
4
7
9
11
6
Algorithm (Coffman-Graham layering)
Input: Reduced digraph G=(V,E) and a positive integer W
Output: Layering of G of width at most W
Initially, all vertices are unlabeled (trivial, as we’ve seen)
For (i = 1 to |V|) perform a.
Choose an unlabeled vertex v, such that {lbl(u) : (u,v) element of E } is minimized b.
Lbl(v) = i
K=1; L1=null; U=null.
While U != V loop a.
Choose u element of (V-U), such that every vertex in {v : (u,v) element of E} is in U, and lbl(u) is maximized b. If not |Lk| < W and for every edge (u,w), w is element of preceding levels then k++; add u to Lk c. Add u to U.
7
9 10
12
1
4
8
11
13
2
3
Phase two (adjusted)
6
5
L
4
L
3
L
2
L
1
L
7
L
6
L
5
13
1
4
8
10
12
9
11
3
7
6
5
2
Algorithm (Coffman-Graham layering) adjusted
1) Exercise.. (only for phase two – previous slide)
A. Describe the adjusted algorithm
B. Draw the iterational steps of the adjusted algorithm one by one.
Crossing Reduction
• Input: proper layered digraph
• Layer-by-Layer Sweep
• Two-Layer Crossing Problem
Two-Layer Crossing Problem
• Each vertex in the two layers gets a unique x-coordinate, purely for ordering purposes:
L
3
L
2
L
1 x
1
1 x
1
2 x
1
3 x
2 x
1
L
3
Two-Layer Crossing Problem cross ( G , x
1
, x
2
)
1 opt ( G , x
1
)
min x
2 cross ( G , x
1
, x
2
)
Two-Layer Crossing Problem
L
2
L
1 x
1
1 x
1
2 x
1
3 x
2 x
1
Crossing Numbers c uv
0
L
2 u
L
1 x
1
1 x
1
2 v x
1
3 x
2 x
1
Crossing Numbers c uv
0 c vu
1
L
2 v
L
1 x
1
1 x
1
2 u x
1
3 x
2 x
1
p
Crossing Numbers q u r u r p q 5
6 p
0
2
0
9 q
2
3
0
2
1
6
( G , r
1 x
1
, x
2
)
x
2
( u )
x
2
( c uv v )
3
6
0
p
Crossing Numbers q u r u r p q 5
6 p
0
2
0
9 q
2
3
6
0 u
1
2
3
6 r
1
0 cross ( G , x
1
, x
2
)
x
2
( u )
x
2
( c uv v )
p
Crossing Numbers q u r u r p q 5
6 p
0
2
0
9 q
2
3
6
0 u
1
2
3
6 r
1
0 cross ( G , x
1
, x
2
)
x
2
( u )
x
2
( c uv v )
2
1
1
6
3
6
19
p
Crossing Numbers q u r u r p q 5
6 p
0
2
0
9 q
2
3
6
0 u
1
2
3
6 r
1
0 opt ( G , x
1
)
u
, v min( c uv
, c vu
)
p
Crossing Numbers q u r u r p q 5
6 p
0
2
0
9 q
2
3
6
0 u
1
2
3
6 r
1
0 opt ( G , x
1
)
u
, v min( c uv
, c vu
)
2
1
1
6
3
2
15
Algorithms for minimizing
• Adjacent Exchange
Similar to Bubble-sort
• Split
Similar to Quick-sort
• Barycenter Method
• Median Method
Quadratic time
Linear time
L
2
Adjacent-Exchange u v
L
1 c uv
3
L
2
Adjacent-Exchange v u
L
1 c uv
3 c vu
0
L
2
Adjacent-Exchange u v
L
1 c uv
2
L
2
Adjacent-Exchange v u
L
1 c uv
2
c uv
2 c vu
1
V left
{}
Split
V right
{}
L
2 a p
L
1 c ap
3
V left
{}
Split
V right
{}
L
2 p a
L
1 c ap
3 c pa
0
L
2
V left
{}
Split
V right
{ a } p b
L
1 c pb
1
L
2
V left
{}
Split
V right
{ a } b p
L
1 c pb
1 c bp
2
L
2
V left
{}
Split
V right
{ a , b } p
L
1 c pb
1 c bp
2
V left
{}
Split
V right
{ a , b }
L
2 p a b
L
1
c uv
3
u
Barycenter Method
1 2 3 4 5 avg ( u )
1 deg( u )
v
N u x
1
( v ) avg ( u )
1
2
( 1
4 )
2 .
5
6 7
Median Method u
1 2 3 4 5 6 7 med ( u )
x
1
( v
j / 2
) ???
med ( u )
x
1
(
Median v
j / 2
• X-coordinate of u is the median of its neighbours
• If no neighbours, then med(u) = 0
• Special case, if med(u) = med(v)...odd degree left, even right
)
Not always optimal
Barycenter
1 2 3 4
Median
5 6 7
1 2 3 4 5 6 7 8 9 10
Horizontal Coordinate Assignment
• Bends occur at dummy vertices
• Objective is to:
– Reduce angles of bends (minimal width)
– Keep ordering of crossing reduction step
X
0 1 2 3 4 5 6
1 k
6
2
3 x ( v i
)
x ( v
1
)
i k
1
1
a i
( v k
)
x ( v
1
)
4
2
3 g p
( p )
i k
1
2
( x ( v i
)
a i
)
2 i
3
5
5 p
( 6 g ( p ) )
2 x ( w )
x ( z )
6
1
4
7
1
5
8
2
6
9
Cycle Removal
3
• Vertex sequence for G :
S
( v
1
, v
2
,..., v n
)
• Dashed edges are the leftward edges
• Leftward edges form feedback set R
• Reversing R makes G acyclic
2 3 4 5 6 7 8 9
Cycle Removal
• Problem:
– Minimizing leftward edges / feedback set R
• How?
– Greedy Cycle Removal Algorithm
Cycle Removal
4
1
5
2
6
3
7 8 9
• Iterate: prepend sinks to S r and remove them from G
S l
{} S r
{}
Cycle Removal
4
1
5
2
6
3
7 8
• Iterate: prepend sinks to S r and remove them from G
S l
{} S r
{ 9 }
Cycle Removal
4
1
5
2
6
3
7 8
• Iterate: prepend sinks to S r and remove them from G
• Iterate: append sources to S l and remove them from G
S l
{} S r
{ 9 }
4
7
Cycle Removal
5
2
6
3
8
• Iterate: prepend sinks to S r and remove them from G
• Iterate: append sources to S l and remove them from G
S l
{ 1 } S r
{ 9 }
4
7
5
8
Cycle Removal
6
3
• Iterate: prepend sinks to S r and remove them from G
• Iterate: append sources to S l and remove them from G
S l
{ 1 , 2 } S r
{ 9 }
4
7
5
8
6
Cycle Removal
• Iterate: prepend sinks to S r and remove them from G
• Iterate: append sources to S l and remove them from G
S l
{ 1 , 2 , 3 } S r
{ 9 }
4
7
5
8
Cycle Removal
• Iterate: prepend sinks to S r and remove them from G
• Iterate: append sources to S l and remove them from G
S l
{ 1 , 2 , 3 , 6 } S r
{ 9 }
Cycle Removal
4
7
5
8
• Iterate: prepend sinks to S r and remove them from G
• Iterate: append sources to S l and remove them from G
• Choose vertex u such the
outdegree(u) – indegree(u) is max, append to S l and remove from G
S l
{ 1 , 2 , 3 , 6 } S r
{ 9 }
Cycle Removal
• Iterate: prepend sinks to S r and remove them from G
• Iterate: append sources to S l and remove them from G
• Choose vertex u such the
outdegree(u) – indegree(u) is max, append to S l and remove from G
• Concatenate S l and S r to obtain S
S l
{ 1 , 2 , 3 , 6 , 4 , 5 , 7 , 8 } S r
{ 9 }
Cycle Removal
4
1
5
2
6
3
7 8 9
1 2 3 6 4 5 7 8 9
Cycle Removal
4
1
5
2
6
3
7 8 9
1 2 3 6 4 5 7 8 9
Chapter 9 (in a nutshell)
The hierarchical approach:
Layer assignment
Crossing reduction
Horizontal coordinate assignment
Exercise
1) Prove Theorem 9.1 (Exercise 3 in book)