Professional Documents
Culture Documents
1 3 5
2 4
Network
• A network is a set of nodes linked by arcs.
• Associated with each network is some type of flow.
node/vertex arc/edge
1 3 5
2 4
Network
• An arc is directed if it allows flow only from one direction to the
other. An arc that is directed has an arrow head pointing to the
direction of flow.
1 3 5
2 4
Network
• If the arc allows flow to both directions, then the arc is said to be
undirected or birectional.
1 3 5
2 4
Network
• A path is a sequence of distinct arcs that join two nodes through
other nodes regardless of the directions of flow in each arc.
1 3 5
Path: 1 – 2 – 3
3–1–2–4
2 4
2–3–4–5
Network
• A path is a sequence of distinct arcs that join two nodes through
other nodes regardless of the directions of flow in each arc.
1 3 5
Path: 1 – 2 – 3
3–1–2–4
2 4
2–3–4–5
Network
• A path is a sequence of distinct arcs that join two nodes through
other nodes regardless of the directions of flow in each arc.
1 3 5
Path: 1 – 2 – 3
3–1–2–4
2 4
2–3–4–5
Network
• A path forms a cycle if it connects a node to itself through other
nodes.
1 3 5
Cycle: 1 – 2 – 3 – 1
2 4
Minimal Spanning Tree
• A tree is a connected graph which contains no cycles.
• Every pair of distinct vertices has a unique path connecting them
• The minimal spanning tree algorithm deals with linking the nodes of a
network, directly or indirectly, using the shortest length of connecting
branches.
• Two well-know algorithms are used to construct minimal spanning
trees:
• Prim’s algorithms
• Kruskal’s Algorithms
[Prim’s Algorithm
[
• Destiny Cable is in the process of providing a cable service to six new
housing development areas.
2 • Determine the most
3 5
1 4 6 economical cable
9 network.
1 10
5 3 Lengths of each arc are in
5 8 6 miles.
7
4 3
[Prim’s Algorithm
[
1. Select a starting node.
2
3 5
1 4 6
9
1 10
5 3
5 8 6
7
4 3
[Prim’s Algorithm
[
2. Find a link from this node to any other node that has the
shortest length.
2
1 3 5
4 6
9
1 10
5 3
5 8 6
7
4 3
[Prim’s Algorithm
[
3. Select the shortest link from any of the nodes that are
connected to any of the nodes that are not yet connected.
2
1 3 5
4 6
9
1 10
5 3
5 8 6
7
4 3
[Prim’s Algorithm
[
4. Repeat procedure 3 until all nodes are connected.
2
1 3 5
4 6
9
1 10
5 3
5 8 6
7
4 3
[Prim’s Algorithm
[
2
1 3 5
4 6
9
1 10
5 3
5 8 6
7
4 3
[Prim’s Algorithm
[
2
1 3 5
4 6
9
1 10
5 3
5 8 6
7
4 3
[Prim’s Algorithm
[
2
1 3 5
4 6
9
1 10
5 3
5 8 6
7
4 3
[Prim’s Algorithm
[
2
1 3 5
4 6
9
1 10
5 3
Alternate
links 5 8 6
7
4 3
[Prim’s Algorithm
[
2
1 3 5
4 6
9
1 10
5 3
5 8 6
7
4 3
[Prim’s Algorithm
[
The length of this spanning tree is 1 + 3 + 4 + 5 + 3 = 16
miles
2
1 3 5
4
1
3
5 6
4 3
[Minimal Spanning Tree Algorithm
[
Note that any minimal spanning tree requires only
number of nodes – 1 links to get all the nodes connected.
2
1 3 5
4
1
3
5 6
4 3
[Kruskal’s Algorithm
[
• Kruskal’s Algorithm is similar to Prim’s Algorithm except
that it allows adding connections even from nodes that
are not yet connected.
[Kruskal’s Algorithm
[
Delivery point
The network gives the lengths in miles of
feasible links connecting offshore natural gas 5
wellheads with an inshore delivery point. 15
20 6
closest to shore, it is equipped with 10
5
6 9 4 14
20 6
5
10
13
15
20 5
12 7
7 3
Delivery point
5
15
6 9 14
4
20 6
5
10
13
15
20 5
12 7
7 3
Delivery point
5
15
6 9 14
4
20 6
5
10
13
15
20 5
12 7
7 3
Delivery point
5
15
6 9 14
4
20 6
5
10
13
15
20 5
12 7
7 3
Delivery point
5
15
6 9 14
4
20 6
5
10
13
15
20 5
12 7
7 3
Delivery point
5
15
6 9 14
4
20 6
5
10
13
15
20 5
12 7
7 3
Delivery point
5
15
6 9 14
4
20 6
5
10
13
15
20 5
12 7
7 3
Delivery point
7 3
The Shortest-Route Model and
the Dijkstra’s Algorithm
The Shortest-Route Model
• Assuming each arc in the network has a length associated
with it.
• The problem of finding the shortest route from one node to
any other node in the network is the shortest route model.
• The shortest route model can also be modeled as a
transshipment model in which there is one source shipping
one unit of product to one destination demanding one unit
of product.
The Shortest Route Model
• The network below shows the distance (in miles) of each
feasible route between cities. Determine the shortest routes
from city a to each of the seven cities.
2
b c
2 4 1
2 3
a 4 z
d e
1 4 7
6
5
f g
The Shortest-Route Model
§ The Dijkstra’s algorithm was conceived by Dutch computer
scientist Edsger Dijkstra in 1959.
§ It is designed to determine the shortest routes between the
source node and every other node in the network.
§ Node label in Dijkstra’s algorithm are of two types: temporary
and permanent. A temporary label is modified if a shorter route
to a node can be found. At the point when no better routes can
be found, the status of the temporary label is changed to
permanent.
Dijkstra’s Algorithm
• First, let us assign L(a)=0 to the starting node a. This label is
permanent as we will not subsequently change its value
• The length of the shortest path from a to a is L(a)=0
2
b c
2 4 1
2 3
a 4 z
d e
1 4 7 6
5
f g
Dijkstra’s Algorithm
• From the node v which has most recently been given permanent
label, give temporary labels to each node u adjacent to it as follows:
2
b c
2 4 1
2 3
a 4 z
d e
L(a)=0
1 4 7 6
f 5 g
Dijkstra’s Algorithm
• LABELLING STEP: If u is unlabeled, give it an initial temporary label:
(L(u), v) where L(u) = L(v) + w(u)
(2, a)1
2
b c
2 4 1
2 3
a 4 z
d e
L(a)=0
1 4 7 6
5
(1, a)1 f g
Dijkstra’s Algorithm
• Choose a node u with the smallest temporary label and make the
label permanent.
(2, a)1
2
b c
2 4 1
2 3
a 4 z
d e
L(a)=0
1 4 7 6
5
(1, a)1 f g
Dijkstra’s Algorithm
• Again, from the node v which has been given permanent label, give
temporary labels to each node u adjacent to it as follows:
(2, a)1
2
b c
2 4 1
2 3
a 4 z
d e
L(a)=0 (5, f)2
1 4 7 6
5
(1, a)1 f g (6, f)2
Dijkstra’s Algorithm
• Choose a node u with the smallest temporary label and make the
label permanent.
(2, a)1
2
b c
2 4 1
2 3
a 4 z
d e
L(a)=0 (5, f)2
1 4 7 6
5
(1, a)1 f g (6, f)2
Dijkstra’s Algorithm
• Again, from the node v which has been given permanent label, give
temporary labels to each node u adjacent to it as follows:
(2, a)1 (4, b)3
2
b c
2 4 1
2 3
a 4 (6, b)3 z
d e
L(a)=0 (5, f)2
1 4 (4, b)3 7 6
5
(1, a)1 f g (6, f)2
Dijkstra’s Algorithm
(2, a)1 (4, b)3
2
b c
2 4 1
2 3
a 4 z
d e (6, b)3
L(a)=0 (5, f)2
1 4 (4, b)3 7 6
5
(1, a)1 f g (6, f)2
Dijkstra’s Algorithm
(2, a)1 (4, b)3
2
b c
2 4 1
2 3
a 4 z
d e (6, b)3
L(a)=0 (5, f)2
1 4 (4, b)3 7 6
5
(1, a)1 f g (6, f)2
Dijkstra’s Algorithm
(2, a)1 (4, b)3
2
b c
2 4 1
2 3
a 4 z
d e (6, b)3
L(a)=0 (5, f)2 (8, d)4
1 4 (4, b)3 7 6
5
(1, a)1 f g (6, f)2
Dijkstra’s Algorithm
(2, a)1 (4, b)3
2
b c
2 4 1
2 3
a 4 z
d e (6, b)3
L(a)=0 (5, f)2 (8, d)4
1 4 (4, b)3 7 6
5
(1, a)1 f g (6, f)2
Dijkstra’s Algorithm
(2, a)1 (4, b)3
2
b c
2 4 1
2 3
a 4 z (5, c)5
d e (6, b)3
L(a)=0 (5, f)2 (8, d)4
1 4 (4, b)3 7 6
5
(1, a)1 f g (6, f)2
Dijkstra’s Algorithm
(2, a)1 (4, b)3
2
b c
2 4 1
2 3
a 4 z (5, c)5
d e (6, b)3
L(a)=0 (5, f)2 (8, d)4
1 4 (4, b)3 7 (7, c)5 6
5
(1, a)1 f g (6, f)2
Dijkstra’s Algorithm
(2, a)1 (4, b)3
2
b c
2 4 1
2 3
a 4 z (5, c)5
d e (6, b)3
L(a)=0 (5, f)2 (8, d)4
1 4 (4, b)3 7 (7, c)5 6
5
(1, a)1 f g (6, f)2
Dijkstra’s Algorithm
(2, a)1 (4, b)3
2
b c
2 4 1
2 3
a 4 z (5, c)5
d e (6, b)3
L(a)=0 (5, f)2 (8, d)4
1 4 (4, b)3 7 (7, c)5 6
5
(1, a)1 f g (6, f)2
(11, z)6
Dijkstra’s Algorithm
(2, a)1 (4, b)3
2
b c
2 4 1
2 3
a 4 z (5, c)5
d e (6, b)3
L(a)=0 (5, f)2 (8, d)4
1 4 (4, b)3 7 (7, c)5 6
5
(1, a)1 f g (6, f)2
(11, z)6
Dijkstra’s Algorithm
(2, a)1 (4, b)3
2
b c
2 4 1
2 3
a 4 z (5, c)5
d e (6, b)3
L(a)=0 (5, f)2 (8, d)4
1 4 (4, b)3 7 (7, c)5 6
5
(1, a)1 f g (6, f)2
(11, z)6
(13, e)7
Dijkstra’s Algorithm
(2, a)1 (4, b)3
2
b c
2 4 1
2 3
a 4 z (5, c)5
d e (6, b)3
L(a)=0 (5, f)2 (8, d)4
1 4 (4, b)3 7 (7, c)5 6
5
(1, a)1 f g (6, f)2
(11, z)6
(13, e)7
Dijkstra’s Algorithm
(2, a)1 (4, b)3 Eg. from point a to e, the
2
b c shortest route is a -> b -> e
2 and the total distance to be
4 1
2 travelled is 6 miles.
10 5
1 30 5
20
30 10
2 40 3 20
Find the maximal flow from node 1 to node 5
CUT 1 = 60 CUT 3 = 70
4 20
10 5
1 30 5
20
30 10
2 40 3 20
CUT 2 = 110
Find the maximal flow from node 1 to node 5
Maximal flow: CUT 1 = 60 CUT 3 = 70
4 20
10 5
1 30 5
20
30 10
2 40 3 20
CUT 2 = 110
Ford-Fulkerson Algorithm
• Residual network – remaining arc capacities for assigning additional
flows
• Augmenting path – directed path from the source to the sink
• Residual capacities – remaining arc capacities
Ford-Fulkerson Algorithm
• Identify an augmenting path by finding some directed path from the
source to the sink in the residual network such that every arc on this
path has strictly positive residual capacity. (If no augmenting path
exists, the net flows already assigned constitute an optimal pattern.)
• Identify the residual capacity of each arc on this augmenting path by
finding the minimum of the residual capacities of the arcs on this
path. Increase the flow in this path by c.
• Decrease by c the residual capacity of each arc on this augmenting
path. Increase by c the residual capacity of each arc in the
opposite direction on this augmenting path. Return to step 1.
MAXIMAL FLOW
4 20
SOURCE 10 5
1 30 5
20
30 10
2 40 3 20
0
MAXIMAL FLOW
1. Choose the largest capacity
4 20
SOURCE 10 5
1 30 5
20
30 10
2 40 3 20
0
MAXIMAL FLOW
2. Follow its flow
4 20
SOURCE 10 5
1 30 5
20
30 10
2 40 3 20
0
MAXIMAL FLOW
3. Again, choose the largest
capacity of the next node 4 20
SOURCE 10 5
1 30 5
20
30 10
2 40 3 20
0
MAXIMAL FLOW
4. Follow its flow
4 20
SOURCE 10 5
1 30 5
20
30 10
2 40 3 20
0
MAXIMAL FLOW
5. Find the maximum allowable
flow in the augmenting path 4 20
SOURCE 10 5
1 30 5
20
30 10
2 40 3 20
0
maximum allowable flow = 20
MAXIMAL FLOW
6. Adjust the capacities based on
the maximum allowable flow 4 20
SOURCE 10 5
10
1 30 5
20
20
30 20 10
10 5
1 30 10 5
20
20
30 20 10
2 40 3 20 0
Flow (1): 1-3-5 = 20
0
MAXIMAL FLOW
4 20
10 5
1 30 10 5
20
20
30 20 10
2 40 3 20 0
Flow (1): 1-3-5 = 20
0
MAXIMAL FLOW
4 20
10 5
1 30 10 5
20
20
30 20 10
2 40 3 20 0
Flow (1): 1-3-5 = 20
0 Flow (2): 1-2-3-4-5 = 10
MAXIMAL FLOW
4 20 10
15 5
10 10
1 30 10 5
20 10
0 20
10 30 20 10 Flow (1): 1-3-5 = 20
Flow (2): 1-2-3-4-5 = 10
2 40 3 20 0
30 0
10
MAXIMAL FLOW
4 20 10
15 5
10 10
1 30 10 5
20 10
0 20
10 30 20 10 Flow (1): 1-3-5 = 20
Flow (2): 1-2-3-4-5 = 10
2 40 3 20 0
30 0
10
MAXIMAL FLOW
4 20 10
15 5
10 10
1 30 10 5
20 10
0 20
10 30 20 10 Flow (1): 1-3-5 = 20
Flow (2): 1-2-3-4-5 = 10
2 40 3 20 0 Flow (3): 1-4-5 = 10
30 0
10
MAXIMAL FLOW
10
4 20 10 0
0 15 5
10 10 20
1 30 10 5
20 10
0 20
10 30 20 10 Flow (1): 1-3-5 = 20
Flow (2): 1-2-3-4-5 = 10
2 40 3 20 0 Flow (3): 1-4-5 = 10
30 0
10
MAXIMAL FLOW
10
4 20 10 0
0 15 5
10 10 20
1 30 10 5
20 10
0 20
10 30 20 10 Flow (1): 1-3-5 = 20
Flow (2): 1-2-3-4-5 = 10
2 40 3 20 0 Flow (3): 1-4-5 = 10
30 0
10
MAXIMAL FLOW
10
4 20 10 0
0 15 5
10 10 20
1 30 10 5
20 10
0 20
10 30 20 10 Flow (1): 1-3-5 = 20
Flow (2): 1-2-3-4-5 = 10
2 40 3 20 0 Flow (3): 1-4-5 = 10
Flow (4): 1-2-5 = 10
30 0
10
MAXIMAL FLOW
10
4 20 10 0
0 15 5
10 10 20
10
1 30 10 5
20 10 0
0 20
20 20
10 30 20 10 Flow (1): 1-3-5 = 20
Flow (2): 1-2-3-4-5 = 10
2 40 3 20 0 Flow (3): 1-4-5 = 10
Flow (4): 1-2-5 = 10
30 0
10
MAXIMAL FLOW
10
4 20 10 0
0 10 5
10 10 20
10
1 30 10 5
20 10 0
0 20
20 20
10 30 20 10 Flow (1): 1-3-5 = 20
Flow (2): 1-2-3-4-5 = 10
2 40 3 20 0 Flow (3): 1-4-5 = 10
Flow (4): 1-2-5 = 10
30 0
10
MAXIMAL FLOW
10
4 20 10 0
0 10 5
10 10 20
10
1 30 10 5
20 10 0
0 20
20 20
10 30 20 10 Flow (1): 1-3-5 = 20
Flow (2): 1-2-3-4-5 = 10
2 40 3 20 0 Flow (3): 1-4-5 = 10
Flow (4): 1-2-5 = 10
30 0 Flow (5): 1-3-2-5 = 10
10
MAXIMAL FLOW
10
4 20 10 0
0 15 5
10 10 20
20
0 10
1 30 10
5
20 10 0
0 20
20 10 30
10 30 20 20 10 Flow (1): 1-3-5 = 20
Flow (2): 1-2-3-4-5 = 10
2 40 3 20 0 Flow (3): 1-4-5 = 10
Flow (4): 1-2-5 = 10
30 0 Flow (5): 1-3-2-5 = 10
40
0 10
MAXIMAL FLOW
10
No more augmenting
path. 4 20 10 0
0 15 5
10 10 20
20
0 10
1 30 10
5
20 10 0
0 20
20 10 30
10 30 20 20 10 Flow (1): 1-3-5 = 20
Flow (2): 1-2-3-4-5 = 10
2 40 3 20 0 Flow (3): 1-4-5 = 10
Flow (4): 1-2-5 = 10
30 0 Flow (5): 1-3-2-5 = 10
40
0 10