talk graph algorithms

8
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path Graph algorithms Tran, Van Hoai Faculty of Computer Science & Engineering HCMC University of Technology E-mail: [email protected] Homepage: http://www.cse.hcmut.edu.vn/˜hoai 2011-2012 Tran, Van Hoai Graph algorithms Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path Definitions & representation Study “Advanced Algorithms” Tran, Van Hoai Graph algorithms Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path Definitions & representation Study “Advanced Algorithms” Representation Adjacency-matrix A: (normally ) for dense graph Incident-matrix B : with size |V | × |E | b ie = 1 if edge e leaves vertex i 1 if edge e enters vertex i 0 otherwise Adjacency-list representation: (normally) for sparse graph Tran, Van Hoai Graph algorithms Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path Definitions & representation Study “Advanced Algorithms” Representation Adjacency-matrix A: (normally ) for dense graph Incident-matrix B : with size |V | × |E | b ie = 1 if edge e leaves vertex i 1 if edge e enters vertex i 0 otherwise Adjacency-list representation: (normally) for sparse graph Weighted graph G = (V ,E ) aij = w ij if (i , j ) E 0 otherwise Tran, Van Hoai Graph algorithms

Upload: dinh-nguyen-cat

Post on 06-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 1/31

Basic graph theoryGraph problems and algorithms

Sparse graphsAssignment 2 - Shortest path

Graph algorithms

Tran, Van Hoai

Faculty of Computer Science & EngineeringHCMC University of Technology

E-mail: [email protected]

Homepage: http://www.cse.hcmut.edu.vn/˜hoai

2011-2012

Tran, Van Hoai Graph algorithms

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 2/31

Basic graph theoryGraph problems and algorithms

Sparse graphsAssignment 2 - Shortest path

Definitions & representation

Study “Advanced Algorithms”

Tran, Van Hoai Graph algorithms

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 3/31

Basic graph theoryGraph problems and algorithms

Sparse graphsAssignment 2 - Shortest path

Definitions & representation

Study “Advanced Algorithms” Representation

Adjacency-matrix A: (normally ) for dense graph Incident-matrix B : with size |V | × |E |

b ie  =

−1 if edge e  leaves vertex i 

1 if edge e  enters vertex i 

0 otherwise

Adjacency-list representation: (normally) for sparse graph

Tran, Van Hoai Graph algorithms

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 4/31

Basic graph theoryGraph problems and algorithms

Sparse graphsAssignment 2 - Shortest path

Definitions & representation

Study “Advanced Algorithms” Representation

Adjacency-matrix A: (normally ) for dense graph Incident-matrix B : with size |V | × |E |

b ie  =

−1 if edge e  leaves vertex i 

1 if edge e  enters vertex i 

0 otherwise

Adjacency-list representation: (normally) for sparse graph

Weighted graph G  = (V ,E )

aij  =

w ij  if  (i , j ) ∈ E 

0 otherwise

Tran, Van Hoai Graph algorithms

B i h h

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 5/31

Basic graph theoryGraph problems and algorithms

Sparse graphsAssignment 2 - Shortest path

Notations

I (v ), I +(v ), I −(v ) ∈ E : incident, incident-out, incident-inedge set of v 

A(v ) ∈ V : adjacent vertex set of v 

Tran, Van Hoai Graph algorithms

B i h th

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 6/31

Basic graph theoryGraph problems and algorithms

Sparse graphsAssignment 2 - Shortest path

Basic problems

Topological sort

Minimum spanning trees Single-source shortest paths

All-pair shortest paths

Maximum flow

Strongly connected components Transitive closure

Tran, Van Hoai Graph algorithms

Basic graph theory

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 7/31

Basic graph theoryGraph problems and algorithms

Sparse graphsAssignment 2 - Shortest path

Minimum spanning tree

IP model

min e ∈E w e x e 

s.t.

e ∈E  x e  = |V | − 1(u ,v )∈E :u ∈S ,v ∈S x (u ,v ) ≤ |S | − 1 ∀S  ⊆ V 

