Title: Announcements
1Announcements
- Network Flow today, depending on how far we get,
we will do String Matching on Wednesday - Then Review for Final next Monday
- This weeks lab will be review of Network Flow
and other material.
2Network Flow
- The Maximum Flow Problem
- and
- The Ford-Fulkerson Algorithm
3Types of Networks
- Internet
- Telephone
- Cell
- Highways
- Rail
- Electrical Power
- Water
- Sewer
- Gas
-
4Maximum Flow Problem
- How can we maximize the flow in a network from a
source or set of sources to a destination of set
of destinations? - The problem reportedly rose to prominence in
relation to the rail networks of the Soviet
Union, during the 1950's. The US wanted to know
how quickly the Soviet Union could get supplies
through its rail network to its satellite states
in Eastern Europe. - In addition, the US wanted to know which rails it
could destroy most easily to cut off the
satellite states from the rest of the Soviet
Union. - It turned out that these two problems were
closely related, and that solving the max flow
problem also solves the min cut problem of
figuring out the cheapest way to cut off the
Soviet Union from its satellites. - The first efficient algorithm for finding the
maximum flow was conceived by two Computer
Scientists, named Ford and Fulkerson. The
algorithm was subsequently named the
Ford-Fulkerson algorithm, and is one of the more
famous algorithms in computer science.
Source lbackstrom, The Importance of
Algorithms, at www.topcoder.com
5Network Flow
- A Network is a directed graph G
- Edges represent pipes that carry flow
- Each edge ltu,vgt has a maximum capacity cltu,vgt
- A source node s in which flow arrives
- A sink node t out which flow leaves
Goal Max Flow
6Network Flow
- The network flow problem is as follows
- Given a connected directed graph G
- with non-negative integer weights,
- (where each edge stands for the capacity of that
edge), - 2 different vertices, s and t, called the source
and the sink, - such that the source only has out-edges and the
sink only has in-edges, - Find the maximum amount of some commodity that
can flow through the network from source to sink.
12
a
b
20
16
9
4
10
7
s
t
4
c
d
14
Each edge stands for the capacity of that edge.
7Network Flow
- One way to imagine the situation is imagining
each edge as a pipe that allows a certain flow of
a liquid per second. - The source is where the liquid is pouring from,
and the sink is where it ends up. - Each edge weight specifies the maximal amount of
liquid that can flow through that pipe per
second. - Given that information, what is the most liquid
that can flow from source to sink per second, in
the steady state?
12
a
b
20
16
9
4
10
7
s
t
4
c
d
14
Each edge stands for the capacity of that edge.
8Network Flow
12
a
b
12/12
a
b
20
16
19/20
12/16
0/9
9
4
10
7
s
t
0/4
0/10
s
t
7/7
13
4
4/4
11/13
c
d
c
d
14
11/14
This graph contains the capacities of each edge
in the graph.
Here is an example of a flow in the graph.
- The flow of the network is defined as the flow
from the source, or into the sink. - For the situation above, the network flow is 23.
912
12/12
a
b
a
b
20
19/20
16
12/16
0/9
9
4
0/4
10
7
0/10
s
t
s
t
7/7
13
4
4/4
11/13
c
d
c
d
14
11/14
capacities
flow
- The Conservation Rule
- In order for the assignment of flows to be valid,
we must have the sum of flow coming into a vertex
equal to the flow coming out of a vertex, for
each vertex in the graph except the source and
the sink. - The Capacity Rule
- Also, each flow must be less than or equal to the
capacity of the edge. - The flow of the network is defined as the flow
from the source, or into the sink. - For the situation above, the network flow is 23.
10Network Flow
- In order to determine the maximum flow of a
network, we will use the following terms - Residual capacity is simply an edges unused
capacity. - Initially none of the capacities will have been
used, so all of the residual capacities will be
just the original capacity.
0/12
a
b
0/20
0/16
Using the notation used / capacity. Residual
Capacity capacity - used.
0/9
0/4
0/10
s
t
0/7
0/4
0/13
c
d
0/14
11Network Flow
- Residual capacity of a path the minimum of the
residual capacities of the edges on that path,
which will end up being the max excess flow we
can push down that path. - Augmenting path defined as one where you have a
path from the source to the sink where every edge
has a non-zero residual capacity.
0/12
a
b
0/20
0/16
Using the notation used / unused. Residual
Capacity unused - used.
0/9
0/4
0/10
s
t
0/7
0/4
0/13
c
d
0/14
12Ford-Fulkerson Algorithm
- While there exists an augmenting path
- Add the appropriate flow to that augmenting path
- So were going to arbitrarily choose an the
augmenting path s,c,d,t in the graph below - And add the flow to that path.
- Residual capacity of a path the minimum of the
residual capacities of the edges on that path.
0/12
a
b
0/20
0/16
0/9
- 4 in this case, which is the limiting factor for
this paths flow.
0/4
0/10
s
t
0/7
4/4
0/4
4/13
0/13
c
d
4/14
0/14
13Ford-Fulkerson Algorithm
- While there exists an augmenting path
- Add the appropriate flow to that augmenting path
- Choose another augmenting path (one where you
have a path from the source to the sink where
every edge has a non-zero residual capacity.) - s,a,b,t
- Residual capacity of a path the minimum of the
residual capacities of the edges on that path.
12/12
0/12
a
b
12/20
0/20
12/16
0/16
0/9
- 12 in this case, which is the limiting factor for
this paths flow.
0/4
0/10
s
t
0/7
4/4
4/13
c
d
4/14
14Ford-Fulkerson Algorithm
- While there exists an augmenting path
- Add the appropriate flow to that augmenting path
- Choose another augmenting path (one where you
have a path from the source to the sink where
every edge has a non-zero residual capacity.) - s,c, d, b, t
- Residual capacity of a path the minimum of the
residual capacities of the edges on that path.
12/12
a
b
12/20
12/16
19/20
0/9
- 7 in this case, which is the limiting factor for
this paths flow.
0/4
0/10
s
t
0/7
7/7
4/4
4/13
11/13
c
d
4/14
11/14
15Ford-Fulkerson Algorithm
- While there exists an augmenting path
- Add the appropriate flow to that augmenting path
- Are there any more augmenting paths?
- No! Were done
- The maximum flow 19 4 23
12/12
a
b
19/20
12/16
0/9
0/4
0/10
s
t
7/7
4/4
11/13
c
d
11/14
16Network Flow
- Another example of the Ford Fulkerson Algorithm
on the board
17Cuts of Flow Networks
18The Net Flow through a Cut (S,T)
19The Capacity of a Cut (S,T)
20Network Flow
- Value of the cut, example on the board
21Augmenting Paths example
- The maximum possible flow through the cut 12
7 4 23
Flow(2)
cut
The network has a capacity of at most 23. This
is called a minimum cut.
22Net Flow of a Network
- The net flow across any cut is the same and equal
to the flow of the network f.
23Bounding the Network Flow
- The value of any flow f in a flow network G is
bounded from above by the capacity of any cut of
G.
24Max-Flow Min-Cut Theorem
- If f is a flow in a flow network G(V,E), with
source s and sink t, then the following
conditions are equivalent - f is a maximum flow in G.
- The residual network Gf contains no augmented
paths. - f f(S,T) for some cut (S,T) (a min-cut).
25Example
- In a department there are n courses and m
instructors. - Every instructor has a list of courses he or she
can teach. - Every instructor can teach at most 3 courses
during a year. - The goal find an allocation of courses to the
instructors subject to these constraints.
26Network Flow Optional Homework Problem
- An orchestra is trying to fill all of its
positions. For different instruments, it needs a
different number of players. - For example, it might need 20 violinists but only
3 trumpet players. - Each potential candidate for the orchestra can
play some set of instruments. - For example, one player might be able to play
either a violin or a viola, while another might
be able to play a trumpet, trombone or tuba. - Given the following information
- A list of how many of each position the orchestra
needs. - A list of each candidate and which instruments
they can play. - Determine whether or not the orchestra can fill
all its positions. - Describe how to solve this problem using network
flow.
27References
- Slides adapted from Arup Guhas Computer Science
II Lecture notes http//www.cs.ucf.edu/dmarino/
ucf/cop3503/lectures/ - Additional material from the textbook
- Data Structures and Algorithm Analysis in Java
(Second Edition) by Mark Allen Weiss - J Elders Network Flow slides, York University