330 likes | 480 Views
COP 3530: Computer Science III Summer 2005 Graphs and Graph Algorithms – Part 7. Instructor : Mark Llewellyn markl@cs.ucf.edu CSB 242, 823-2790 http://www.cs.ucf.edu/courses/cop3530/summer05. School of Computer Science University of Central Florida.
E N D
COP 3530: Computer Science III Summer 2005 Graphs and Graph Algorithms – Part 7 Instructor : Mark Llewellyn markl@cs.ucf.edu CSB 242, 823-2790 http://www.cs.ucf.edu/courses/cop3530/summer05 School of Computer Science University of Central Florida
A network is an important type of graph. A network can be exemplified by a network of pipelines used to deliver water from one source to one destination. However, water is not simply pumped through one pipe, but through many pipes with different pumping stations in between. The pipes are of different diameter and the stations are of different power so that the amount of water that can be pumped may differ from one pipeline to another. v 3 6 1 t 7 3 s w 9 5 1 5 z u 2 Networks sink source
A network N consists of A weighted digraph G with nonnegative integer edge weights, where the weight of an edge e is called the capacity c(e) of e Two distinguished vertices, s and t of G, called the source and sink ortarget, respectively, such that s has no incoming edges and t has no outgoing edges. v 3 6 1 t 7 3 s w 9 5 1 5 z u 2 Networks (cont.) sink source
Note: Our definition of the source and sink vertices was chosen for intuitiveness – in the general case, the source and sink can be any two vertices. v 3 6 1 w 7 3 u t 9 5 1 5 z s 2 Networks (cont.) sink source
A flow ffor a network N is an assignment of an value f(e) to each edge e that satisfies the following properties: Capacity Rule: For each edge e, 0 f (e) c(e). (Capacity constraint: flow on an edge cannot exceed the capacity of the edge.) flow capacity v 1/3 2/6 1/1 t 3/7 3/3 s w 2/9 4/5 1/1 3/5 z u 2/2 Flow
flow capacity v 1/3 2/6 1/1 t 3/7 3/3 s w 2/9 4/5 1/1 3/5 z u 2/2 Flow • Conservation Rule: For each vertex v s, t The flow into a vertex is the same as the flow out of the vertex.
The Maximum Flow Problem • The problem is to maximize the flow so that has a maximum value for any possible function f. • This is called the maximum-flow (or max-flow) problem. • Applications • Hydraulic systems • Electrical circuits • Traffic movements • Freight transportation
v 1/3 2/6 1/1 t 3/7 3/3 s w 2/9 4/5 1/1 3/5 z u 2/2 Flow = 2 + 3 + 3 = 1 + 3 + 4 = 8 v 3/3 4/6 1/1 t 3/7 3/3 s w 2/9 4/5 1/1 3/5 z u 2/2 Maximum flow = 4 + 3 + 3 = 3 + 3 + 4 = 10 The Maximum Flow Problem (cont.)
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t(augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop A Simple Flow Algorithm The residual capacity from u to v with respect to flow f (denoted f(u,v)), is defined as: f(u,v) = c(e) – f(e). Intuitively, the residual capacity defined by a flow f is any additional capacity that f has not fully utilized in “pushing” its flow from source to sink.
Residual Graph (Gr) Flow Graph (Gf) v v /3 3 /6 6 /1 1 t t /7 7 /3 3 s s w w /9 9 /5 5 /1 1 /5 5 z z u u /2 2 A Simple Flow Algorithm (cont.)
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t(augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop Gr- unchanged Gf- changed v 3 v 0/3 6 0/6 1 0/1 t 7 t 0/7 3 0/3 s s w w 9 5 0/5 0/9 1 0/1 5 0/5 z u z u 2 0/2 A Simple Flow Algorithm - Example
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t (augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop Gr- changed Gf - unchanged v 3 v 0/3 6 0/6 1 0/1 t 7 t 0/7 3 0/3 s s w w 9 5 0/5 0/9 1 0/1 5 0/5 z u z u 2 0/2 A Simple Flow Algorithm - Example
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t (augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop Gr -unchanged Gf - changed v 3 v 0/3 6 0/6 1 0/1 t 7 t 0/7 3 0/3 s s w w 9 5 2/5 0/9 1 0/1 5 2/5 z u z u 2 2/2 A Simple Flow Algorithm - Example Minimum residual capacity on this first path is 2 (edge (u,z))
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t (augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop Gf - unchanged v 0/3 0/6 0/1 t 0/7 0/3 s w 2/5 0/9 0/1 2/5 z u 2/2 A Simple Flow Algorithm - Example Gr- changed v 3 6 1 t 7 3 s w 9 3 1 3 z u Capacity drops by 2
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t (augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop Gf - unchanged v 0/3 0/6 0/1 t 0/7 0/3 s w 2/5 0/9 0/1 2/5 z u 2/2 A Simple Flow Algorithm - Example Gr- changed v 3 6 1 t 7 3 s w 9 3 1 3 z u
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t (augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop Gf - changed v 0/3 0/6 0/1 t 0/7 3/3 s w 5/5 3/9 0/1 2/5 z u 2/2 A Simple Flow Algorithm - Example Minimum residual capacity on this first path is 3 (edge (s,w)) Gr- unchanged v 3 6 1 t 7 3 s w 9 3 1 3 z u
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t (augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop Gf - unchanged v 0/3 0/6 0/1 t 0/7 3/3 s w 5/5 3/9 0/1 2/5 z u 2/2 A Simple Flow Algorithm - Example Gr- changed v 3 6 1 t 7 s w 6 1 3 z u
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t (augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop Gf - changed v 0/3 0/6 0/1 t 0/7 3/3 s w 5/5 3/9 0/1 2/5 z u 2/2 A Simple Flow Algorithm - Example Gr- unchanged v 3 6 1 t 7 s w 6 1 3 z u
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t (augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop Gf - changed v 3/3 3/6 0/1 t 0/7 3/3 s w 5/5 3/9 0/1 2/5 z u 2/2 A Simple Flow Algorithm - Example Minimum residual capacity on this first path is 3 (edge (v,t)) Gr- unchanged v 3 6 1 t 7 s w 6 1 3 z u
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t (augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop Gf - unchanged v 3/3 3/6 0/1 t 0/7 3/3 s w 5/5 3/9 0/1 2/5 z u 2/2 A Simple Flow Algorithm - Example Gr- changed v 6 1 t 7 s w 6 1 3 z u
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t (augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop Gf - unchanged v 3/3 3/6 0/1 t 0/7 3/3 s w 5/5 3/9 0/1 2/5 z u 2/2 A Simple Flow Algorithm - Example Gr- changed v 6 1 t 7 s w 6 1 3 z u
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t (augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop Gf - changed v 3/3 3/6 0/1 t 1/7 3/3 s w 5/5 3/9 1/1 3/5 z u 2/2 A Simple Flow Algorithm - Example Minimum residual capacity on this first path is 1 (edge (u,w)) Gr- unchanged v 6 1 t 7 s w 6 1 3 z u
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t (augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop Gf - unchanged v 3/3 3/6 0/1 t 1/7 3/3 s w 5/5 3/9 1/1 3/5 z u 2/2 A Simple Flow Algorithm - Example Gr- changed v 6 1 t 7 s w 6 3 z u
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t (augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop Gf - unchanged v 3/3 3/6 0/1 t 1/7 3/3 s w 5/5 3/9 1/1 3/5 z u 2/2 A Simple Flow Algorithm - Example Gr- changed v 6 1 t 7 s w 6 3 z u
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t (augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop Gf - changed v 3/3 4/6 1/1 t 2/7 3/3 s w 5/5 3/9 1/1 3/5 z u 2/2 A Simple Flow Algorithm - Example Minimum residual capacity on this first path is 1 (edge (v,w)) Gr- unchanged v 6 1 t 7 s w 6 3 z u
Initialize all edges of the flow graph with zero flow Loop while a path in G from sto t Find a path in G from s to t (augmenting path) Add to the flow graph the minimum residual capacity from this path Reduce the residual capacity of the edges end Loop Gf - unchanged v 3/3 4/6 1/1 t 2/7 3/3 s w 5/5 3/9 1/1 3/5 z u 2/2 A Simple Flow Algorithm - Example Gr- changed v 2 t 5 s w 6 3 z u
Algorithm terminates as there are no more paths from source to sink. Gf - final v 3/3 4/6 1/1 t 2/7 3/3 s w 5/5 3/9 1/1 3/5 z u 2/2 A Simple Flow Algorithm - Example Notice thatboth the capacity constrain and the conservation constraint have been satisfied by the solution.
Gf Gr 0/2 2 v v 0/3 3 w w 0/2 2 t t s s 0/1 1 0/4 4 0/2 2 0/3 3 z z u u 0/3 2 Problem With The Simple Flow Algorithm
Gf 0/2 v 3/3 w 0/2 t s 0/1 3/4 0/2 3/3 z u 0/3 Problem With The Simple Flow Algorithm Gr 2 v w 2 t s 1 1 2 z u 2 Algorithm terminates with a suboptimal flow solution.
It turns out that flows are closely related to another concept, known as cuts. Intuitively, a cut is a division of the vertices of a flow network N into two sets, with the source on one side and the sink on the other. Formally, a cut of N is a partition X = (Vs, Vt) of the vertices of N such that s Vs and t Vt. An edge e of N with origin u Vs and destination v Vt is said to be a forward edge of cut X. An edge with origin in Vt and a destination in Vs is said to be a backward edge of cut X. Envision a cut as a separation of s and t in N done by cutting across edges of N, with forward edges going from s’s side to t’s side and backward edges going in the opposite direction. Cuts
v 3 6 1 t 7 3 s w 5 9 1 5 z u 2 Cuts (cont.) Two cuts of N, X1 on the left and X2 on the right. These cuts have only forward edges and their capacities are: c(X1) =10 and c(X2) = 21. X1 X2
v 3 6 1 t 7 3 s w 5 9 1 5 z u 2 Cuts (cont.) Cut X of N has both forward and backward edges. Example, edge(u,z) has its origin in Vt but its destination is in Vs. The capacity of X is 17. X
Given a flow f for N, the flow across cut X, denoted f(X), is equal to the sum of the flows in the forward edges of X minus the sum of the flows in the backward edges of X. That is, f(X) is the net amount of commodity that flows from the source side of X into the sink side of X. Theorem: Let N be a flow network. Given any flow f for N and any cut X of N, the value of f does not exceed the capacity of X, that is: |f| c(X) Cuts (cont.)