The ILP approach to the layered

Ago Kuusik

Veskisilla Teooriapäevad 1-3.10.2004 1 Outline

 Introduction  Hierarchical drawing & Sugiyama algorithm  (LP) and Integer Linear Programming (ILP)  Multi-level crossing minimisation ILP  Maximum level planar subgraph ILP

2 Graphs

Set of vertices V (real world: entities)

Set of edges E ::= pairs of vertices (real world: relations) Directed graph: E ::= set of ordered pairs of vertices

3 Graph drawing

 Started to grow in 1960s, aim – software understanding  Now, used in number of areas, for example – Software engineering (call graphs, class diagrams, database schemas) – Social studies (relationship diagrams) – Chemistry (molecular structures)

4 Graph drawing

Definition: Given a graph G=(V, E), represent the graph on a plane: – Vertices – closed shapes – Edges – Jordan curves between vertex shapes (Jordan curve = a closed curve that does not intersect itself)

5 Aesthetic criteria

 General  Application-specific – Min. number of edge – Specific vertex crossings shapes (E-R – Uniform edge diagram) direction (directed – Specific vertex graph) locations (class – Min. number of edge hierarchy) bends – Min. area

6 Hierachical drawing

Given: a (A cyclic graph can be converted acyclic by reversing some edges; minimum is NP hard)  Objective: – Uniform edge direction – Min. Number of edge crossings

7 Sugiyama algorithm

 Published by Sugiyama, Tagawa, Toda 1981  Vertices are placed on discrete layers  Edges have uniform direction  Edges connect vertices of adjacent layers  Reduced edge crossings  Overall balance of vertex locations

8 0. random layout 1. layering

2. sorting on layers 3. final positioning 9 1. Layering

 Assign vertices to discrete layers so that the edges point to common direction – Longest path layering, shortest path layering: simple DFS algorithms – Coffman-Graham layering – constrains the width of the drawing – ILP approaches (Nikolov, 2002)

10 Proper and non-proper layering

Proper Non-Proper

Dummy vertex

11 2. Sorting of vertices on layers

 A combinatorial problem of re-ordering a set instead of a geometric placement problem  Objective: min. edge crossings  NP-hard even for 2 layers (Eades et al, 1986)  Heuristics: barycenter, median, stochastic  ILP approach

12 3. Positioning of vertices

 Objective: balanced positioning, reduction of edge bends  Algorithms: – Linear Programming method (Sugiyama et al., 1981) – Pendulum heuristic (Sander, 1995)

13 Our improvement to Sugiyama algorithm

 We aim to improve the 2nd step: reordering of vertices: – Find the optimal solution or a solution with guaranteed quality – Optimise accross all layers – Consider visualising the maximum level planar subgraph as an alternative to crossing minimisation

14 Min. crossings vs max. planar subgraph

Max. planar subgraph

Min. crossings

15 ILP - motivation

 Possible to get the optimum result faster than by complete enumeration  Known precision of the solution, if a terminated run  Applications where quality is important (like publishing)  Generation of comparative results for proving heuristics  Study of the problem from a different angle

16 ILP vs other approaches

time Complete enumeration ILP

heuristics

quality 17 Linear program - Example

A chemical factory has a line with 3 machines: Unit price x 100 EEK/t A B C 1 x2 200 EEK/t x : 4t/day x : 6t/day x1: 16t/day 1 1 x : 6t/day x : 6t/day x2: 4t/day 2 2

Max. daily capacity (exclusively)

Find the daily amounts (x1 and x2) of products so that the total price is maximal.

18 Linear program - formulation

x2 + max(100x1 200x2) 1 1 subject to: x + x ≤1 16 1 4 2 1 1 4 + ≤ 1 + 1 ≤ (A) x1 x2 1 x1 x2 1 16 4 3 6 6 1 1 100x + 200x (B) x + x ≤ 1 1 2 1 2 2 = = 4 16 x1 3.33; x2 2.67 1 1 + ≤ 1 1 1 (C) x1 x2 1 x + x ≤1 6 6 4 1 16 2 ≥ x1 ,x2 0 1 2 3 4 x1

19 LP solution methods

 Simplex method (Dantzig 1947) – basically a greedy search along the vertices of the polytope determined by constraints – polynomially unbounded – works well in practice  Ellipsoid (Khachyan 1979) and interior point (Karmarkar 1984) methods – polynomially bounded

20 Integer Linear program - Example

A car factory has a line with 3 machines: Piece price x 100 kEEK A B C 1 x2 200 kEEK x : 4p/day x : 6p/day x1: 16p/day 1 1 x : 6p/day x : 6p/day x2: 4p/day 2 2

Max. daily capacity (exclusively)

How many (x1 and x2) of the different car models must be manufactured so that the total price will be maximal.

21 Integer linear program - formulation

x + 2 max(100x1 200x2) subject to: 1 1 x + x ≤1 1 1 16 1 4 2 (A) x + x ≤1 4 1 2 1 1 16 4 x + x ≤ 1 6 1 6 2 1 1 3 (B) x + x ≤ 1 + 1 2 100x1 200x2 4 16 2 1 1 (C) x + x ≤ 1 1 2 1 1 + 1 ≤ 6 6 x1 x2 1 ≥ 4 16 x1 ,x2 0 1 2 3 4 x x1 ,x2 integral 1

22 ILP algorithms

 When the solution of a LP-relaxation is – Integral – we have found the optimal solution – Fractional – need to define a more constrained problem

23 Branch-and-bound algorithm

 Solve the initial LP, let LB = cx

 Select a fractional variable xi=ti and create two subproblems:

≤ ≤   ≤ ≥   min { cx | Ax b, xi ti } min { cx | Ax b, xi ti }