x e  ∈ {0, 1} ∀e ∈ E 

Tran, Van Hoai Graph algorithms

Basic graph theory

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 8/31

Basic graph theoryGraph problems and algorithms

Sparse graphsAssignment 2 - Shortest path

Minimum spanning tree

IP model

min e ∈E w e x e 

s.t.

e ∈E  x e  = |V | − 1(u ,v )∈E :u ∈S ,v ∈S x (u ,v ) ≤ |S | − 1 ∀S  ⊆ V 

x e  ∈ {0, 1} ∀e ∈ E 

Prim’s algorithm O (V 2) Kruskal’s algorithm O (|V ||E |)

Tran, Van Hoai Graph algorithms

Basic graph theory

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 9/31

Basic graph theoryGraph problems and algorithms

Sparse graphsAssignment 2 - Shortest path

MST algorithms

Algorithm 1: PrimInput: G , r 

beginE T  = ∅;V T  = {r };while V T  = V  do

(u , v ) = arg mine  connected to S {w e };E T  = E T  ∪ {(u , v )};V T  = V T  ∪ {{u , v } \ S };

end

end

Tran, Van Hoai Graph algorithms

Basic graph theory

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 10/31

Basic graph theoryGraph problems and algorithms

Sparse graphsAssignment 2 - Shortest path

MST algorithms

Algorithm 3: PrimInput: G , r 

begin E T  = ∅;V T  = {r };while V T  = V  do

(u , v ) = arg mine  connected to S {w e };E T  = E T  ∪ {(u , v )};V T  = V T  ∪ {{u , v } \ S };

end

end

Algorithm 4: KruskalInput: G , r 

beginE T  = ∅;sort E  according to w e ;let the ordering be e 1 , e 2 , . . . , e |E |;

for each edge  e i , i  = 1, 2, . . . , |E | doif  E T  ∪ {e i } has no cycle  then

E T  = E T  ∪ {e i };if  |E T | = |V | − 1 then

break;

endend

end

end

Tran, Van Hoai Graph algorithms

Basic graph theory

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 11/31

Basic graph theoryGraph problems and algorithms

Sparse graphsAssignment 2 - Shortest path

Parallelization of Prim’s algorithm

Algorithm 5: Prim’s algorithmInput: G , r begin

V T  = {r };d [r ] = 0;for v  ∈ V  \ V T  do

if  (r , v ) ∈ E  then d [v ] = w (r ,v );

else d [v ] = ∞;endwhile V T  = V  do

u  = arg minv ∈V \V T {d [v ]};

V T  = V T  ∪ {u };

for v  ∈ V  \ V T  dod [v ] = min{d [v ], w (u ,v )};

end

end

end

Tran, Van Hoai Graph algorithms

Basic graph theory

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 12/31

g p yGraph problems and algorithms

Sparse graphsAssignment 2 - Shortest path

Parallelization of Prim’s algorithm

Algorithm 6: Prim’s algorithmInput: G , r begin

V T  = {r };d [r ] = 0;for v  ∈ V  \ V T  do

if  (r , v ) ∈ E  then d [v ] = w (r ,v );

else d [v ] = ∞;endwhile V T  = V  do

u  = arg minv ∈V \V T {d [v ]};

V T  = V T  ∪ {u };

for v  ∈ V  \ V T  dod [v ] = min{d [v ], w (u ,v )};

end

end

end

Parallelization

Tran, Van Hoai Graph algorithms

Basic graph theory

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 13/31

Graph problems and algorithmsSparse graphs

Assignment 2 - Shortest path

Parallelization of Prim’s algorithm

Algorithm 7: Prim’s algorithmInput: G , r begin

V T  = {r };d [r ] = 0;for v  ∈ V  \ V T  do

if  (r , v ) ∈ E  then d [v ] = w (r ,v );

else d [v ] = ∞;endwhile V T  = V  do

u  = arg minv ∈V \V T {d [v ]};

V T  = V T  ∪ {u };

