31
FUNDAMENTAL PROBLEMS AND ALGORITHMS Graph Theory and Combinational © Giovanni De Micheli Stanford University

005 Graph Coloring Hypergraphs

Embed Size (px)

Citation preview

Page 1: 005 Graph Coloring Hypergraphs

FUNDAMENTAL PROBLEMSAND

ALGORITHMS

Graph Theory and Combinational

© Giovanni De MicheliStanford University

Page 2: 005 Graph Coloring Hypergraphs

Shortest/Longest path problem

•• Single-source shortest path problemSingle-source shortest path problem.• Model:

– Directed graph GG(V, (V, E)E) with NN vertices.– Weights on each edge.– A source vertex.

• Single-source shortest path problem.– Find shortest path from the source to any vertex.– Inconsistent problem:

• Negative-weighted cycles.

Page 3: 005 Graph Coloring Hypergraphs

Shortest path problem

• Acyclic graphs:– Topological sort O(N O(N 2 2 ).).–– --

• All positive weights:– Dijkstra’s algorithm.

Bellman’s equations: GG(V, (V, E)E) with NN vertices

Page 4: 005 Graph Coloring Hypergraphs

Dijkstra’s algorithmDIJKSTRA(G(V, E, W)){ s 0 =0; for (i =1 to N) s i = w 0,i , repeat { select unmarked vq such that sq is minimal; mark vq ; foreach (unmarked vertex v i ) s i = min {s i , (sq +w q, i )}, } until (all vertices are marked)}

Apply toKorea’s map,robot tour, etc

GG(V, (V, E)E) with NN vertices

Page 5: 005 Graph Coloring Hypergraphs

Bellman-Ford’salgorithmBELLMAN_FORD(G(V, E, W))BELLMAN_FORD(G(V, E, W))

{ s 1 0 = 0; for (i = 1 to N) s 1 i =w 0, i ; for (j =1 to N){ for (i =1 to N){ s j+1

i = min { s j i , (s j k +w q, i )}, } if (s j+1 i == s j i ∀ i ) return (TRUE) ; } return (FALSE) }

k≠i

Page 6: 005 Graph Coloring Hypergraphs

Longest path problem

• Use shortest path algorithms:– by reversing signs on weights.

• Modify algorithms:– by changing min with max.

• Remarks:– Dijkstra’s algorithm is not relevant.– Inconsistent problem:

• Positive-weighted cycles.

Page 7: 005 Graph Coloring Hypergraphs

Example – Bellman-Ford

• Iteration 1: l 0 =0, l 1 =3, l 2 = 1, l 3 =∞.• Iteration 2: l 0 =0, l 1 =3, l 2 =2, l 3 =5.• Iteration 3: l 0 =0, l 1 =3, l 2 =2, l 3 =6.

Use shortest path algorithms: by reversing signs onweights.

source

Page 8: 005 Graph Coloring Hypergraphs

Liao-Wong’salgorithm

