Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 172 DATA STRUCTURES.

Similar presentations


Presentation on theme: "CSC 172 DATA STRUCTURES."— Presentation transcript:

1 CSC 172 DATA STRUCTURES

2 FLOW

3 FLOW “I can go with the flow.” - Queens of the Stone Age

4 “Let your body go with the flow.”
“I can go with the flow.” - Queens of the Stone Age “Let your body go with the flow.” - Madonna

5 “Let your body go with the flow.”
“I can go with the flow.” - Queens of the Stone Age “Let your body go with the flow.” - Madonna “Use the flow, Luke!” - Obi-wan Kenobi

6 FLOW NETWORKS Three categories: Distribution problems
Matching problems Cut problems

7 FLOW NETWORKS Distribution problems
-moving objects from one place to another in a network Merchandise distribution Communication Traffic flow 1 2 3 4 5 6 7 8 9

8 FLOW NETWORKS Matching problems -connecting pairs Job Placement
Minimum distance point matching 1 1 2 2 3 3 4 4 A B C D E

9 MATCHING JOB ASSINGMENTS
Abe – Adobe, Apple, HP Bea – Adobe, Apple, Yahoo Cal – HP, IBM, Sun Deb – Adobe, Apple Eli – IBM, Sun, Yahoo Fay – HP, Sun, Yahoo Adobe – Abe, Bea, Deb Apple – Abe, Bea, Deb HP – Abe, Cal, Fay IBM – Cal, Eli Sun – Cal, Eli, Fay Yahoo – Bea, Eli, Fay

10 FLOW NETWORKS Cut problems
-remove edges to break graph into two pieces Network reliability Cutting supply lines 1 1 2 2 3 3 4 4 5

11 FLOW NETWORKS (DEF) Flow Networks :

12 FLOW NETWORKS (DEF) s Flow Networks : Digraphs A B C D E t

13 FLOW NETWORKS (DEF) Flow Networks : Digraphs
Weights on edges (capacities) 2 2 1 A B 2 2 1 2 C 2 4 D E 2 1 1 t

14 FLOW NETWORKS (DEF) Flow Networks : Digraphs
source s Flow Networks : Digraphs Weights on edges (capacities) Two special verticies Source ; s Sink : t 2 2 1 A B 2 2 1 2 C 2 4 D E 1 2 1 t sink

15 CAPACITY AND FLOW Edge Capacity non-negative weights t s 2 2 1 A B 2 2
4 D E 1 2 1 1 t

16 CAPACITY AND FLOW Edge Capacity non-negative weights Flow
0 <= flow <= capacity flow in = flow out 2 2 1 2 1 A B 2 2 1 1 1 1 1 2 C 2 4 D 1 E 1 2 1 1 2 1 t

17 CAPACITY AND FLOW Edge Capacity non-negative weights Flow
value = 3 s Edge Capacity non-negative weights Flow 0 <= flow <= capacity flow in = flow out Value outflow of source inflow of sink 2 2 1 2 1 A B 2 2 1 1 1 1 1 2 C 2 4 D 1 E 1 2 1 1 2 1 t value = 3

18 RESIDUAL GRAPH Residual = capacity - flow t s 2 2 1 2 1 A B 2 2 1 1 1
value = 3 s Residual = capacity - flow 2 2 1 2 1 A B 2 2 1 1 1 1 1 2 C 2 4 D 1 E 1 2 1 1 2 1 t value = 3

19 RESIDUAL CAPACITY Residual = capacity - flow t s 2 2 1 1 1 2 1 A B 1 2
value = 3 s Residual = capacity - flow 2 2 1 1 1 2 1 A B 1 2 2 1 1 1 1 1 1 2 C 1 2 4 1 4 D 1 E 1 2 1 1 1 2 1 t value = 3

20 RESIDUAL GRAPH Residual = capacity - flow t s 1 A 1 B 1 1 1 C 1 D 4 E

21 AUGMENTATION PATH Augmentation Path
s Augmentation Path - a path from source to sink through the residual graph 1 A 1 B 1 1 1 C 1 D 4 E 1 t

22 BACKEDGE For every edge, there is a virtual reverse back edge
the capacity of a back edge is the flow of the edge 2 2 1 2 1 A B 2 2 1 1 1 1 2 1 C 2 4 D 1 E 1 2 1 1 2 1 t

23 BACKEDGE For every edge, there is a virtual reverse back edge
the capacity of a back edge is the flow of the edge (whoa!) Backedge(v,w) = flow(w,v) 2 2 2 1 1 2 1 A B 1 2 2 1 1 1 1 1 2 1 C 1 2 4 1 D 1 E 1 2 1 1 2 1 2 1 t

24 BACKEDGE GRAPH For every edge, there is a virtual reverse back edge
the capacity of a back edge is the flow of the edge (whoa!) Backedge(v,w) = flow(w,v) 2 1 A B 1 1 1 C 1 1 D E 1 2 t

25 RESIDUAL GRAPH Residual(w,v) = capacity(w,v) – flow(w,v)
Backedge(v,w) = flow(w,v) 2 1 1 A A 1 1 B B 1 1 1 1 1 C C 1 1 D D 1 4 E E 1 1 2 t t

26 Of course, in real life : There is one graph public class Edge {
int v, w ; int capacity, flow; int residual, backflow; // methods }

27 Define Capacity Graph Flow graph
residual graph (capacity – flow at each edge) back edge graph – reverse edge directions augmenting path – from s to t along non-zero capacity edges

28 Why all the complexity? Sometimes, in graph theory as in life, it turns out that greed leads us to sub-optimal results.

29 s 3 2 1 A B 3 4 2 D E 2 3 t

30 s 3 2 1 A B 3 4 2 D E 2 3 t

31 s 3 2 3 1 A B 3 4 2 3 D E 2 3 3 t

32 s 2 1 A B 3 1 2 D E 2 t

33 capacity, flow, residual, backedge
3 2 3 2 1 1 A B A B 4 3 2 3 2 4 D E D E 2 3 3 2 t t

34 capacity, flow, residual, backedge
3 2 3 2 3 1 1 A B A B 4 3 2 3 2 4 3 D E D E 2 3 3 3 2 t t

35 capacity, flow, residual, backedge
3 2 2 3 3 1 1 A B A B 1 3 2 3 2 4 3 3 D E D E 2 3 3 2 3 t t

36 capacity, flow, residual, backedge
3 2 2 3 3 1 1 A B A B 1 3 2 3 2 4 3 3 D E D E 2 3 3 2 3 t t

37 capacity, flow, residual, backedge
3 2 2 3 2 3 1 1 A B A B 1 3 2 2 2 3 2 4 1 3 D E D E 2 3 2 3 2 3 t t

38 capacity, flow, residual, backedge
3 2 3 2 3 1 2 1 A B A B 3 3 2 2 2 3 2 2 4 1 1 D E D E 2 3 2 2 3 3 t t

39 capacity, flow, residual, backedge
3 2 3 2 3 1 2 1 A B A B 3 3 2 2 2 3 2 2 4 1 1 D E D E 2 3 2 2 3 3 t t


Download ppt "CSC 172 DATA STRUCTURES."

Similar presentations


Ads by Google