0% found this document useful (0 votes)
28 views

Network Models 00 - Maximum Flow - Shortest Path

Uploaded by

kareemkadrey02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Network Models 00 - Maximum Flow - Shortest Path

Uploaded by

kareemkadrey02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Networks Models

Path Exhaustion Algorithm

Prepared by:
Dr. Eng. Moustafa R. A. Eltantawi

Fall Semester 2019 – 2020


September – December
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 minimal-spanning tree technique determines a
path through a network that connects all the points
while minimizing the total distance
• The shortest-route technique can find the shortest
path through a network
Introduction
• 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
What is Network Flow?
• 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.
Concepts in Network Flow
• “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 Terminology
• 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-6
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)
7 4 D
B
Source
6
(Supply) 4 2 5 1
4 E
C

NetworkModel-7
Maximal-Flow Technique
Definition:
The maximal-flow technique finds the maximum
flow of any quantity or substance 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.
12-8
Maximal-Flow Technique
• The maximal-flow technique allows us to determine the maximum
amount of a material that can flow through a network
• 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-10
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-35
2
Exercise 02
Capacity in Hundreds of Cars per Hour

7 5
A D Sink
2 2
4
5
Source B 1
7
1
4 3

C E
4
Copyright © 2012 Pearson Education 11-36
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?
Copyright © 2012 Pearson Education 11-37
Algorithm for Shortest Path Problem
• Start with the source, or origin. Label it with zero
distance from origin. It is now called a solved node.
• Find the next nearest node: do this by:
• Consider all unsolved (unlabeled) nodes that are directly connected to a
solved (labelled) node – these are the candidate nodes.
• For each candidate, calculate the distance to origin by adding the branch
distance to the labelled distance.
• Find the minimum distance, and label that node with the distance and the
preceding node. This node is now called a solved node.
• Repeatuntil the destination becomes a solved node.
The shortest route can then be traced backwards. NetworkModel-38
Dijkstra’s Shortest-Path Algorithm
• Iterative algorithm
• After k iterations, know least-cost path to k nodes

• S: nodes whose least-cost path definitively known


• Initially, S = {u} where u is the source node
• Add one node to S in each iteration

• D(v): current cost of path from source to node v


• Initially, D(v) = c(u,v) for all nodes v adjacent to u
• … and D(v) = ∞ for all other nodes v
• Continually update D(v) as shorter paths are learned
39
Dijkstra’s Shortest-Path Algorithm
The algorithm
1) Create a set sptSet (shortest path tree set) that keeps track of vertices
included in shortest path tree, i.e., whose minimum distance from source is
calculated and finalized Initially, this set is empty.
2) Assign a distance value to all vertices in the input graph. Initialize all distance
values as INFINITE. Assign distance value as 0 for the source vertex so that it is
picked first.
3) While sptSet doesn’t include all vertices
….a) Pick a vertex u which is not there in sptSet and has minimum distance
value.
….b) Include u to sptSet.
….c) Update distance value of all adjacent vertices of u. To update the distance
values, iterate through all adjacent vertices. For every adjacent vertex v, if sum
of distance value of u (from source) and weight of edge u-v, is less than the
distance
40 value of v, then update the distance value of v.
Dijsktra’s Algorithm
1 Initialization:
2 S = {u}
3 for all nodes v
4 if v adjacent to u {
5 D(v) = c(u,v)
6 else D(v) = ∞
7
8 Loop
9 find w not in S with the smallest D(w)
10 add w to S
11 update D(v) for all v adjacent to w and not in S:
12 D(v) = min{D(v), D(w) + c(w,v)}
41
13 until all nodes in S
Dijkstra’s Algorithm Example 01
The set sptSet is initially empty
and distances assigned to vertices
are {0, INF, INF, INF, INF, INF,
INF, INF} where INF indicates
infinite. The Original Graph
Now pick the vertex with minimum distance
value. The vertex 0 is picked, include it in sptSet.
So sptSet becomes {0}. After including 0 to
sptSet, update distance values of its adjacent
vertices.
42
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
43 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.44The 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
45
value of vertex 6 and 8 becomes finite (15 and 9 respectively).
Dijkstra’s Algorithm Example 01
The Original Graph Zero Iteration
3rd Iteration
2nd Iteration

1st 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.
46
Dijkstra’s Algorithm Example 01
The Original Graph Zero Iteration 2nd Iteration Successive Iterations

1st Iteration
3rd Iteration

We repeat the above steps until sptSet does include all


vertices of given graph. Finally, we get the Shortest
Path Tree (SPT) shown above in most R.H.S.
47
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
48
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
49 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
50
Exercise 01
• Find the shortest path between Source and Sink.
• Idea is to start with the source, or origin, and find the shortest
path to each of the nodes in the network sequentially until the
destination is reached.
7 5
A D Sink
2 2
4
5
Source B 1
7
1
3
4

C E
4 NetworkModel-51

You might also like