You are on page 1of 60

Networks Models

Path Exhaustion Algorithms


‫إنهاك‬
Prepared by:
Dr. Eng. Moustafa Reda A. Eltantawi

Fall 2022
Introduction
• This materials covers three network models that can
be used to solve a variety of problems
• The Maximal-Flow Technique finds the maximum
flow of any quantity or substance through a network.
• The Shortest-Route Technique can find the shortest
path through a network.

• The Chinese-Postman Problem determines a path


through a network that connects all the points while
minimizing the total distance
Network Terminology
• Large scale problems may require hundreds or thousands of iterations making efficient
computer programs a necessity

• All types of networks use a common terminology

• The points on a network are called nodes and may be represented as circles of squares

• The lines connecting the nodes are called arcs

• A network consists of a set of nodes and arcs.

• The arcs may have some flow through them.

• If flow is allowed in only one direction, the arc is a directed arc.

• If flow is allowed in both directions, the arc is an undirected arc. NetworkModel-3


Network Terminology
• “Sources” are nodes which supply a commodity ‫السلع األساسية‬

• “Sinks” are nodes which use up a commodity.

• An edge’s capacity is the maximum amount of flow which can pass through it.

• Graphs are usually directed.

• Network Flow is a subsection of graph theory related specifically to situations where


something moves from one location to another.

• An easily visualized example of network flow is piping system through which a quantity
of water must pass.
Network Terminology
• In a directed network with flow, the arc capacity is the maximum flow allowed on an arc.

• A supply node (or source node) has net flow out of the node.

• A demand node (or sink node) has net flow into the node.

• A transshipment node (or intermediate node) satisfies conservation of flow; flow in equals flow
out.
A

3 Sink
5 1 9 (Demand)
B D
7 4
Source
(Supply) 6
5 1
4 2
4
C E
NetworkModel-5
First Network Application
Maximal-Flow Technique
• The maximal-flow technique finds the maximum flow of any quantity or substance through a
network. In other words The maximal-flow technique allows us to determine the maximum
amount of a material that can flow through a network.

For example:
This technique can determine the maximum number of vehicles (cars, trucks,
etc.) that can go through a network of roads from one location to another.

• Waukesha Wisconsin is in the process of developing a road system for the downtown area

• The City Planners would like to determine the maximum number of cars that can flow
through the town from west to east

• The road network is shown in Example 1.

• The numbers by the nodes indicate the number of cars that can flow from the node
The Augmenting Path Algorithm for
the Maximum Flow Problem
1. Identify a flow augmenting path in the residual network (initially
the original network), by checking all nodes connected to the
source node with residual capacity along the arcs.
If no augmenting path exists, the current flow is optimal.
2. Identify the residual capacity c* of this augmenting path by
finding the minimum residual capacities along all arcs in the path.
Increase the flow in this path by c*.

3. Decrease the residual capacities on each arc in the path by c* (if


arc is in the opposite direction, increase its residual capacity by
c*). Go to step 1.
NetworkModel-7
Illustrative Example 2:
• What is the maximum flow from A to B?

1 4

4 2
3
5

A 3 B

3 6
2 3

1
2 5
Illustrative Example 2:
1 4

1 4 2
3
5

A 3 B

6
3 2 3

1
2 5
Illustrative Example 2:
1 4

1 3
4 2
5

A 3 B

2
2 6
2 3
3 0
1
2 5
Illustrative Example 2:
1 4

1 3
4 2
5

2 A 3 B

6
3 2
3
2
2
2 5
1
0
Illustrative Example 2:
1 4

1 3
4 2
5

2 A 3 B

3 2
6
3
2 4 0
2
0 2 5
0
1
0
Illustrative Example 2:
1 4

1 3 4 2 5

2 A 3 B

2 3
6 2
3
2 4 0
2
0 2 5
0
1
0
Illustrative Example 2:
1 4
1
2 3 4 2 5
2 0 3
2 A 1 3 B

5 3
6 2

Max
3
2 4 0
2
0 2 5
Flow 1
0

0
Exercise 01
Road network for Waukesha

Capacity in Hundreds of Cars per Hour

2 2 6 East
Point
3
1
West 1
1 2
Point 4 6
1
10
3 5
Copyright © 2012 Pearson Education 11-32
2
Exercises 02 – 03 – 04 - 05
• Find the max flow between v and w.

NetworkModel-33
Exercise 06
•Find the max flow between Source A
and Destination L.

Copyright © 2012 Pearson Education Capacity of Cars per Hour 11-34


Exercises 07 - 08
• Find the max flow between Source and Sink.

20 d
Sink b
7 5
A D 50 30 40
2 2 25
4 20 f
5 B
a 70
1 7 Source
Sink
Source 1 15
4 3 45
30 10
50
C E
4
c 30 e

Capacity in Hundreds of Cars per Hour


Second Network Application
Shortest-Path/Routing
Problem
Given a graph and a source vertex in this
graph,
Find:
shortest paths from source to all vertices in the
given graph?
Dijkstra’s Algorithm Example 01

Zero
Iteration

The Original Graph


