Graph Algorithms CptS 223 Advanced Data Structures Larry Holder - - PowerPoint PPT Presentation

graph algorithms
SMART_READER_LITE
LIVE PREVIEW

Graph Algorithms CptS 223 Advanced Data Structures Larry Holder - - PowerPoint PPT Presentation

Graph Algorithms CptS 223 Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University 1 Network Flow How much freight can flow from Seattle to Pullman? From Seattle to


slide-1
SLIDE 1

1

Graph Algorithms

CptS 223 – Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University

slide-2
SLIDE 2

Network Flow

2

How much freight can flow from Seattle to Pullman? From Seattle to Chicago? From Washington to Illinois?

slide-3
SLIDE 3

Network Flow Approach

Let the waypoints (cities, distribution centers) be

vertices in a graph

Let the routes (roads, rails, waterways, airways)

between waypoints be directed edges in the graph

Each edge has a weight representing the route’s

capacity

Choose a starting point s and an ending point t Determine the maximum rate (e.g., tons/hour) at

which we can flow freight from point s to point t

Without the freight piling up anywhere along the way

3

slide-4
SLIDE 4

Network Flow Applications

Freight flow through shipping networks Fluid flow through a network of pipes Data flow (bandwidth) through computer networks Nutrient flow through food networks Electricity flow through power distribution systems People flow through mass transportation systems Traffic flow through a city

4

slide-5
SLIDE 5

Network Flow Problem

Given

Directed graph G= (V,E) with edge capacities cv,w Source vertex s Sink vertex t

Constraints

Flow along directed edge (v,w) cannot exceed capacity cv,w At every vertex (except s and t) the total flow coming in

must equal the total flow going out

Find

Maximum amount of flow from s to t

5

slide-6
SLIDE 6

Network Flow

Example network graph (left) and its

maximum flow (right)

6

slide-7
SLIDE 7

Maximum Flow Algorithm

Flow graph Gf

Indicates the amount of flow on each edge in the network

Residual graph Gr

Indicates how much more flow can be added to each edge

in the network

Residual capacity = (capacity – current flow) Edges with zero residual capacity removed

Augmenting path

Path from s to t in Gr Edge with smallest residual capacity in the path indicates

amount by which flow can increase along path

7

slide-8
SLIDE 8

Maximum Flow Algorithm

Example

8

Network Graph Initial Flow Graph Residual Graph

Augmenting Path (s,b,d,t)

slide-9
SLIDE 9

Maximum Flow Algorithm

While an augmenting path exists in Gr

Choose one Flow increase FI = minimum residual

capacity along augmenting path

Increase flows along augmenting path in

flow graph Gf by FI

Update residual graph Gr

9

slide-10
SLIDE 10

Maximum Flow Algorithm

Example (cont.) after choosing (s,b,d,t)

10

Network Graph Flow Graph (f=2) Residual Graph

Augmenting Path (s,a,c,t)

slide-11
SLIDE 11

Maximum Flow Algorithm

Example (cont.) after choosing (s,a,c,t)

11

Network Graph Flow Graph (f=4) Residual Graph

Augmenting Path (s,a,d,t)

slide-12
SLIDE 12

Maximum Flow Algorithm

Example (cont.) after choosing (s,a,d,t)

12

Network Graph Flow Graph (f=5) Residual Graph Terminates with maximum flow f = 5.

slide-13
SLIDE 13

Maximum Flow Algorithm

Problem: Suppose we chose

augmenting path (s,a,d,t) first

13

Network Graph Flow Graph (f=3) Residual Graph Terminates with flow f = 3.

slide-14
SLIDE 14

Maximum Flow Algorithm

Solution

Indicate potential for back flow in residual graph I.e., allow another augmenting path to undo some of the

flow used by a previous augmenting path

14

Network Graph Flow Graph (f=3) Residual Graph

slide-15
SLIDE 15

Maximum Flow Algorithm

Example (cont.) after choosing (s,b,d,a,c,t)

15

Network Graph Flow Graph (f=5) Residual Graph Terminates with maximum flow f = 5.

slide-16
SLIDE 16

Maximum Flow Algorithm

Analysis

If edge capacities are rational numbers, then this

algorithm always terminates with maximum flow

If capacities are integers and maximum flow is f,

then running time is O(f · |E|)

Flow always increases by at least 1 with each

augmenting path

Augmenting path can be found in O(|E|) time using

unweighted shortest-path algorithm

Problem: Can be slow for large f

16

slide-17
SLIDE 17

Maximum Flow Algorithm

Variants

Always choose augmenting path allowing largest

increase in flow

O(|E|) calls to O(|E| log |V|) Dijkstra algorithm Running time O(|E| 2 log |V|)

Always choose the augmenting path with the

fewest edges (unweighted shortest path)

At most O(|E||V|) augmenting steps, each costing O(|E|)

for call to BFS

Running time O(|E| 2|V|)

17

slide-18
SLIDE 18

Network Flow

Variants

Multiple sources and sinks

Create super-source with infinite-capacity links to each

source

Create super-sink with infinite-capacity links from each

sink

Min-cost flow

Each edge has capacity and cost Find maximum flow with minimum cost No known fast solution

18

slide-19
SLIDE 19

Network Flow

Important algorithm with numerous

practical applications

Running time depends on method for

finding augmenting path

BFS: O(|E| 2|V|) Dijkstra: O(|E| 2 log |V|)

19