comp4048 planar and orthogonal graph drawing algorithms richard webber national ict australia
Post on 22-Dec-2015
222 views
TRANSCRIPT
COMP4048Planar and Orthogonal Graph
Drawing Algorithms
Richard WebberNational ICT Australia
Lecture Overview
• Planarity• Testing Planarity• Tessellation Drawings• Visibility Drawings• Polyline Drawings• Orthogonal Drawings via Visibility
Drawings• Orthogonal Drawings via Network Flow• Degree > 4• Bend Stretching• Degree > 4 again
Planarity
• A graph is planar if it can be drawn such that no edges cross
• A drawing is planar if it is drawn with no edges crossing
Planarity
• Straight-line drawing with no edge crossings = Fáry Drawing (Fáry 1948)
• 2D Fáry Drawing = Planar (Graph) Drawing
Planar Drawing Planar Embedding Planar
Graph• Plane Graph (drawing) = 2d
Planarity
• Simple Planar Embedding n + f = m + 2
m = O(n) and f = O(n)
m 3n-6
Euler
(http://www-history.mcs.st-andrews.ac.uk/Biographies/Euler.html)
Testing Planarity
• (Di Battista et al. 1999, Goldstein 1963)• Trees and SP Digraphs = planar• Graph = planar
connect components = planar• Connect components = planar
biconnected components = planar– Biconnected two vertex-disjoint
paths
Testing Planarity
1. Find a cycle C in G (biconnected cycle must exist)
2. Decompose remaining edges into pieces Pi
– Connected without passing vertices of C
– Incident vertices in C are attachments of Pi
– If C 2+ pieces then C is separating– If C 1 piece then C is non-separating
– C non-separating and P1 a path separating C
Testing Planarity
Testing Planarity
• Each piece must lie entirely inside or outside C
• Two pieces interlace if they cannot both be inside (outside) C without breaking planarity
• Interlacement graph I of G with respect to C
– Vertices = pieces of G– Edges between interlacing
pieces
Testing Planarity
• Biconnected G with cycle C is planar iff1. For each piece P, P’ = P C is planar;
and2. Interlacement graph I is bipartite
• Planarity of P’
determinedrecursively
Testing Planarity
1. Compute piece of G with respect to C2. For each non-path piece P
1. P’ = P C
2. C’ = cycle of P’ by replacing C between consecutive attachments with a path through P
3. Recursively test P’ with C’ – return if “non-planar”
3. Compute interlacement graph I4. Return “non-planar” if I not bipartite5. Return “planar”
Testing Planarity
• Computing pieces and finding C’: O(n)• Computing I and testing bipartite: O(n2)• Each invocation = O(n2), O(n) invocations
O(n3) running time• Can be improved to O(n) (Hopcroft+Tarjan
1974)• Can construct planar embedding
– use bipartite interlacement graph to alternate inside/outside pieces
– path-pieces trivially inserted– non-path-pieces constructed recursively
Planar st-Graphs
• (Di Battista et al. 1999, Lempel et al. 1967)• Digraphs only• s = source, t = sink – only one of each
– Add dummies if needed• Topological numbering – number(v) for v V
such that (u, v) E number(v) > number(u)• Topological sorting – numbering [0..n-1]• For weighted edges
number(v) number(u) + weight(u, v)• number(s) = 0; number(v) by max over BFS
– optimal in O(n + m) time
Planar st-Graphs
Planar st-Graphs
• F = faces of planar st-graph G such thatexternal face split: left s* and right t*
• orig(e), dest(e), left(e), right(e)
• left(v), right(v), orig( f ), dest( f )
• orig(v) = dest(v) = v; left( f ) = right( f ) = f
• G* = ( F, { ( left(e), right(e) ) | e E } )– G* is also planar st-graph
Planar st-Graphs
Planar st-Graphs
Tessellation Drawings
• (Di Battista et al. 1999, Tamassia+Tollis 1989)
• Vertices / Edges / Faces = Objects• Object o drawn as a rectangle (o)
– Possibly degenerate (o1) (o2) =
• Union over all o V E F = rectangle (o)s horizontally adjacent os left/right (o)s vertically adjacent os orig/dest
Tessellation Drawings
1. G* from G2. Topological numbering Y of G3. Topological numbering X of G*
4. For each o V E F– xL(o) = X(left(o))
– xR(o) = X(right(o))
– yB(o) = Y(orig(o))
– yT(o) = Y(dest(o))
• O(n) time and O(n2) area
Tessellation Drawings
Visibility Drawings
• (Di Battista et al. 1999, Tamassia+Tollis 1986)
• Vertices = Horizontal lines• Edges = Vertical lines• Intersections only where edges meet
end-points• Tessellation Drawing Visibility
Drawing– degenerate vertices, non-degenerate faces
Visibility Drawings
1. G* from G2. weight(e) = 1 – Optimal topological
numbering Y of G3. weight(e*) = 1 – Optimal topological
numbering X of G*4. For each v V
– y (v) = Y(v); xL(v) = X(left(v)); xR(v) = X(right(v))-1
5. For each e E– x (e) = X(left(e)); yB(e) = Y(orig(e)); yT(e) = Y(dest(e))
• O(n) time and O(n2) area
Visibility Drawings
Constrained Visibility
• (Di Battista et al. 1999, Di Battista et al. 1992)
• Identify non-intersecting paths i in G– No common edges– No “crossings”– Can “touch” at vertices
Constrained Visibility
• Set of paths covers G – Add single-edge paths
1. Duplicate each path, adding faces to G* gives G
2. weight(e) = 1, Y(s) = 0 – Optimal topological numbering Y of G
3. weight(e*) = 0.5, X(s*) = -0.5 – Optimal topological numbering X of G
Constrained Visibility
4. For each : for each e – x (e) = X()– yB(e) = Y(orig(e))– yT(e) = Y(dest(e))
5. For each v V– y(v) = Y(v)– xL(v) = minv X()– xR(o) = maxv X()
• O(n) time and O(n2) area
Constrained Visibility
Polyline Drawings
• (Di Battista et al. 1999, Di Battista et al. 1992)
1. Construct a visibility drawing2. Place vertex vi at an arbitrary pi on
its line segment3. Draw short edge (vi, vj) as line pi pj
4. Draw long edge (vi, vj) as polyline pi (x(u, v), yu+1) (x(u, v), yv-1) pj
Polyline Drawing
• Place vertex at mid-point of its line segment
• O(n) time and O(n2) area
6n-12 bends (2 per edge)
Polyline Drawing
• Place vertex above long edges if they exist
• O(n) time and O(n2) area
(10n-31)/3 bends
Polyline Drawing
• Use constrained visibility
• Place vertex on path
• O(n) time and O(n2) area
4n-10 bends
Orthogonal via Visibility
• (Di Battista et al. 1999)• Input = planar st-graph1.Create subpaths v for v {s,t}
– 2 incoming edges leftmost-inrightmost-out
– 1 or 3 incoming edges median-inmedian-out
Orthogonal via Visibility
Orthogonal via Visibility
2. Unify subpaths with common edges to give
3. Apply Constrained-Visibility algorithm
Orthogonal via Visibility
4. Create orthogonal drawing– Place vertex v {s,t} on path v
– Place s (t) on path of median of out (in) edges
– Routes general edges via paths– Route s (t) edges as …
Orthogonal via Visibility
• O(n) time, O(n2) area, 2n+4 bends
Orthogonal via Network Flow
• (Di Battista et al. 1999, Tamassia 1987)• Visibility guarantees O(1) bends per edge• Want to minimise total bends for embedding
– minimising over all embeddings in NP-hard• Represent angles as a commodity
– Produced by vertices, consumed by faces, transferred by bends
• Apply a cost to each bend– Minimising bends = minimising cost of
flow!
Orthogonal via Network Flow
• Replace each (undirected) edge (u, v) with two darts (u, v) and (v, u)
– dart = counterclockwise for f f is on left (u, v)·/2 = angle from dart (u, v) to
next dart counterclockwise about u (u, v) = number of “left” bends in (u, v)
• Orthogonal representation = all (, )– Same representation same number
bends
Orthogonal via Network Flow
Orthogonal via Network Flow
• Network N such that…• Source (sink) v produces (consumes) (v)• Arc (u, v) has
– Lower bound (u, v)
– Capacity (u, v)
– Cost (u, v)
– Flow (u, v) such that (u, v) (u, v) (u, v)
• Sum into v {s,t} = sum out• Cost of flow in N = sum all (u, v)·(u, v)
Orthogonal via Network Flow
• Embed Graph G into Network N by…• Nodes of N = vertices and faces of G• Vertex-node v produces (v) = 4
• Internal face-node f consumes (f) = 2a(f)-4
• External face-node f consumes (f) = 2a(f)+4
– a(f) = number vertex-angles in face f
Orthogonal via Network Flow
• Dart (u, v) with left (right) face f (g) – arc (u, f): (u, f) = 1, (u, f) = 4, (u, f) = 0
(u, v)
– arc (f, g): (f, g) = 0, (f, g) = , (f, g) = 1 (u, v)
Orthogonal via Network Flow
1. Construct N from G – O(n) time2. Compute minimum cost flow for N –
O(n2 log n) (Ahuja et al. 1993) or O(n7/4 log n) (Garg+Tamassia 1997) time
3. Map N to orthogonal representation for G – O(n) time
Orthogonal via Network Flow
• To map orthogonal representation to drawing…
1. Divide the faces into rectangles• e corner(e) next(e) – counterclockwise• turn(e) = +1 (left), 0 (straight), –1 (right)• front(e) = 1st next(e’) s.t. sum e..e’ = +1
• If turn(e) = –1 then insert– Vertex project(e) in front(e)
– Edge extend(e) = (corner(e), project(e))
Orthogonal via Network Flow
• External face by enclosing in a rectangle• Total O(n+b) time – b = number of bends
Orthogonal via Network Flow
2. Assign edge lengths• Minimising lengths/area – compaction• Interior rectangles: (u, v) 2, (u, v) =
0
• Exterior rectangle: (u, v) 2, (u, v) = 0
• Use horizontal and vertical flow networks, Nhor and Nver
Orthogonal via Network Flow
• Horizontal Flow Network Nhor
– Nodes = interior faces of G plus lower s and upper t outer face
– Arcs (f, g) face f shares horizontal edge with face g – f below g
(f, g) = 1, (f, g) = , (f, g) = 1 (f, g) = length of horizontal edge
• Nver is analogous
Orthogonal via Network Flow
Orthogonal via Network Flow
• Run-time dominated by network flow– O(n2 log n) or O(n7/4 log n) – Guarantees minimal
width/height/length/area• Alternative Method
– Place dummy vertices in external corners– Treat vertical (horizontal) paths as vertices– Calculate topological ordering X (Y)– Edge length = X(v)-X(u) (Y(v)-Y(u))– O(n) time, but no guarantee of minimal
total edge length
Degree > 4
• (Di Battista et al. 1999, Fößmeier+ Kaufmann 1996)
• Replace vertex v of degree d > 4 with a cycle v1, …, vd – each vi incident to one edge incident to v
• Solve using Network Flow such that cycle edges have no bends…
– For edge (u, v) separating faces f and g,(f, g) = (g, f) = 0
• By planarity, still O(n) vertices
Degree > 4
Bend Stretching
• (Di Battista et al. 1999, Tamassia+Tollis 1989)
1. Take any planar orthogonal drawing2. Identify configurations that can be
transformed to reduce bends3. Iterate• General case requires O(n2)
• Identifying special cases requires O(n)
Bend Stretching
Bend Stretching
Bend Stretching
Bend Stretching
Bend Stretching
Alternative Degree > 4
• (Di Battista et al. 1999, Papakostas+Tollis 1997)
• Vertices are rectangular boxes– width = max(1, out-degree-1)
– height = max(1, in-degree/2-1)
• Place vertices in order by st-numbering– Place above previous vertex– Place between median in-coming edges– Route in-coming edges to left and right sides– Route out-going edges from top
Degree > 4
References
• I. Fáry (1948): “On Straight Lines Representations of Planar Graphs” in Acta Scientiarum Mathematicarum, 11:229-233
• G. Di Battista, P. Eades, R. Tamassia, I. G. Tollis (1999): Graph Drawing: Algorithms for the Visualization of Graphs, Prentice-Hall
• A. J. Goldstein (1963): “An Efficient and Constructive Algorithm for Testing Whether a Graph can be Embedded in the Plane”, Proc. Graph and Combinatorics Conf.
• J. Hopcroft, R. E. Tarjan (1974): “Efficient Planarity Testing”, J. ACM, 21(4):549-568
• A. Lempel, S. Even, I. Celerbaum (1967): “An Algorithm for Planarity Testing of Graphs”, Proc. Int. Symp. Theory of Graphs (1966), pp. 215-232, Gordon and Breach
References
• R. Tamassia, I. G. Tollis (1989): “Tessellations Representations of Planar Graphs”, Proc. 27th Allerton Conf. Communication, Control and Computing
• R. Tamassia, I. G. Tollis (1986): “A Unified Approach to Visibility Representations of Planar Graphs”, Discrete and Computational Geometry, 1(4):321-341
• G. Di Battista, R. Tamassia, I. G. Tollis (1992): “Constrained Visibility Representations of Graphs”, Information Processing Letters, 41:1-7
• R. Tamassia (1987): “On Embedding a Graph in the Grid with the Minimum Number of Bends”, SIAM J. Computing, 16(3):421-444
• R. K. Ahuja, T. L. Magnanti, J. B. Orlin (1993): Network Flows: Theory, Algorithms and Applications, Prentice-Hall
References
• A. Garg, R. Tamassia (1997): “A New Minimum Cost Flow Algorithm with Applications to Graph Drawing”, Proc. Graph Drawing (1996), Springer-Verlag, LNCS 1190:193-200
• U. Fößmeier, M. Kaufmann (1996): “Drawing High Degree Graphs with Low Bend Numbers”, Proc. Graph Drawing (1995), Springer-Verlag, LNCS 1027:254-266
• R. Tamassia, I. G. Tollis (1989): “Planar Grid Embedding in Linear Time”, IEEE Trans. Circuits and Systems, 36(9):1230-1234
• A. Papakostas, I. G. Tollis (1997): “Orthogonal Drawing of High Degree Graphs with Small Area and Few Bends”, Proc. 5th Work. Algorithms and Data Structures, Springer-Verlag, LNCS, 1272:354-367