Adjacent vertices of 0 are 1 and 7. The distance values of 1
and 7 are updated as 4 and 8. The Zero iteration gives a
subgraph shows vertices and their distance values, only the
vertices with finite distance values are shown. The vertices
included
37 in SPT are shown in green colour
Dijkstra’s Algorithm Example 01
Zero Iteration
1st Iteration

The Original Graph


Pick the vertex with minimum distance value
and not already included in SPT (not in sptSet).
The 1st Iteration picks vertex 1 which is added
to sptSet. So sptSet now becomes {0, 1}.
Update the distance values of adjacent vertices
of 1.38The distance value of vertex 2 becomes 12.
Dijkstra’s Algorithm Example 01
2nd Iteration
Zero Iteration 1st Iteration

The Original Graph

Pick the vertex with minimum distance value and not already included in
SPT (not in sptSet). The 2nd Iteration picks Vertex 7. So sptSet now
becomes {0, 1, 7}. Update the distance values of adjacent vertices of 7. The
distance
39
value of vertex 6 and 8 becomes finite (15 and 9 respectively).
Dijkstra’s Algorithm Example 01
The Original Graph Zero Iteration 2nd Iteration Successive Iterations

1st Iteration
3rd Iteration

Pick the vertex with minimum distance value and not already included in SPT (not in sptSet). The 3rd Iteration
picks Vertex 6. So sptSet now becomes {0, 1, 7, 6}. Update the distance values of adjacent vertices of 6. The
distance value of vertex 5 and 8 are updated.
We repeat the above steps until spt Set does include all vertices of given graph. Finally, we get the Shortest Path
Tree (SPT) shown above in most R.H.S. 40
Dijkstra’s Shortest-Path Algorithm
The Output
• Vertex Distance from Source
0 0
1 4
2 12
3 19
4 21
5 11
6 9
7 8
41
8 14
Dijkstra’s Algorithm Example 02
The Original Graph
2 3 2
3 1
1 1
1 4
0
4 0
1 1
5 Zero Iteration
2 5
4 3 2 3
6
3 2
1 3 2
1 1
4 1
0 4
1 0
5 1st Iteration 1
5 2nd Iteration
2 4 3
42 2 4 3
Dijkstra’s Algorithm Example 02 4th Iteration
3rd Iteration 5th Iteration
3 2 3 2 3 5
1 1 1
1 3 3 4 3 4
0 0 0
4
5 5 5
2 4 3 2 4 3 2 4 3

3 5 3 5 3 5
1
3 4 3 6 3 6
0 0 0
5 5 8
2 3 2 3 2
6 6 6
6th Iteration 7th Iteration 8th Iteration
43
Exercise 01 - 02
7 5

•Find the
A D
2 2
4 Sink

shortest
5
B
1
Source 7
1

path 4 3
C E
4

between B C D

Source
5 10
15 10 10 5
10 J

and Sink.
A 20 E
5
20 10 5
Source H Destination
5 10
5
5 5 10
K F
5
I G NetworkModel-44
Exercise 03
Suppose that we have a 'map' of the form shown below, in which the
letters A—L refer to towns that are connected by roads. If the lengths of
these roads are as marked, what is the length of the shortest path from
A to all the other towns?
Third Network Application
The Chinese Postman
Problem
In this problem, discussed by the Chinese mathematician Mei-Ku Kwan, a
postman wishes to deliver his letters, covering the least possible total distance and
returning to his starting point. He must obviously traverse each road in his route at least
once, but should avoid covering too many roads more than once.

This problem can be reformulated in terms of a weighted graph, where the graph
corresponds to the network of roads, and the weight of each edge is the length of the
corresponding road. In this reformulation, the requirement is to find a closed walk of
minimum total weight that includes each edge at least once.
The Chinese Postman Problem
The Chinese Postman Problem
If the graph is Eulerian, then any Eulerian trail
is a closed walk of the required type. Such an
Eulerian trail can be found by Fleury's algorithm.
If the graph is not Eulerian, then the
problem is much harder, although an
efficient algorithm for its solution is
known. To illustrate the ideas
involved, we look at a special case, in
which exactly two vertices have odd
degree (see the graph in R.H.S.).
The Chinese Postman Problem
Since vertices B and E are the only vertices of odd degree, we
can find a semi- Eulerian trail from B to E covering each edge
exactly once. In order to return to the starting point, covering
the least possible distance, we now find the shortest path from
E to B using the algorithm described above.
The solution of the Chinese postman
problem is then obtained by taking this
shortest path E  F  A  B, together
with the original semi-Eulerian trail,
giving a total distance of 13 + 64 = 77.
Note that, if we combine the shortest
path and the semi-Eulerian trail, we
get an Eulerian graph (see R.H.S.).
Illustrative Example
Exercise 01 - 02
Solve the Chinese
postman problem
for the weighted
graphs shown in
R.H.S.
Exercise 03 - 04
G 40 F 62 E

45

A
Solve the Chinese 35 28
80

postman problem 42

for the weighted B


38
C
70
D
G F 124 E
graphs shown in 80

90
R.H.S. starting at A.
A 170 56 160

84

76 140
B C D

You might also like