math1800 lec8 bb
TRANSCRIPT
-
7/27/2019 Math1800 Lec8 Bb
1/35
MATH1800Mathematical Modelling
School of Mathematical and Physical Sciences,Faculty of Science and Information Technology,
University of Newcastle, Australia
Semester 2
Lec 8 Recap
What is the difference between a graph and digraph (i.e. network)?
What are three different ways of characterizing a tree?
What is a subgraph?
What is a spanning tree?
What is a minimum spanning tree (MST)?
How does Prims algorithm work?
What is a cut?
What is a cut induced by an edge of a spanning tree?What does the interchangeable property (i.e. Property 2) tell us aboutspanning trees?
What is the cut optimality condition for MST?
How can the cut optimality condition be used to prove that Prims
algorithm constructs an MST?
-
7/27/2019 Math1800 Lec8 Bb
2/35
Lec 8 Recap
What is the difference between a graph and digraph (i.e. network)?
What are three different ways of characterizing a tree?
What is a subgraph?
What is a spanning tree?
What is a minimum spanning tree (MST)?
How does Prims algorithm work?
What is a cut?
What is a cut induced by an edge of a spanning tree?
What does the interchangeable property (i.e. Property 2) tell us aboutspanning trees?
What is the cut optimality condition for MST?
How can the cut optimality condition be used to prove that Prims
algorithm constructs an MST?
Lec 8 Network Models: Shortest Paths in Directed Graphs (Networks)
The Shortest Path Problem
Given a directed graph with nodes N, and arcs A, find theshortest path from a node sto a node twith respect to arclength/cost cij.
Example: Find the shortest path from node 1to node 5(i.e. s=1, t=5)
1
2 3
4 5
1
1
2 2
5
9
8
Shortest path is (1, 2, 3, 5)with cost 8. (why?)
-
7/27/2019 Math1800 Lec8 Bb
3/35
Lec 8 Network Models: Shortest Paths in Directed Graphs (Networks)
The Shortest Path Problem
Given a directed graph with nodes N, and arcs A, find theshortest path from a node sto a node twith respect to arclength/cost cij.
Example: Find the shortest path from node 1to node 5(i.e. s=1, t=5)
1
2 3
4 5
1
1
2 2
5
9
8
Shortest path is (1, 2, 3, 5)with cost 8. (why?)
Enumeration:
Path 1: (1,2,3,5)with cost 8
Path 2: (1,2,5)with cost 9
Path 3: (1,2,4,5)with cost 12
Path 4: (1,4,5)with cost 10
Lec 8 Network Models: Shortest Paths in Directed Graphs (Networks)
The Shortest Path Problem
Given a directed graph with nodes N, and arcs A, find theshortest path from a node sto a node twith respect to arclength/cost cij.
Example: Find the shortest path from node 1to node 5(i.e. s=1, t=5)
1
2 3
4 5
1
1
2 2
5
9
8
Shortest path is (1, 2, 3, 5)with cost 8. (why?)
Enumeration:
Path 1: (1,2,3,5)with cost 8
Path 2: (1,2,5)with cost 9 Path 3: (1,2,4,5)with cost 12
Path 4: (1,4,5)with cost 10
Logical deduction:
The shortest path must use one of the arcs (4,5), (2,5),and (3,5). The cost of any path using arcs (2,5), or (4,5)is at least 9. The only path that does not use arcs (4,5)and (2,5)is the path (1, 2, 3, 5)with cost 8andtherefore optimal.
-
7/27/2019 Math1800 Lec8 Bb
4/35
Lec 8 Network Models: Shortest Paths in Directed Graphs (Networks)
The Shortest Path Problem
Given a directed graph with nodes N, and arcs A, find theshortest path from a node sto a node twith respect to arclength/cost cij.
Q. What about shortest paths in larger networks?
Lec 8 Network Models: Shortest Paths in Directed Graphs (Networks)
The Shortest Path Problem
Given a directed graph with nodes N, and arcs A, find theshortest path from a node sto a node twith respect to arclength/cost cij.
Q. What about shortest paths in larger networks?
No. of nodes
(n)
Max no. of arcs(n2)
Max no. of paths between a pair of nodes(n!)
10 100 3628800
20 400 2432902008176640000
50 2,500 30414093201713378043612608166065(32 more digits)
100 10,000 93326215443944152681699238856267(126 more digits)
: : :
1000 1,000,000 402387260077093773543702433923(2,538 more digits)
-
7/27/2019 Math1800 Lec8 Bb
5/35
Lec 8 Network Models: Applications of Shortest Paths
Transportat ion/Communicat ion networks (Logist ics, GPS, Google maps,internet routing , etc.)
Find the shortest (either time or distance) path from origin to destination
Lec 8 Network Models: Applications of Shortest Paths
Capital Replacement Strategy
Each year a company car costs more to run and maintain, and depreciates invalue (see below). Projected new car prices are also given below.
If the company requires a car for 5 years, what is the optimal strategy?
Age of car Annual cost Trade-in Value
1 $1,000 $12,000
2 $2,000 $10,000
3 $5,000 $6,000
4 $9,000 $5,000
5 $12,000 $3,000
Start of Year Price
1 $19,000
2 $18,500
3 $18,000
4 $18,000
5 $17,000
-
7/27/2019 Math1800 Lec8 Bb
6/35
Lec 8 Network Models: Applications of Shortest Paths
Capital Replacement Strategy
Each year a company car costs more to run and maintain, and depreciates in
value (see below). Projected new car prices are also given below.
If the company requires a car for 5 years, what is the optimal strategy?
Age of car Annual cost Trade-in Value
1 $1,000 $12,000
2 $2,000 $10,000
3 $5,000 $6,000
4 $9,000 $5,000
5 $12,000 $3,000
Start of Year Price
1 $19,000
2 $18,500
3 $18,000
4 $18,000
5 $17,000
A network model:
inode Start of year i
iarc Buy a car at the start of year i and drive until start of year j (i < j)j
ilength Cost of buying a car at the start of year i+cost ofj-iyears of maintenancetrade-in value of (j-i)year-old car
jcij
Lec 8 Network Models: Applications of Shortest Paths
Capital Replacement Strategy
Each year a company car costs more to run and maintain, and depreciates invalue (see below). Projected new car prices are also given below.
If the company requires a car for 5 years, what is the optimal strategy?
Age of car Annual cost Trade-in Value
1 $1,000 $12,000
2 $2,000 $10,000
3 $5,000 $6,000
4 $9,000 $5,000
5 $12,000 $3,000
Start of Year Price
1 $19,000
2 $18,500
3 $18,000
4 $18,000
5 $17,000
1 2 3 4 5
19+1+2+5-6 =21
6
19+1+2-10 =12
19+1-12 =8 18.5+1-12 =7.5 18+1-12 =7
18.5+1+2-10 =11.5
Optimal strategy: shortestpath from node 1 to node 6.
Exercise: complete network and find shortest path.
-
7/27/2019 Math1800 Lec8 Bb
7/35
Lec 8 Network Models: Applications of Shortest Paths
Very L arge Scale Integration (VLSI) circuit desig n
When designing VLSI circuits, need to isolate negative feedback loops. These
negative feedback loops correspond to negative cost cycles in the amplifier-gainnetwork of the circuit.
Lec 8 Network Models: Applications of Shortest Paths
Robot ic Surgery
Planning shortest paths through patientsanatomy and avoid obstacles
-
7/27/2019 Math1800 Lec8 Bb
8/35
Lec 8 Network Models: Applications of Shortest Paths
Image Segmentation
Find a line in an image that separates distinguishable objects of interest, i.e. line
that cuts through the fewest number of black pixels. This grid of pixels can bemodelled as a graph, with any edge across a black pixel given a high cost. Theshortest path defines the best separation.
Lec 8 Network Models: Shortest Path Algorithms
DijkstrasAlgori thm fo r Short est Paths (1956)
Given network with nodes Nand arcs A, find shortestpath from node sto node t.
1. Assign a distance label di, and a predecessor labelpito each node. Set dito infinity for all nodesexcept s. Set dsto 0. Mark all nodes as unlabelled.
2. Pick an unlabellednode iwith the minimumdistance label dito explore.
3. Update distance and predecessor labels forneighbouring nodes of i: for all nodesjs.t. (i,j)is anarc if dj> di + cijthen set djto di + cijand set pjto i.
4. Mark ias labelled.
5. Repeat second step until all nodes are labelled.
ditracks the distance of the shortest path found so far from sto node i.
pitracks the node that precedes ion the shortest path found so far from sto i.
-
7/27/2019 Math1800 Lec8 Bb
9/35
Lec 8 Network Models: Shortest Path Algorithms
DijkstrasAlgori thm fo r Short est Paths (1956)
Given network with nodes Nand arcs A, find shortestpath from node sto node t.
1. Assign a distance label di, and a predecessor labelpito each node. Set dito infinity for all nodesexcept s. Set dsto 0. Mark all nodes as unlabelled.
2. Pick an unlabellednode iwith the minimumdistance label dito explore.
3. Update distance and predecessor labels forneighbouring nodes of i: for all nodesjs.t. (i,j)is anarc if dj> di + cijthen set djtodi + cijand set pjto i.
4. Mark ias labelled.
5. Repeat second step until all nodes are labelled.
ditracks the distance of the shortest path found so far from sto node i.
pitracks the node that precedes ion the shortest path found so far from sto i.
Lec 8 Network Models: Shortest Path Algorithms
DijkstrasAlgori thm fo r Short est Paths (1956)
Given network with nodes Nand arcs A, find shortestpath from node sto node t.
1. Assign a distance label di, and a predecessor labelpito each node. Set dito infinity for all nodesexcept s. Set dsto 0. Mark all nodes as unlabelled.
2. Pick an unlabellednode iwith the minimumdistance label dito explore.
3. Update distance and predecessor labels forneighbouring nodes of i: for all nodesjs.t. (i,j)is anarc if dj> di + cijthen set djtodi + cijand set pjto i.
4. Mark ias labelled.
5. Repeat second step until all nodes are labelled.
ditracks the distance of the shortest path found so far from sto node i.
pitracks the node that precedes ion the shortest path found so far from sto i.
-
7/27/2019 Math1800 Lec8 Bb
10/35 1
Lec 8 Network Models: Shortest Path Algorithms
1
2 3
4 5
1
1
2 2
5
9
8
Find the shortest path from node 1 to node 5.
Lec 8 Network Models: Shortest Path Algorithms
1
2 3
4 5
1
1
2 2
5
9
8
Node
1 2 3 4 5
(0,-) (,-) (,-) (,-) (,-)
Find the shortest path from node 1 to node 5.
Step 1.Initialise distance and predecessor labels
Distance and predecessor label (di,pi) for node i
Unlabelled nodes
Labelled nodes
Node we are currently exploring
-
7/27/2019 Math1800 Lec8 Bb
11/35
Lec 8 Network Models: Shortest Path Algorithms
1
2 3
4 5
1
1
2 2
5
9
8
Node
1 2 3 4 5
(0,-) (,-) (,-) (,-) (,-)
(0,-) (1,1) (,-) (1,1) (,-)
Find the shortest path from node 1 to node 5.
Step 1.Initialise distance and predecessor labels
Step 2.Pick unlabelled node with minimum distance label, i.e, node 1.
Step 3.Update distance and predecessor labels for nodes 2 and 4.
Updatedistance and predecessor labels forneighbouring nodes of i: for all nodesjs.t. (i,j)is anarc if dj> di + cijthen set djtodi + cijand set pjto i.
Unlabelled nodes
Labelled nodes
Node we are currently exploring
Lec 8 Network Models: Shortest Path Algorithms
1
2 3
4 5
1
1
2 2
5
9
8
Node
1 2 3 4 5
(0,-) (,-) (,-) (,-) (,-)
(0,-) (1,1) (,-) (1,1) (,-)
Find the shortest path from node 1 to node 5.
Step 1.Initialise distance and predecessor labels
Step 2.Pick unlabelled node with minimum distance label, i.e, node 1.
Step 3.Update distance and predecessor labels for nodes 2 and 4.
Step 4.Mark node 1 as labelled.
Updatedistance and predecessor labels forneighbouring nodes of i: for all nodesjs.t. (i,j)is anarc if dj> di + cijthen set djtodi + cijand set pjto i.
Unlabelled nodes
Labelled nodes
Node we are currently exploring
-
7/27/2019 Math1800 Lec8 Bb
12/35 1
Lec 8 Network Models: Shortest Path Algorithms
1
2 3
4 5
1
1
2 2
5
9
8
Node
1 2 3 4 5
(0,-) (,-) (,-) (,-) (,-)
(0,-) (1,1) (,-) (1,1) (,-)
(0,-) (1,1) (6,2) (1,1) (9,2)
Find the shortest path from node 1 to node 5.
Step 1.Initialise distance and predecessor labels
Step 2.Pick unlabelled node with minimum distance label, i.e, node 1.
Step 3.Update distance and predecessor labels for nodes 2 and 4.
Step 4.Mark node 1 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 2(node 4 is also possible).
Step 3.Update distance and predecessor labels for nodes 3,4 and 5.
Updatedistance and predecessor labels forneighbouring nodes of i: for all nodesjs.t. (i,j)is anarc if dj> di + cijthen set djtodi + cijand set pjto i.
Unlabelled nodes
Labelled nodes
Node we are currently exploring
Lec 8 Network Models: Shortest Path Algorithms
1
2 3
4 5
1
1
2 2
5
9
8
Node
1 2 3 4 5
(0,-) (,-) (,-) (,-) (,-)
(0,-) (1,1) (,-) (1,1) (,-)
(0,-) (1,1) (6,2) (1,1) (9,2)
Find the shortest path from node 1 to node 5.
Step 1.Initialise distance and predecessor labels
Step 2.Pick unlabelled node with minimum distance label, i.e, node 1.
Step 3.Update distance and predecessor labels for nodes 2 and 4.
Step 4.Mark node 1 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 2(node 4 is also possible).
Step 3.Update distance and predecessor labels for nodes 3,4 and 5.
Step 4.Mark node 2 as labelled.Unlabelled nodes
Labelled nodes
Node we are currently exploring
-
7/27/2019 Math1800 Lec8 Bb
13/35 1
Lec 8 Network Models: Shortest Path Algorithms
1
2 3
4 5
1
1
2 2
5
9
8
Node
1 2 3 4 5
(0,-) (,-) (,-) (,-) (,-)
(0,-) (1,1) (,-) (1,1) (,-)
(0,-) (1,1) (6,2) (1,1) (9,2)
(0,-) (1,1) (6,2) (1,1) (9,2)
Find the shortest path from node 1 to node 5.
Step 1.Initialise distance and predecessor labels
Step 2.Pick unlabelled node with minimum distance label, i.e, node 1.
Step 3.Update distance and predecessor labels for nodes 2 and 4.
Step 4.Mark node 1 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 2(node 4 is also possible).
Step 3.Update distance and predecessor labels for nodes 3,4 and 5.
Step 4.Mark node 2 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 4.
Step 3.Update distance and predecessor label for node 5.
Updatedistance and predecessor labels forneighbouring nodes of i: for all nodesjs.t. (i,j)is anarc if dj> di + cijthen set djtodi + cijand set pjto i.
Unlabelled nodes
Labelled nodes
Node we are currently exploring
Lec 8 Network Models: Shortest Path Algorithms
1
2 3
4 5
1
1
2 2
5
9
8
Node
1 2 3 4 5
(0,-) (,-) (,-) (,-) (,-)
(0,-) (1,1) (,-) (1,1) (,-)
(0,-) (1,1) (6,2) (1,1) (9,2)
(0,-) (1,1) (6,2) (1,1) (9,2)
Find the shortest path from node 1 to node 5.
Step 1.Initialise distance and predecessor labels
Step 2.Pick unlabelled node with minimum distance label, i.e, node 1.
Step 3.Update distance and predecessor labels for nodes 2 and 4.
Step 4.Mark node 1 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 2(node 4 is also possible).
Step 3.Update distance and predecessor labels for nodes 3,4 and 5.
Step 4.Mark node 2 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 4.
Step 3.Update distance and predecessor label for node 5.Step 4.Mark node 4 as labelled.
Unlabelled nodes
Labelled nodes
Node we are currently exploring
-
7/27/2019 Math1800 Lec8 Bb
14/35 1
Lec 8 Network Models: Shortest Path Algorithms
1
2 3
4 5
1
1
2 2
5
9
8
Node
1 2 3 4 5
(0,-) (,-) (,-) (,-) (,-)
(0,-) (1,1) (,-) (1,1) (,-)
(0,-) (1,1) (6,2) (1,1) (9,2)
(0,-) (1,1) (6,2) (1,1) (9,2)
(0,-) (1,1) (6,2) (1,1) (8,3)
Find the shortest path from node 1 to node 5.
Step 1.Initialise distance and predecessor labels
Step 2.Pick unlabelled node with minimum distance label, i.e, node 1.
Step 3.Update distance and predecessor labels for nodes 2 and 4.
Step 4.Mark node 1 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 2(node 4 is also possible).
Step 3.Update distance and predecessor labels for nodes 3,4 and 5.
Step 4.Mark node 2 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 4.
Step 3.Update distance and predecessor label for node 5.
Step 4.Mark node 4 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 3.
Step 3.Update distance and predecessor labels for node 5.
Updatedistance and predecessor labels forneighbouring nodes of i: for all nodesjs.t. (i,j)is anarc if dj> di + cijthen set djtodi + cijand set pjto i.
Unlabelled nodes
Labelled nodes
Node we are currently exploring
Lec 8 Network Models: Shortest Path Algorithms
1
2 3
4 5
1
1
2 2
5
9
8
Node
1 2 3 4 5
(0,-) (,-) (,-) (,-) (,-)
(0,-) (1,1) (,-) (1,1) (,-)
(0,-) (1,1) (6,2) (1,1) (9,2)
(0,-) (1,1) (6,2) (1,1) (9,2)
(0,-) (1,1) (6,2) (1,1) (8,3)
Find the shortest path from node 1 to node 5.
Step 1.Initialise distance and predecessor labels
Step 2.Pick unlabelled node with minimum distance label, i.e, node 1.
Step 3.Update distance and predecessor labels for nodes 2 and 4.
Step 4.Mark node 1 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 2(node 4 is also possible).
Step 3.Update distance and predecessor labels for nodes 3,4 and 5.
Step 4.Mark node 2 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 4.
Step 3.Update distance and predecessor label for node 5.Step 4.Mark node 4 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 3.
Step 3.Update distance and predecessor labels for node 5.
Step 4.Mark node 3 as labelled.
Unlabelled nodes
Labelled nodes
Node we are currently exploring
-
7/27/2019 Math1800 Lec8 Bb
15/35 1
Lec 8 Network Models: Shortest Path Algorithms
1
2 3
4 5
1
1
2 2
5
9
8
Node
1 2 3 4 5
(0,-) (,-) (,-) (,-) (,-)
(0,-) (1,1) (,-) (1,1) (,-)
(0,-) (1,1) (6,2) (1,1) (9,2)
(0,-) (1,1) (6,2) (1,1) (9,2)
(0,-) (1,1) (6,2) (1,1) (8,3)
Find the shortest path from node 1 to node 5.
Step 1.Initialise distance and predecessor labels
Step 2.Pick unlabelled node with minimum distance label, i.e, node 1.
Step 3.Update distance and predecessor labels for nodes 2 and 4.
Step 4.Mark node 1 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 2(node 4 is also possible).
Step 3.Update distance and predecessor labels for nodes 3,4 and 5.
Step 4.Mark node 2 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 4.
Step 3.Update distance and predecessor label for node 5.
Step 4.Mark node 4 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 3.
Step 3.Update distance and predecessor labels for node 5.
Step 4.Mark node 3 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 5.
Step 3.No distance and predecessor labels need updating.
Step 4.Mark 5 as labelled. No unlabelled labels remaining. STOP
Unlabelled nodes
Labelled nodes
Node we are currently exploring
Lec 8 Network Models: Shortest Path Algorithms
1
2 3
4 5
1
1
2 2
5
9
8
Find the shortest path from node 1 to node 5.
Step 1.Initialise distance and predecessor labels
Step 2.Pick unlabelled node with minimum distance label, i.e, node 1.
Step 3.Update distance and predecessor labels for nodes 2 and 4.
Step 4.Mark node 1 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 2(node 4 is also possible).
Step 3.Update distance and predecessor labels for nodes 3,4 and 5.
Step 4.Mark node 2 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 4.
Step 3.Update distance and predecessor label for node 5.Step 4.Mark node 4 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 3.
Step 3.Update distance and predecessor labels for node 5.
Step 4.Mark node 3 as labelled.
Step 2.Pick unlabelled node with minimum distance label, i.e, node 5.
Step 3.No distance and predecessor labels need updating.
Step 4.Mark 5 as labelled. No unlabelled labels remaining. STOP
Iteration1
Iteration2
Iteration3
Iteration4
Iteration5
Iterat
ionNode
1 2 3 4 5
0 (0,-) (,-) (,-) (,-) (,-)
1 (0,-) (1,1) (,-) (1,1) (,-)
2 (0,-) (1,1) (6,2) (1,1) (9,2)
3 (0,-) (1,1) (6,2) (1,1) (9,2)
4 (0,-) (1,1) (6,2) (1,1) (8,3)
Unlabelled nodes
Labelled nodes
Node we are currently exploring
-
7/27/2019 Math1800 Lec8 Bb
16/35 1
Lec 8 Network Models: Shortest Path Algorithms
1
2 3
4 5
1
1
2 2
5
9
8
Find the shortest path from node 1 to node 5.
The shortest path from 1to 5is: (1,2,3,5) with cost 8
Property of Distance and Predecessor Labels
The distance and predecessor labels inform us about notonly the optimal path from sto t, but from sto every othernode.
Q. What is the shortest path from 1 to 2?
A. (1,2) with cost 1
Q. What is the shortest path from 1 to 3?
A. (1,2,3) with cost 6
Q. What is the shortest path from 1 to 4?
A. (1,4) with cost 1
Q. What is the shortest path from 1 to 4?
A. (1,2,3,5) with cost 8
Iterat
ionNode
1 2 3 4 5
0 (0,-) (,-) (,-) (,-) (,-)1 (0,-) (1,1) (,-) (1,1) (,-)
2 (0,-) (1,1) (6,2) (1,1) (9,2)
3 (0,-) (1,1) (6,2) (1,1) (9,2)
4 (0,-) (1,1) (6,2) (1,1) (8,3)
Unlabelled nodes
Labelled nodes
Node we are currently exploring
Lec 8 Network Models: Shortest Path Algorithms
1
2 3
4 5
1
1
2 2
5
9
8
Find the shortest path from node 1 to node 5.
The shortest path from 1to 5is: (1,2,3,5) with cost 8
Property of Distance and Predecessor Labels
The distance and predecessor labels inform us about notonly the optimal path from sto t, but from sto every othernode.
Q. What is the shortest path from 1 to 2?A. (1,2) with cost 1
Q. What is the shortest path from 1 to 3?
A. (1,2,3) with cost 6
Q. What is the shortest path from 1 to 4?
A. (1,4) with cost 1
Q. What is the shortest path from 1 to 4?
A. (1,2,3,5) with cost 8
Iterat
ionNode
1 2 3 4 5
0 (0,-) (,-) (,-) (,-) (,-)
1 (0,-) (1,1) (,-) (1,1) (,-)
2 (0,-) (1,1) (6,2) (1,1) (9,2)
3 (0,-) (1,1) (6,2) (1,1) (9,2)
4 (0,-) (1,1) (6,2) (1,1) (8,3)
Unlabelled nodes
Labelled nodes
Node we are currently exploring
-
7/27/2019 Math1800 Lec8 Bb
17/35 1
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 3
4 5
50
200
6
40
150
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
Unlabelled nodes
Labelled nodes
Node we are currently exploring
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 3
4 5
50
200
6
40
150
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1 (0,-) (100,1) (,-) (200,1) (,-) (,-)
Unlabelled nodes
Labelled nodes
Node we are currently exploring
-
7/27/2019 Math1800 Lec8 Bb
18/35 1
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 3
4 5
50
200
6
40
150
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1 (0,-) (100,1) (,-) (200,1) (,-) (,-)
2 (0,-) (100,1) (300,2) (150,2) (200,2) (,-)
Unlabelled nodes
Labelled nodes
Node we are currently exploring
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 3
4 5
50
200
6
40
150
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1 (0,-) (100,1) (,-) (200,1) (,-) (,-)
2 (0,-) (100,1) (300,2) (150,2) (200,2) (,-)
3 (0,-) (100,1) (300,2) (150,2) (190,4) (,-)Unlabelled nodes
Labelled nodes
Node we are currently exploring
-
7/27/2019 Math1800 Lec8 Bb
19/35 1
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 3
4 5
50
200
6
40
150
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1 (0,-) (100,1) (,-) (200,1) (,-) (,-)
2 (0,-) (100,1) (300,2) (150,2) (200,2) (,-)
3 (0,-) (100,1) (300,2) (150,2) (190,4) (,-)
4 (0,-) (100,1) (300,2) (150,2) (190,4) (290,5)
Unlabelled nodes
Labelled nodes
Node we are currently exploring
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 3
4 5
50
200
6
40
150
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1 (0,-) (100,1) (,-) (200,1) (,-) (,-)
2 (0,-) (100,1) (300,2) (150,2) (200,2) (,-)
3 (0,-) (100,1) (300,2) (150,2) (190,4) (,-)
4 (0,-) (100,1) (300,2) (150,2) (190,4) (290,5)
5 (0,-) (100,1) (300,2) (150,2) (190,4) (290,5)
Unlabelled nodes
Labelled nodes
Node we are currently exploring
-
7/27/2019 Math1800 Lec8 Bb
20/35 2
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 3
4 5
50
200
6
40
150
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1 (0,-) (100,1) (,-) (200,1) (,-) (,-)
2 (0,-) (100,1) (300,2) (150,2) (200,2) (,-)
3 (0,-) (100,1) (300,2) (150,2) (190,4) (,-)
4 (0,-) (100,1) (300,2) (150,2) (190,4) (290,5)
5 (0,-) (100,1) (300,2) (150,2) (190,4) (290,5)
6 (0,-) (100,1) (300,2) (150,2) (190,4) (290,5)
Unlabelled nodes
Labelled nodes
Node we are currently exploring
Lec 8 Network Models: Shortest Path Algorithms
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1 (0,-) (100,1) (,-) (200,1) (,-) (,-)
2 (0,-) (100,1) (300,2) (150,2) (200,2) (,-)
3 (0,-) (100,1) (300,2) (150,2) (190,4) (,-)
4 (0,-) (100,1) (300,2) (150,2) (190,4) (290,5)
5 (0,-) (100,1) (300,2) (150,2) (190,4) (290,5)
6 (0,-) (100,1) (300,2) (150,2) (190,4) (290,5)
Find the shortest path from node 1 to node 6.
1
2 3
4 5
50
200
6
40
150
The shortest path from 1to 6is: (1,2,4,5,6) with cost 290
Note: once a node is labelled, its distance and predecessor label is neverchanged. Hence, once a node is labelled, its distance label gives the shortestdistance from sto that node. We could therefore have stopped at iteration 5.
Unlabelled nodes
Labelled nodes
Node we are currently exploring
-
7/27/2019 Math1800 Lec8 Bb
21/35 2
Lec 8 Network Models: Shortest Path Algorithms
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1 (0,-) (100,1) (,-) (200,1) (,-) (,-)
2 (0,-) (100,1) (300,2) (150,2) (200,2) (,-)
3 (0,-) (100,1) (300,2) (150,2) (190,4) (,-)
4 (0,-) (100,1) (300,2) (150,2) (190,4) (290,5)
5 (0,-) (100,1) (300,2) (150,2) (190,4) (290,5)
6 (0,-) (100,1) (300,2) (150,2) (190,4) (290,5)
Find the shortest path from node 1 to node 6.
1
2 3
4 5
50
200
6
40
150
The shortest path from 1to 6is: (1,2,4,5,6) with cost 290
Note: once a node is labelled, its distance and predecessor label is neverchanged. Hence, once a node is labelled, its distance label gives the shortestdistance from sto that node. We could therefore have stopped at iteration 5.
Q. Does Dikstrasalgorithm always find the shortest path?
Unlabelled nodes
Labelled nodes
Node we are currently exploring
Lec 8 Network Models: Shortest Path Algorithms
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1 (0,-) (100,1) (,-) (200,1) (,-) (,-)
2 (0,-) (100,1) (300,2) (150,2) (200,2) (,-)
3 (0,-) (100,1) (300,2) (150,2) (190,4) (,-)
4 (0,-) (100,1) (300,2) (150,2) (190,4) (290,5)
5 (0,-) (100,1) (300,2) (150,2) (190,4) (290,5)
6 (0,-) (100,1) (300,2) (150,2) (190,4) (290,5)
Find the shortest path from node 1 to node 6.
1
2 3
4 5
50
200
6
40
150
The shortest path from 1to 6is: (1,2,4,5,6) with cost 290
Note: once a node is labelled, its distance and predecessor label is neverchanged. Hence, once a node is labelled, its distance label gives the shortestdistance from sto that node. We could therefore have stopped at iteration 5.
Q. Does Dikstrasalgorithm always find the shortest path?
A. No.
Unlabelled nodes
Labelled nodes
Node we are currently exploring
-
7/27/2019 Math1800 Lec8 Bb
22/35 2
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 4
3
1
6
5-100
10 1
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1
2
3
4
5
6
Unlabelled nodes
Labelled nodes
Node we are currently exploring
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 4
3
1
6
5-100
10 1
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1 (0,-) (1,1) (,-) (,-) (,-) (,-)
2
3
4
5
6
Unlabelled nodes
Labelled nodes
Node we are currently exploring
-
7/27/2019 Math1800 Lec8 Bb
23/35 2
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 4
3
1
6
5-100
10 1
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1 (0,-) (1,1) (,-) (,-) (,-) (,-)
2 (0,-) (1,1) (11,2) (2,2) (,-) (,-)
3
4
5
6
Unlabelled nodes
Labelled nodes
Node we are currently exploring
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 4
3
1
6
5-100
10 1
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1 (0,-) (1,1) (,-) (,-) (,-) (,-)
2 (0,-) (1,1) (11,2) (2,2) (,-) (,-)
3 (0,-) (1,1) (11,2) (2,2) (,-) (3,4)
4
5
6
Unlabelled nodes
Labelled nodes
Node we are currently exploring
-
7/27/2019 Math1800 Lec8 Bb
24/35 2
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 4
3
1
6
5-100
10 1
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1 (0,-) (1,1) (,-) (,-) (,-) (,-)
2 (0,-) (1,1) (11,2) (2,2) (,-) (,-)
3 (0,-) (1,1) (11,2) (2,2) (,-) (3,4)
4 (0,-) (1,1) (11,2) (2,2) (,-) (3,4)
5
6
Unlabelled nodes
Labelled nodes
Node we are currently exploring
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 4
3
1
6
5-100
10 1
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1 (0,-) (1,1) (,-) (,-) (,-) (,-)
2 (0,-) (1,1) (11,2) (2,2) (,-) (,-)
3 (0,-) (1,1) (11,2) (2,2) (,-) (3,4)
4 (0,-) (1,1) (11,2) (2,2) (,-) (3,4)
5 (0,-) (1,1) (11,2) (2,2) (-89,3) (3,4)
6
Unlabelled nodes
Labelled nodes
Node we are currently exploring
-
7/27/2019 Math1800 Lec8 Bb
25/35 2
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 4
3
1
6
5-100
10 1
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1 (0,-) (1,1) (,-) (,-) (,-) (,-)
2 (0,-) (1,1) (11,2) (2,2) (,-) (,-)
3 (0,-) (1,1) (11,2) (2,2) (,-) (3,4)
4 (0,-) (1,1) (11,2) (2,2) (,-) (3,4)
5 (0,-) (1,1) (11,2) (2,2) (-89,3) (3,4)
6 (0,-) (1,1) (11,2) (-88,5) (-89,3) (3,4)
Unlabelled nodes
Labelled nodes
Node we are currently exploring
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
Q. Does Dikstrasalgorithm always find the shortest path?
A. No. Not if there are negat ive cost arcs.
Q. Are there other algorithms that can find the shortest path when there arenegative cost arcs?
1
2 4
3
1
6
5-100
10 1
Iteration Node
1 2 3 4 5 6
0 (0,-) (,-) (,-) (,-) (,-) (,-)
1 (0,-) (1,1) (,-) (,-) (,-) (,-)
2 (0,-) (1,1) (11,2) (2,2) (,-) (,-)
3 (0,-) (1,1) (11,2) (2,2) (,-) (3,4)
4 (0,-) (1,1) (11,2) (2,2) (,-) (3,4)
5 (0,-) (1,1) (11,2) (2,2) (-89,3) (3,4)
6 (0,-) (1,1) (11,2) (-88,5) (-89,3) (3,4)
Unlabelled nodes
Labelled nodes
Node we are currently exploring
-
7/27/2019 Math1800 Lec8 Bb
26/35 2
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 3
4 5
50
200
6
40
150
Q. What is the shortest path from 1 to 6?
Path 1: (1,2,3,6) with cost 400
Path 2: (1,2,3,5,2,3,6) with cost 250
Path 3: (1,2,3,5,2,3,5,2,3,6) with cost 100
Path 3: (1,2,3,5,2,3,5,2,3,5,2,3,6) with cost -50
Path 4: (1,2,3,5,2,3,5,2,3,5,2,3,5,2,3,6) with cost -200
:
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 3
4 5
50
200
6
40
150
Q. What is the shortest path from 1 to 6?A. There is none.
Q. What is the shortest path from 1 to 6 that does not contain any cycles?
Path 1: (1,2,3,6) with cost 300
Path 2: (1,2,3,5,2,3,6) with cost 50
Path 3: (1,2,3,5,2,3,5,2,3,6) with cost -100
Path 3: (1,2,3,5,2,3,5,2,3,5,2,3,6) with cost -250
Path 4: (1,2,3,5,2,3,5,2,3,5,2,3,5,2,3,6) with cost -400
:
-
7/27/2019 Math1800 Lec8 Bb
27/35 2
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 3
4 5
50
200
6
40
150
Q. What is the shortest path from 1 to 6?A. There is none.
Q. What is the shortest path from 1 to 6 that does not contain any cycles?
Path 1: (1,2,3,6) with cost 300
Path 2: (1,2,3,5,2,3,6) with cost 50
Path 3: (1,2,3,5,2,3,5,2,3,6) with cost -100
Path 3: (1,2,3,5,2,3,5,2,3,5,2,3,6) with cost -250
Path 4: (1,2,3,5,2,3,5,2,3,5,2,3,5,2,3,6) with cost -400
:
Q. Are there algorithms that can find the shortest path when there are negativecost arcs?
A. Yes, there are efficient algorithms when there are no negat ive cost cyc les.
Q. Are there algorithms that can find the shortest path that does not contain anycycles?
Lec 8 Network Models: Shortest Path Algorithms
Find the shortest path from node 1 to node 6.
1
2 3
4 5
50
200
6
40
150
Q. What is the shortest path from 1 to 6?A. There is none.
Q. What is the shortest path from 1 to 6 that does not contain any cycles?
Path 1: (1,2,3,6) with cost 300
Path 2: (1,2,3,5,2,3,6) with cost 50
Path 3: (1,2,3,5,2,3,5,2,3,6) with cost -100
Path 3: (1,2,3,5,2,3,5,2,3,5,2,3,6) with cost -250
Path 4: (1,2,3,5,2,3,5,2,3,5,2,3,5,2,3,6) with cost -400
:
Q. Are there algorithms that can find the shortest path when there are negativecost arcs?
A. Yes, there are efficient algorithms when there are no negat ive cost cyc les.
Q. Are there algorithms that can find the shortest path that does not contain anycycles?
A. Yesbut they are not ef fic ient. This can be a very difficult problem.
-
7/27/2019 Math1800 Lec8 Bb
28/35 2
Lec 8 Network Models: Shortest Path Algorithms
Practical variants of Dijkstrasalgorithm
Dijkstrasalgorithm on a road network
Lec 8 Network Models: Shortest Path Algorithms
Practical variants of Dijkstrasalgorithm
Bi-directional Dijkstrasalgorithm on a road network
-
7/27/2019 Math1800 Lec8 Bb
29/35 2
Lec 8 Network Models: Shortest Path Algorithms
Practical variants of Dijkstrasalgorithm
Dijkstrasalgorithm with A* search on a road network
Lec 8 Network Models: Shortest Path Algorithms
Practical variants of Dijkstrasalgorithm
Dijkstra Bi-directional Dijkstra
Bi-directional Dijkstra + A*
-
7/27/2019 Math1800 Lec8 Bb
30/35 3
Lec 8 Network Models: Shortest Path Algorithms
Practical variants of Dijkstrasalgorithm
Hierarchy in a road network
Lec 8 Network Models: Shortest Path Algorithms
Practical variants of Dijkstrasalgorithm
Bi-directional Dijkstrasalgorithm + A* + Hierarchy on a road network
-
7/27/2019 Math1800 Lec8 Bb
31/35 3
Lec 8 Network Models: Flows in Directed Graphs
Think of arcs in network as conduits carrying flow. Given a network with nodes Nand arcs A, for each arc e = (i,j)in Awe associate an amount xe(or xij)corresponding to the amount of flow through arc e.
A = {(1,2), (1,4), (2,3), (2,4), (4,3)}
X = (x1,2, x1,4, x2,3, x2,4, x4,3) = (4,3,2,1,6)
Flow
For a graph with nodes Nand arcs A, the vector Xis calleda f low.
Flow in Directed Graph
1 2
34
4
31
6
2
Flow vector
Lec 8 Network Models: Flows in Directed Graphs
Flow in Directed Graph
1 2
34
4
31
6
2
Net flow in/out of a node
The net flow in/out of a node is the total amount of flowentering/leaving the node.
Q. What is the net flow in tonode 3? 8
Q. What is the net flow in tonode 4? 4
Q. What is the net flow ou tof node 3? 0
Q. What is the net flow ou tof node 4? 6
-
7/27/2019 Math1800 Lec8 Bb
32/35 3
Lec 8 Network Models: Flows in Directed Graphs
Bounds on f low
For each arc e, we may be given a lowerand/or upperbound leand uerespectively on the allowable flow along e.
A = {(1,2), (1,4), (2,3), (2,4), (4,3)}L = (l1,2, l1,4, l2,3, l2,4, l4,3) = (0,1,0,2,0)
U = (u1,2, u1,4, u2,3, u2,3, u4,3) = (5,3,4,3,5)
Bounds on flow
1 2
34
[0,5]
[1,3] [0,4]
[0,5]
Note: If a lower bound is not given then we can assume it is 0, i.e., we do not haveve flow.
Lec 8 Network Models: Flows in Directed Graphs
Bounds on flow
1 2
34
[0,5]
[1,3] [0,4]
[0,5]
Feasib le flow from source to sink
A flow from a source node sto a sink node tis feasible if:
1. for all nodes except sand t, the
net flow into the node = net flow out of the node, and
2. the flow along each arc is within the stated bounds.
Flow balancerequirement
No leaks
-
7/27/2019 Math1800 Lec8 Bb
33/35 3
Lec 8 Network Models: Flows in Directed Graphs
Bounds on flow
1 2
34
[0,5]
[1,3] [0,4]
[0,5]
Flow in Directed Graph
1 2
34
4
31
6
2
Q. Is the following a feasible flow from node 1 to node 3 (i.e. s=1, t=3)?
A. No. Flow balance requirements are not satisfied at nodes 2 and 4, and the boundsare not satisfied on arcs (2,4) and (4,3).
Feasib le flow from source to sink
A flow from a source node sto a sink node tis feasible if:
1. for all nodes except sand t, the
net flow into the node = net flow out of the node, and
2. the flow along each arc is within the stated bounds.
Lec 8 Network Models: Flows in Directed Graphs
Find threefeasible flows from node 1 to node 3:
Bounds on flow
1 2
34
[0,5]
[1,3] [0,4]
[0,5]
Flow 1
1 2
34
2
12
3
0
Flow 2
1 2
34
3
22
4
1
Flow 3
1 2
34
5
32
5
3
Flow balance Bounds
Flow balance Bounds
Flow balance Bounds
Note: if flow balance is satisfied, then the net flow out of s= net flow into t. Thisnet flow out of s(or into t) is the amount of flow that is pushed through from sto t.
-
7/27/2019 Math1800 Lec8 Bb
34/35 3
Lec 8 Network Models: Flows in Directed Graphs
Find threefeasible flows from node 1 to node 3:
Bounds on flow
1 2
34
[0,5]
[1,3] [0,4]
[0,5]
Flow 1
1 2
34
2
12
3
0
Flow 2
1 2
34
3
22
4
1
Flow 3
1 2
34
5
32
5
3
Net flow out of s=net flow intot= 3
Net flow out of s=net flow intot= 5
Net flow out of s=net flow intot= 5
Flow from sto t= 3 Flow from sto t= 5 Flow from sto t= 8
Lec 8 Network Models: Flows in Directed Graphs
The Maximum Flow Problem
The maximum f low prob lemis one of finding a feasibleflow from a node sto a node twhere the net flow leaving s(or entering t) is the maximum possible, i.e. finding themaximum amount of flow that can be pushed through from
sto t.
Flow 1
1 2
34
2
12
3
0
Flow 2
1 2
34
3
22
4
1
Flow 3
1 2
34
5
32
5
3
Net flow out of s=net flow intot= 3
Net flow out of s=net flow intot= 5
Net flow out of s=net flow intot= 5
Flow from sto t= 3 Flow from sto t= 5 Flow from sto t= 8
Q. Is 8the maximum possible flow from sto t?Yes(why?)
-
7/27/2019 Math1800 Lec8 Bb
35/35
Lec 8 Network Models: Applications of Maximum Flow
Transporting Natural Gas through Pipelines
Western Australia Natural Gas Co. has developed a pipeline network to transportLiquefied Natural Gas (LNG) from exploration fields to refineries and other
locations. There are 10 pipelines in the network (see below). The maximum flowrate along each pipeline is given in hundreds of litres per hour.
What is the maximum possible flow rate of LNG from node 1 to node 8?
2 4
10
3
6
1
5 7
8
8
12 10
6 10
8 5
12
10
Maximum flow rate inL/ hour.