Algo VC Lecture-21
Algo VC Lecture-21
1
Recap
An example:
Waukesha is in the process of developing a road
system for down town.
3 City planners would like to determine the maximum
Road Network forWaukesha
Iteration 1
Add 2
2
1 2
2
3
Subtract 2 6 East
West 1 0
Point
3 2
Point 2006 by
4
Prentice
6 Hall, East
1 New path Inc.
West 1
Point
Upper Saddle
Point River, NJ 07458
Solving the Waukesha Example
The New Path reflects the new relative capacity at this
stage.
The flow number by any node represents two factors.
One factor is the flow that can come from that node.
The second factor is flow that can be reduced coming int
the node.
3 0
2
The number 1 by node 1 indicates that 100 cars can flow
from node 1 to node 2. 4
6 East
1 New path
West Point
1
Point
8
Solving the Waukesha Example
The number 0 by node 2 on the path from node 2 to no
6 indicates that 0 cars can flow from node 2 to node 6.
3 2
0
4
6 East
1
West 1 New path
Point
Point
The number 4 by node 6, on the path from node 6 to n
2, indicates that
we can reduce the flow into node 6 by 2 (or 200 cars) an
9 that there is
Solving the Waukesha Example
On the path from node 2 to node 1, the number 3 by
node 2 shows that we can reduce the flow into node 2 b
2 (or 200 cars) and that there is a capacity of 1 (or 100
cars) from node 2 to node 1
3 2
0
4
6 East
1 New path
West 1
Point
Point
At this stage, there is a flow of 200 cars through the
network from node 1
10
to node 2 to node 6.
Repeat the Process
Add 1
3 2
1 1 6
1 1
1
1
4
Subtract 1
Old Path
12
3 2 Add 1
1 1 6
1 1
1
Second Iteration for Waukesha
4
1
0 Subtract 1
4 2
Old Path
0
4
2 6 East
0
West 2
0 Point
1 0 2 0
Point 10
1
4
6
5
0 3 1
3 2
New Network
13
Continuing the Process
14
Third Iteration
0
4 2
0
4
2 6 East
0
West 2
0 Point
1 0 2 0
Point 10
1
4
Subtract 2
6
5
0 3 12006 by
3 2
Add 2
Prentice Hall,
Inc.
Upper Saddle
River, NJ 07458
Continuing the Process
16
Final Iteration
4 2
0 New Path
0
4
2 6 East
0
West 2
2 Point
1 0 2 0
Point 10
1
4
4
2006
5 by
0 3 Prentice
3 Hall,
3 0 Inc.
Path = 1, 3, 5, 6
Upper Saddle
River, NJ 07458
Final Network Flow
The maximum flow of 500 cars per hour is
summarized in the
(Carsfollowing
per Hour) table:
PATH FLOW
1-2-6 200 4 20
1-2-4-6 100 0
4
1-3-5-6 200 2 6 East
0 2
Total =500 Point
West 12 020
10 4
Point 1
4
5
0 3 3
30
18
The Shortest-Route Technique
19
Example: From Rays Plant to
Warehouse
For example,
Every day, Ray Design, Inc., must transport beds,
chairs, and other furniture items from the factory to
the warehouse.
This involves going through several cities.
Ray would like to find the route with the shortest
distance.
20
Shortest-Route Technique (continued)
Plant 2
200 4
1 50 150 6
3 52006 by
40
Prentice Hall,
Warehouse
Inc.
Upper Saddle
River, NJ 07458
Steps of the Shortest-Route
Technique
1. Find the nearest node to the origin (plant). Put
the distance in a box by the node.
2. Find the next-nearest node to the origin (plant),
and put the distance in a box by the node. In
some cases, several paths will have to be
checked to find the nearest node.
3. Repeat this process until you have gone
2006 by
through
the entire network. Prentice Hall,
Inc.
The last distance at the ending Upper Saddle
node will be the
distance of the shortestRiver,
route.NJ 07458
Shortest-Route Technique
(continued)
Ray Design: 1st Iteration
100
Plant 2
200 4
1 50 150 6
3 5
40
2006 by
Warehouse
Prentice Hall,
The nearest node to the plantInc.
is node 2, with
a distance of 100 miles. Upper Saddle
Thus, connect these two nodes.
River, NJ 07458
Shortest Route Technique
(continued)
Ray Design: 2nd Iteration
100
2
200 4
1 50 150 6
3 5
40 2006 by
150
Prentice Hall,
The nearest node to the plantInc.
is node 3, with
a distance of 50 miles. Upper Saddle
River, NJ 07458
Thus, connect these two nodes.
Shortest-Route Technique
(continued)
Ray Design: 3rd Iteration
100
2
200 4
1 50 150 6
3 5
40 2006 by
150 190
Prentice Hall,
The nearest node to the plant Inc.
is node 5, with
a distance of 40 miles. Upper Saddle
Thus, connect these two nodes.River, NJ 07458
Shortest Route Technique
(continued)
4th and Final Iteration
290
100
2
200 4
1 50 150 6
2006 by
3 5
40 Prentice Hall,
150 190
Inc.
Total Shortest Route = Upper Saddle
100 + 50 + 40 + 100 = 290 miles. River, NJ 07458
Minimum Connector Algorithms(Prims algorithm)
)
27
Example
3
4
8 6
8
Avonford Fingley Donster
7
5
4
2
28
Edan
We model the situation as a network, then
the problem is to find the minimum
connector for the network
5
B C
3
4
8 6
8
A F D
7
5
4
2
29
Prims Algorithm
B 5
C
Select any vertex
3
4
8 6 A
E
30
Prims Algorithm
B 5
C
3 Select the
6
4 shortest
8
edge connected
8 to
A D any vertex
7 F
already
5 connected.
4
2
AE 4
E
31
Prims Algorithm
B 5
C
3
4
8 6
Select the
8 shortest
A D edge connected
7 F
to
5 any vertex
4
2
already
connected.
E ED 2
32
Prims Algorithm
B 5
C
3 Select the
6
4 shortest
8
edge connected
8 to
A D any vertex
7 F
already
5 connected.
4
2
DC 4
E
33
Prims Algorithm
B 5
C
3 Select the
4
8 6 shortest
edge connected
8
A to
F D
7 any vertex
5
already
4 connected.
2
EF 5
E
34
Prims Algorithm
B 5
C All vertices have been
connected.
3
4
8 6 The solution is
8 AB 3
A D AE 4
7 F
ED 2
DC 4
5
EF 5
4
2
36
Analysis of Prim's Algorithm
37
Summary
39