LIAO WONG(G( V, E∪ F, W)){ for ( i = 1 to N) l 1 i = 0; for ( j = 1 to |F|+ 1) {{ foreach vertex v i

l j+1 i = longest path in G( V, E,W E ) ;

flag = TRUE; foreach edge ( v p, v q) ∈ F { if ( l j+1

q < l j+ 1 p + w p,q ){

flag = FALSE; E = E ∪ ( v 0 , v q) with weight ( l j+ 1 p + w p,q) } } if ( flag ) return (TRUE) ; } } return (FALSE)

adjust

Page 9: 005 Graph Coloring Hypergraphs

Example – Liao-Wong

•• Iteration 1:Iteration 1: l 0 = 0, l 1 = 3, l 2 = 1, l 3 = 5.• Adjust: add edge (v 0 , v 1 ) with weight 2.•• Iteration 2:Iteration 2: l 0 = 0, l 1 = 3, l 2 = 2, l 3 = 6.

Only positiveedges from (a)

(b) adjusted byadding longestpath from node0 to node 2

Looking for longest pathfrom node 0 to node 3

Page 10: 005 Graph Coloring Hypergraphs

Vertex cover

• Given a graph G(V, E)– Find a subset of the vertices

• covering all the edges.

• Intractable problem.• Goals:

– Minimum cover.– Irredundant cover:

• No vertex can be removed.

Page 11: 005 Graph Coloring Hypergraphs

Example

Page 12: 005 Graph Coloring Hypergraphs

Heuristic algorithm vertex basedVERTEX_COVERV(G(V; E)){ C = ∅ ; while (E ≠≠≠≠≠≠≠≠ ∅ ) do { select a vertex v ∈ V; delete v from G(V, E) ; C=C ∪ {fv} ; }}

Page 13: 005 Graph Coloring Hypergraphs

Heuristic algorithm edge basedVERTEX_COVEREE(G(V, E)){ C = ∅ ; while (E ≠≠≠≠≠≠≠≠ ∅ ) do { select an edge {u, v} ∈ E; C=C ∪ {u, v}; delete from G(V, E) any edge incident to either u or v ; }}

Page 14: 005 Graph Coloring Hypergraphs

Graph coloring

• Vertex labeling (coloring):– No edge has end-point with the same label.

• Intractable on general graphs.• Polynomial-time algorithms for chordal (and

interval) graphs:– Left-edge algorithm.

Page 15: 005 Graph Coloring Hypergraphs

Graph coloring heuristic algorithmVERTEX_COLOR(G(V, E)){ for (i =1 to |V| ) { c =1 while (∃ a vertex adjacent to vv ii

with color c) do { c = c +1; color v i with color c ; } }}

Page 16: 005 Graph Coloring Hypergraphs

Graphcoloring

exactalgorithm

EXACT_COLOR( G( V, E) , k)EXACT_COLOR( G( V, E) , k){repeat { NEXT VALUE( k) ; if ( c k == 0) return ; if ( k == n) c is a proper coloring; else EXACT COLOR( G( V, E) , k+ 1) }}

Page 17: 005 Graph Coloring Hypergraphs

Graphcoloring

exactalgorithm

NEXT VALUE( k)NEXT VALUE( k){repeat { c k = c k + 1; if ( there is no adjacent vertex to v k with the same color c k ) return ; } until ( c k =< maximum number of colors ) ; c k = 0;}

Page 18: 005 Graph Coloring Hypergraphs

Interval graphs

• Edges represent interval intersections.• Example:

– Restricted channel routing problem with novertical constraints.

• Possible to sort the intervals by left edge.

Page 19: 005 Graph Coloring Hypergraphs

Example

Page 20: 005 Graph Coloring Hypergraphs

Example

Page 21: 005 Graph Coloring Hypergraphs

Left-edgealgorithmLEFT EDGE( I)

{ Sort elements of I in a list L with ascending order of li ; c = 0; while (Some interval has not been colored ) do {{ S = ∅ ; repeat { s = first element in the list L whose left edge l s is higher than the rightmost edge in S. S= S ∪ { s} ; } until ( an element s is found ); c = c + 1; color elements of S with color c; delete elements of S from L; } }}

Page 22: 005 Graph Coloring Hypergraphs

Clique partitioning and covering

• A clique partition is a cover.• A clique partition can be derived from a cover by

making the vertex subsets disjoint.• Intractable problem on general graphs.• Heuristics:

– Search for maximal cliques.• Polynomial-time algorithms for chordal graphs.

Page 23: 005 Graph Coloring Hypergraphs

Heuristicalgorithm

CLIQUEPARTITION( G( V, E) )CLIQUEPARTITION( G( V, E) ){ =∅ ; while ( G( V, E) not empty ) do { compute largest clique C V in G( V, E) ; =∪ C; delete C from G( V, E) ; }}

CLIQUE( G( V, E) )CLIQUE( G( V, E) ){ C = seed vertex; repeat { select vertex v ∈ V , v∉ C and adjacent to all vertices of C; if (no such vertex is found) return C = C ∪ {v} ; }}}}

Page 24: 005 Graph Coloring Hypergraphs

Covering and Satisfiability

• Covering problems can be cast as satisfiability.• Vertex cover.

– Ex1: ( x 1 + x 2 ) (x 2 + x 3 ) (x 3 + x 4 ) (x 4 + x 5)– Ex2: (x3 + x4 ) (x1 + x3) (x1 + x2) (x2 + x4) (x4 + x5)

• Objective function:• Result:

– Ex1: x 2 = 1, x 4 = 1– Ex2: x 1 = 1, x 4 = 1

Page 25: 005 Graph Coloring Hypergraphs

Covering problem

• Set covering problem:– A set S.– A collection C of subsets.– Select fewest elements of C to cover S.

• Intractable.• Exact method:

– Branch and bound algorithm.• Heuristic methods.

Page 26: 005 Graph Coloring Hypergraphs

Examplevertex-cover of a graph

Page 27: 005 Graph Coloring Hypergraphs

Exampleedge-cover of a hypergraph

Page 28: 005 Graph Coloring Hypergraphs

Matrix representation• Boolean matrix: A.A.• Selection Boolean vector: x.x.• Determine x x such that:

–– A xA x ≥≥≥≥ 1.– Select enough columns to cover all rows.

• Minimize cardinality of x.

Page 29: 005 Graph Coloring Hypergraphs

Branch and bound algorithm• Tree search of the solution space:

– Potentially exponential search.• Use bounding function:

– If the lower bound on the solution cost that can bederived from a set of future choices exceeds the cost ofthe best solution seen so far:

– Kill the search.• Good pruning may reduce run-time.

Page 30: 005 Graph Coloring Hypergraphs

Branch andbound

algorithm

BRANCH_AND_BOUND{Current best = anything;Current cost = 1;S= s 0 ; while (S6 = ; ) do { Select an element in s 2S; Remove s from S ; Make a branching decision based on s yielding sequences f s i ; i= 1; 2; ...; mg ; for ( i = 1 to m) { Compute the lower bound b i of s i ; if ( b i Current cost) Kill s i ; else { if ( s i is a complete solution ) { Current best = s i , Current cost = cost of s i, } else Add s i to set S; } } }}

Page 31: 005 Graph Coloring Hypergraphs

Example