for v  ∈ V  \ V T  dod [v ] = min{d [v ], w (u ,v )};

end

end

end

Parallelization

Iterative method ⇒ poorscalability

Tran, Van Hoai Graph algorithms

Basic graph theory

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 14/31

Graph problems and algorithmsSparse graphs

Assignment 2 - Shortest path

Single-source shortest path

IP model

min

e ∈E w e x e s.t.

e ∈I +(s ) b se x e  = −1 s  is source

e ∈I (v ) b ve x e  = 0 ∀v  ∈ V e ∈I −(d ) b de x e  = 1 d  is destination

x e  ∈ {0, 1} ∀e ∈ E 

Tran, Van Hoai Graph algorithms

Basic graph theoryG h bl d l i h

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 15/31

Graph problems and algorithmsSparse graphs

Assignment 2 - Shortest path

Single-source shortest path

IP model

min

e ∈E w e x e s.t.

e ∈I +(s ) b se x e  = −1 s  is source

e ∈I (v ) b ve x e  = 0 ∀v  ∈ V e ∈I −(d ) b de x e  = 1 d  is destination

x e  ∈ {0, 1} ∀e ∈ E 

Dijkstra: correct if w  : E  → Z 

+

Bellman-Ford: suggested for negative-weighted graphs(except that there is no negative loop)

Tran, Van Hoai Graph algorithms

Basic graph theoryG h bl d l ith

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 16/31

Graph problems and algorithmsSparse graphs

Assignment 2 - Shortest path

All-pairs shortest path

Algorithms for single-source shortest path Use parallel single-source shortest path algorithm Partition vertices and use sequential single-source shortest

path algorithm

Tran, Van Hoai Graph algorithms

Basic graph theoryGraph problems and algorithms

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 17/31

Graph problems and algorithmsSparse graphs

Assignment 2 - Shortest path

All-pairs shortest path

Algorithms for single-source shortest path Use parallel single-source shortest path algorithm Partition vertices and use sequential single-source shortest

path algorithm

Floyd-WarshallRecurrence equation

d (k )ij 

=

w (i , j ) if k  = 0

min{d (k −1)ij 

, d (k −1)ik 

+ d (k −1)kj 

} if k ≥ 1

Algorithm 9: Floyd-WarshallInput: G begin

D (0) = A;for k  = 1 → n do

for i  = 1 → n dofor j  = 1 → n do

d (k )ij 

=

min{d (k −1)ij 

, d (k −1)ik 

+

d (k −1)kj 

};

end

end

endendTran, Van Hoai Graph algorithms

Basic graph theoryGraph problems and algorithms

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 18/31

Graph problems and algorithmsSparse graphs

Assignment 2 - Shortest path

Parallelization of Floyd-Warshall (1)

Tran, Van Hoai Graph algorithms

Basic graph theoryGraph problems and algorithms

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 19/31

Graph problems and algorithmsSparse graphs

Assignment 2 - Shortest path

Parallelization of Floyd-Warshall (2)

Tran, Van Hoai Graph algorithms

Basic graph theoryGraph problems and algorithms

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 20/31

Graph problems and algorithmsSparse graphs

Assignment 2 - Shortest path

Maximum flow problem

IP model

max

e ∈I +(s ) x e s.t. e ∈I (v ) b ve x e  = 0 ∀v  ∈ V  \ {s , d }

x e  ∈ Z  + ∀e ∈ E 

Tran, Van Hoai Graph algorithms

Basic graph theoryGraph problems and algorithms

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 21/31

p p gSparse graphs

Assignment 2 - Shortest path

Maximum flow problem

IP model

max

e ∈I +(s ) x e s.t. e ∈I (v ) b ve x e  = 0 ∀v  ∈ V  \ {s , d }

x e  ∈ Z  + ∀e ∈ E 

Tran, Van Hoai Graph algorithms

Basic graph theoryGraph problems and algorithms

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 22/31

p p gSparse graphs

Assignment 2 - Shortest path

Maximal independent set

I  ⊂ V  is called independent iff  ∀u , v  ∈ I , (u , v ) ∈ E 

