Network Flow Problem
Network Flow Problem
SANTHINI PAUL
1
INTRODUCTION
Network Nodes telephone exchanges, computers, satellites gates, registers, processors joints reservoirs, pumping stations, lakes stocks, companies Arcs cables, fiber optics, microwave relays wires rods, beams, springs pipelines transactions Flow voice, video, packets current heat, energy fluid, oil money freight, vehicles, passengers energy
2
communication
circuits mechanical hydraulic financial transportation chemical
Flow Graph
A common scenario is to use a graph to represent a flow network and use it to answer questions about material flows Flow is the rate that material moves through the network Each directed edge is a conduit for the material with some stated capacity Vertices are connection points but do not collect material
Flow into a vertex must equal the flow leaving the vertex, flow conservation
Representation
Flow network: directed graph G=(V,E)
v1 v3
v1
v3
v2
v4
source
v2
v4
sink
Sink vertex t
where material is consumed
Flow concepts
A flow network G=(V,E): a directed graph, where each edge (u,v)E has a nonnegative capacity c(u,v)>=0. If (u,v)E, we assume that c(u,v)=0. two distinct vertices :a source s and a sink t.
A flow in G: a real-valued function f:V*V R satisfying the following two properties: Capacity constraint: For all u,v V, we require f(u,v) c( u,v). Flow conservation: For all u V-{s,t}, we require
Contd..
f (e) f (e)
e.in .v e.out .v The quantity f (u,v) is called the net flow from vertex u to vertex v. The value of a flow is defined as
f f ( s, v )
vV
The total flow from source to any other vertices. The same as the total flow from any vertices to the sink.
Example of flow
Lucky puck company
Residual networks
Given a flow network and a flow, the residual network consists of edges that can admit more net flow. G=(V,E) --a flow network with source s and sink t f: a flow in G. The amount of additional net flow from u to v before exceeding the capacity c(u,v) is the residual capacity of (u,v), given by: cf(u,v)=c(u,v)-f(u,v) in the other direction: cf(v, u)=c(v, u)+f(u, v).
10
Given a flow network G=(V,E) and a flow f, an augmenting path is a simple path from s to t in the residual network Gf. Residual capacity of p : the maximum amount of net flow that we can ship along the edges of an augmenting path p, i.e., cf(p)=min{cf(u,v):(u,v) is on p}.
3 2 1
PROCEDURE
Start with our graph, G, and construct a flow graph Gf. Gf tells the flow that has been attained at any stage in the algorithm. Initially all edges in Gf have no flow. Construct a graph, Gr, called the residual graph. Gr tells, for each edge, how much more flow can be added. We can calculate this by subtracting the current flow from the capacity for each edge. An edge in Gr is known as a residual edge
13
Contd..
At each stage, we find a path in Gr from s to t. This path is known as an augmenting path. The minimum edge on this path is the amount of flow that can be added to every edge on the path. We do this by adjusting Gf and recomputing Gr. When we find no path from s to t in Gr, we terminate
14
Example:
15
Suppose we select s, b, d, t.
17
The only path left to select is s, a, d, t, which allows one unit of flow. The resulting graphs are:
The algorithm terminates at this point, because t is unreachable from s. The resulting flow of 5 happens to be the maximum.
18
G, Gf, Gr if initial action is to add three units of flow along s, a, d, t -algorithm terminates with suboptimal solution
20
In order to make this algorithm work, we need to allow the algorithm to change its mind. To do this, for every edge (v, w) with flow fv,w in the flow graph, we will add an edge in the residual graph (w, v) of capacity fv,w. In effect, we are allowing the algorithm to undo its decisions by sending flow back in the opposite direction. This is best seen by example.
21
Graphs after three units of flow added along s, a, d, t using correct algorithm
22
Notice that in the residual graph, there are edges in both directions between a and d. Either one more unit of flow can be pushed from a to d, or up to three units can be pushed back -- we can undo flow. Now the algorithm finds the augmenting path s, b, d, a, c, t, of flow 2. By pushing two units of flow from d to a, the algorithm takes two units of flow away from the edge (a, d) and is essentially changing its mind.
23
Graphs after two units of flow added along s, b, d, a, c, t using correct algorithm There is no augmenting path in this graph, so the algorithm terminates. Surprisingly, it can be shown that if the edge capacities are rational numbers, this algorithm always terminates with a maximum flow.
24
The maximum flow is seen by inspection to be 2,000,000 by sending 1,000,000 down each side. Random augmentations could continually augment along a path that includes the edge connected by a and b. If this were to occur repeatedly, 2,000,000 augmentations would be required, when we could get by with only 2.
25
If the capacities are all integers and the maximum flow is f, then, since each augmenting path increases the flow value by at least 1, f stages suffice, and the total running time is O(f|E|), since an augmenting path can be found in O(|E|) time by an unweighted shortest-path algorithm. This is a bad running time as the previous example shows.
26
A simple method to get around this problem is always to choose the augmenting path that allows the largest increase in flow. If capmax is the maximum edge capacity, then O(|E| log capmax) augmentations will suffice to find the maximum flow. In this case, since O(|E| log |V|) time is used for each calculation of an augmenting path, a total bound of O(|E|2 log |V| log capmax) is obtained. If the capacities are all small integers, this reduces to O(|E|2 log |V|).
27
Another way to choose augmenting paths is always to take the path with the least number of edges, with the plausible expectation that by choosing a path in this manner, it is less likely that a small, flow-restricting edge will turn up on the path. Using this rule, O(|E| |V|) augmenting steps are required. Each step takes O(|E|), again using an unweighted shortest-path algorithm, yielding a O(|E|2|V|) bound on the running time.
28
Thank You
29