• For each subproblem, SOLVE, if • cx > LB  don’t explore this branch • cx < LB 

• Non-integral x: REPEAT with some xj • Integral x: • LB = cx, if no more unexplored subproblems  optimal solution • x is infeasible  don’t explore this branch

24 Branch-and-bound

25 The lower and upper bounds

Consider a minimisation problem: cx The upper bound = min(cx) over the integral solutions so far

The lower bound = max(cx) over the not yet branched non-integral solutions time

26 Cutting plane algorithm

Do 1. Solve the LP-relaxation 2. If x is not integral 1. Add a constraint to LP-relaxation that separates x from the polytope While x not integral

27 Cutting plane

28 Branch and Cut

 Based on branch-and bound algorithm  Each time a subproblem results in a non-integer solution x, try to find a cutting plane separating x from the polytope  Use only binding constraints for a subproblem

29 Polyhedral combinatorics

Binary vector: x The set of all valid binary vectors: S Weights vector: c

General combinatorial optimisation problem: min { cx subject to x ∈ S}

Replace it with a linear optimisation problem:

min { cx subject to Ax ≤ b}

S = P ∩ Zn , P = { x ∈ Rn : Ax ≤ b} 30 Polyhedral combinatorics

 How to define Ax≤b? This an art!  The best inequalities are those that define a facet of the polytope.  A facet-defining inequality holds as an equality for |x| linearly independent solutions.

31 How to derive an ILP formulation?

 Derive from the ILP formulation of some similar problem, e.g.: – Multi-level crossing minimisation  linear ordering – Maximum level planar subgraph  maximum planar subgraph  Analyse smaller problem instances by software. http://www.informatik.uni-heidelberg.de/groups/comopt/software/PORTA/ (PORTA derives from all enumerated solutions the facets of the polytope supported by these solutions)

32 Multi-Level Crossing Minimisation ILP

p −1 Minimise r ∑ ∑ cijkl r =1 (i , j )(k ,l )∈Er

−cr ≤ xr +1 − xr ≤ cr (i, j),(k,l)∈ E , j < l Subject to ijkl jl ik ijkl r − r ≤ r +1 + r ≤ + r ∈ < 1 cijkl xlj xik 1 cijkl (i, j),(k,l) Er, j l ≤ r + r − r ≤ < < 0 xij xjk xik 1 i j k r r ∈ { } xij ,cijkl 0,1

i k i k xr r r ik i j k r r+1 r+1 r r j l j l xij x jk 33 The vertex-exchange graph

−cr ≤ xr +1 − xr ≤ cr Consider the crossing ijkl jl ik ijkl − r ≤ r +1 + r ≤ + r constraints: 1 cijkl xlj xik 1 cijkl They establish relationships If cr = 0: between linear ordering variables. ijkl r +1 = r x jl xik Objects & relationships  Graph r +1 = − r xlj 1 xik

- + a b de ab ce + + + - + c d e gh cd fh + f g h fg 34 Level planarity testing

1 0 0 - + a b de ab ce + + + - + c e d gh cd fh 1 + 0 0 f h g fg 0

a b + de ab + - c d e + fg cd + f g ce 35 Benefits of V-E graph

 O(|V|2) level planarity testing algorithm (|E| < 2|V| - 4)  O(|V|3) layout algorithm for level planar graph  V-E graph odd/labelled cycle inequalities to crossing minimisation ILP: ∑ cr ≥ 1, C - an odd-labelled fundamental cycle in V-E graph ijkl c r ∈C ijkl

36 Example (random layout)

96 vertices, 110 edges 37 Example (Sugiyama layout)

98 crossings

38 Example (ILP layout)

31 crossings

88s on 300MHz DEC AlphaStation 39 Example (Gansner et al., ‘93)

41 crossings

40 Example (ILP)

38 crossings, 143s 41 Independence system

 A set E; I is a set of subsets of E, ⊆ ⊆ ∈ ∈  F1 F2 E and F2 I  F1 I   (E,I) is an independence system  If C ⊆ E, C ∉ I and for every F ⊂ C, F ∈ I  C is a circuit Determine the maximum weighted member of I: max cT x subject to: + + + = − = ai1x1 ai2 x2 ... ai| E| x| E| | Ci | 1, i 1,2...,| | 0, e ∉C a =  j i ij ∈ 42 1, e j Ci Maximum level planar subgraph ILP

Independent sets – level planar subgraphs Circuits –minimal level non-planar subgraphs

Given a level graph G=(V,E):  ∈ 1, e E p Maximise ∑ xe E ⊂ E, e∈ E, x =  p e ∉ 0, e E p ≤ − Subject to: ∑ xe S 1 S is a MLNP subgraph e∈S

43 MLNP subgraphs - trees

44 MLNP subgraphs – LNP cycles

45 MLNP subgraphs – LP cycles + paths

46 Separation algorithm

47 Using odd-labelled cycles of V-E graph

Use the edges of the original graph that induced an odd-labelled cycles in the vertex-exchange graph

48 Primal heuristic

- is executed each time a subproblem is solved. - The result vector x is employed as weight function for a greedy heuristic 2 stages: 4. Removal 5. Adding attempts

49 MLP subgraph example - original

50 MLP subgraph example – B&C

6 of 65 edges non-planar 96 inequalities 24s 51 Conclusions

Results Open problems  MLNP subgraphs  Specific algorithms for detecting MLNP  Vertex exchange subgraphs? graph  Can we estimate the  Improved crossings crossing number by V-E minimisation ILP graph?  Max. planar  Efficiency of ILP-s: subgraph ILP – employ O(n) level planarity testing – b&c crossing min ILP 52 Thank you for attention!

53