Tran, Van Hoai Graph algorithms

Basic graph theoryGraph problems and algorithms

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 23/31

Sparse graphsAssignment 2 - Shortest path

Maximal independent set

I  ⊂ V  is called independent iff  ∀u , v  ∈ I , (u , v ) ∈ E 

{a, d , i , h} is an independent set

{a, c , j , f  , g } is a maximum independent set{a, d , h, f  } is a maximal independent set

Tran, Van Hoai Graph algorithms

Basic graph theoryGraph problems and algorithms

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 24/31

Sparse graphsAssignment 2 - Shortest path

Maximal independent set

I  ⊂ V  is called independent iff  ∀u , v  ∈ I , (u , v ) ∈ E 

{a, d , i , h} is an independent set

{a, c , j , f  , g } is a maximum independent set{a, d , h, f  } is a maximal independent set

IP modelmax

v ∈V  x v 

s.t. x v  +

u ∈A(v ) auv x u  = 1 ∀v  ∈ V 

x v  ∈ {0, 1} ∀v  ∈ V 

Tran, Van Hoai Graph algorithms

Basic graph theoryGraph problems and algorithms

S h

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 25/31

Sparse graphsAssignment 2 - Shortest path

Ruby’s randomized algorithm

Tran, Van Hoai Graph algorithms

Basic graph theoryGraph problems and algorithms

S h

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 26/31

Sparse graphsAssignment 2 - Shortest path

Other aspects of shortest path problem

Johnson’s algorithm: use priority queue to store labels forv  ∈ V  \ V T 

Tran, Van Hoai Graph algorithms

Basic graph theoryGraph problems and algorithms

Sparse graphs

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 27/31

Sparse graphsAssignment 2 - Shortest path

Other aspects of shortest path problem

Johnson’s algorithm: use priority queue to store labels forv  ∈ V  \ V T 

Geometric shortest path

Geometric objects implicitly encoding graph and its weights Shortest path in simple polygon

Tran, Van Hoai Graph algorithms

Basic graph theoryGraph problems and algorithms

Sparse graphs

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 28/31

Sparse graphsAssignment 2 - Shortest path

Assignment 2 - Parallel shortest path

With GNU C/C++

How to run your binary$ mpirun -np <#number of processes> program <graphfile> <source vertex> <destination vertex>

graph file: MeTiS format output: sequence of vertices on shortest path, computing

time (including data loading time)

Tran, Van Hoai Graph algorithms

Basic graph theoryGraph problems and algorithms

Sparse graphs

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 29/31

Sparse graphsAssignment 2 - Shortest path

Assignment 2 - requirements (1)

C/C++ source code

Short presentation (15 minutes): PowerPoint file Vietnamese, font size 11 Contents: (i) (algorithmic) idea, (ii) computational

experiments (1 → 4 processes) (parameter

consideration) , (iii) remarks

Tran, Van Hoai Graph algorithms

Basic graph theoryGraph problems and algorithms

Sparse graphs

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 30/31

Sparse graphsAssignment 2 - Shortest path

Assignment 2 - requirements (2)

Data: 4elt.graph (2D finite element mesh - 15,606 nodesand 45,878 edges)@http://www.cse...vn/˜hoai/download/parallel-computing/2011-2012

4elt.graph: undirected graph, unweighted We assume that weight of edges are 1

Tran, Van Hoai Graph algorithms

Basic graph theoryGraph problems and algorithms

Sparse graphs

8/3/2019 Talk Graph Algorithms

http://slidepdf.com/reader/full/talk-graph-algorithms 31/31

p g pAssignment 2 - Shortest path

Assignment 2 - requirements (2)

Data: 4elt.graph (2D finite element mesh - 15,606 nodesand 45,878 edges)@http://www.cse...vn/˜hoai/download/parallel-computing/2011-2012

4elt.graph: undirected graph, unweighted We assume that weight of edges are 1

Due date: 18 Dec, 2011

Tran, Van Hoai Graph algorithms