Вы находитесь на странице: 1из 35

MATH1800 Mathematical 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 about spanning 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

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 about spanning 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 the shortest path from a node s to a node t with respect to arc length/cost cij.

Example: Find the shortest path from node 1 to node 5 (i.e. s=1, t=5) Shortest path is (1, 2, 3, 5) with cost 8. (why?)
1 5 8 9

2
2

3
2

1
1

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 the shortest path from a node s to a node t with respect to arc length/cost cij.

Example: Find the shortest path from node 1 to node 5 (i.e. s=1, t=5) Shortest path is (1, 2, 3, 5) with cost 8. (why?)
1 5 8 9

2
2

3
2

1
1

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 the shortest path from a node s to a node t with respect to arc length/cost cij.

Example: Find the shortest path from node 1 to node 5 (i.e. s=1, t=5) Shortest path is (1, 2, 3, 5) with cost 8. (why?)
1 5 8 9

2
2

3
2

1
1

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 8 and therefore optimal.

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 the shortest path from a node s to a node t with respect to arc length/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 the shortest path from a node s to a node t with respect to arc length/cost cij.

Q. What about shortest paths in larger networks?

No. of nodes (n) 10 20 50 100 : 1000

Max no. of arcs (n2) 100 400 2,500 10,000 : 1,000,000

Max no. of paths between a pair of nodes (n!) 3628800 2432902008176640000 30414093201713378043612608166065(32 more digits) 93326215443944152681699238856267(126 more digits) : 402387260077093773543702433923(2,538 more digits)

Lec 8

Network Models: Applications of Shortest Paths


Transportation/Communication networks (Logistics, 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 in value (see below). Projected new car prices are also given below.
Age of car 1 2 3 4 5 Annual cost $1,000 $2,000 $5,000 $9,000 $12,000 Trade-in Value $12,000 $10,000 $6,000 $5,000 $3,000 Start of Year 1 2 3 4 5 Price $19,000 $18,500 $18,000 $18,000 $17,000

If the company requires a car for 5 years, what is the optimal strategy?

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.
Age of car 1 2 3 4 5 Annual cost $1,000 $2,000 $5,000 $9,000 $12,000 Trade-in Value $12,000 $10,000 $6,000 $5,000 $3,000 Start of Year 1 2 3 4 5 Price $19,000 $18,500 $18,000 $18,000 $17,000

If the company requires a car for 5 years, what is the optimal strategy? A network model:
node arc length

i i i
cij

Start of year i

j j

Buy a car at the start of year i and drive until start of year j (i < j) Cost of buying a car at the start of year i + cost of j-i years of maintenance trade-in value of (j-i) year-old car

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.
Age of car 1 2 3 4 5 Annual cost $1,000 $2,000 $5,000 $9,000 $12,000 Trade-in Value $12,000 $10,000 $6,000 $5,000 $3,000 Start of Year 1 2 3 4 5 Price $19,000 $18,500 $18,000 $18,000 $17,000

If the company requires a car for 5 years, what is the optimal strategy?
19+1+2+5-6 = 21 19+1+2-10 = 12

1
19+1-12 = 8

3
18.5+1+2-10 = 11.5

Optimal strategy: shortest path from node 1 to node 6.

18.5+1-12 = 7.5 18+1-12 = 7

Exercise: complete network and find shortest path.

Lec 8

Network Models: Applications of Shortest Paths


Very Large Scale Integration (VLSI) circuit design
When designing VLSI circuits, need to isolate negative feedback loops. These negative feedback loops correspond to negative cost cycles in the amplifier-gain network of the circuit.

Lec 8

Network Models: Applications of Shortest Paths


Robotic Surgery
Planning shortest paths through patients anatomy and avoid obstacles

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 be modelled as a graph, with any edge across a black pixel given a high cost. The shortest path defines the best separation.

Lec 8

Network Models: Shortest Path Algorithms


Dijkstras Algorithm for Shortest Paths (1956) Given network with nodes N and arcs A, find shortest path from node s to node t. 1. Assign a distance label di, and a predecessor label pi to each node. Set di to infinity for all nodes except s. Set ds to 0. Mark all nodes as unlabelled. 2. Pick an unlabelled node i with the minimum distance label di to explore. 3. Update distance and predecessor labels for neighbouring nodes of i: for all nodes j s.t. (i,j) is an arc if dj > di + cij then set dj to di + cij and set pj to i. 4. Mark i as labelled. 5. Repeat second step until all nodes are labelled.

di tracks the distance of the shortest path found so far from s to node i. pi tracks the node that precedes i on the shortest path found so far from s to i.

Lec 8

Network Models: Shortest Path Algorithms


Dijkstras Algorithm for Shortest Paths (1956) Given network with nodes N and arcs A, find shortest path from node s to node t. 1. Assign a distance label di, and a predecessor label pi to each node. Set di to infinity for all nodes except s. Set ds to 0. Mark all nodes as unlabelled. 2. Pick an unlabelled node i with the minimum distance label di to explore. 3. Update distance and predecessor labels for neighbouring nodes of i: for all nodes j s.t. (i,j) is an arc if dj > di + cij then set dj to di + cij and set pj to i. 4. Mark i as labelled. 5. Repeat second step until all nodes are labelled.

di tracks the distance of the shortest path found so far from s to node i. pi tracks the node that precedes i on the shortest path found so far from s to i.

Lec 8

Network Models: Shortest Path Algorithms


Dijkstras Algorithm for Shortest Paths (1956) Given network with nodes N and arcs A, find shortest path from node s to node t. 1. Assign a distance label di, and a predecessor label pi to each node. Set di to infinity for all nodes except s. Set ds to 0. Mark all nodes as unlabelled. 2. Pick an unlabelled node i with the minimum distance label di to explore. 3. Update distance and predecessor labels for neighbouring nodes of i: for all nodes j s.t. (i,j) is an arc if dj > di + cij then set dj to di + cij and set pj to i. 4. Mark i as labelled. 5. Repeat second step until all nodes are labelled.

di tracks the distance of the shortest path found so far from s to node i. pi tracks the node that precedes i on the shortest path found so far from s to i.

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 5.

2
2

5 8 9

3
2

1
1

Lec 8

Network Models: Shortest Path Algorithms


Step 1. Initialise distance and predecessor labels 1

Find the shortest path from node 1 to node 5.

2
2

5 8 9

3
2

1
1

4
Unlabelled nodes Labelled nodes

Node we are currently exploring


Node 1 (0,-) 2 (,-) 3 (,-) 4 (,-) 5 (,-)

Distance and predecessor label (di,pi) for node i

10

Lec 8

Network Models: Shortest Path Algorithms


Step 1. Initialise distance and predecessor labels 1

Find the shortest path from node 1 to node 5.

2
2

5 8 9

3
2

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.

1
1

4
Unlabelled nodes Labelled nodes

Update distance and predecessor labels for neighbouring nodes of i: for all nodes j s.t. (i,j) is an arc if dj > di + cij then set dj to di + cij and set pj to i.

Node we are currently exploring


Node 1 (0,-) (0,-) 2 (,-) (1,1) 3 (,-) (,-) 4 (,-) (1,1) 5 (,-) (,-)

Lec 8

Network Models: Shortest Path Algorithms


Step 1. Initialise distance and predecessor labels 1

Find the shortest path from node 1 to node 5.

2
2

5 8 9

3
2

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.

1
1

4
Unlabelled nodes Labelled nodes

5
Update distance and predecessor labels for neighbouring nodes of i: for all nodes j s.t. (i,j) is an arc if dj > di + cij then set dj to di + cij and set pj to i.

Node we are currently exploring


Node 1 (0,-) (0,-) 2 (,-) (1,1) 3 (,-) (,-) 4 (,-) (1,1) 5 (,-) (,-)

11

Lec 8

Network Models: Shortest Path Algorithms


Step 1. Initialise distance and predecessor labels 1

Find the shortest path from node 1 to node 5.

2
2

5 8 9

3
2

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.

1
1

4
Unlabelled nodes Labelled nodes

Node we are currently exploring


Node 1 (0,-) (0,-) (0,-) 2 (,-) (1,1) (1,1) 3 (,-) (,-) (6,2) 4 (,-) (1,1) (1,1) 5 (,-) (,-) (9,2)

Update distance and predecessor labels for neighbouring nodes of i: for all nodes j s.t. (i,j) is an arc if dj > di + cij then set dj to di + cij and set pj to i.

Lec 8

Network Models: Shortest Path Algorithms


Step 1. Initialise distance and predecessor labels 1

Find the shortest path from node 1 to node 5.

2
2

5 8 9

3
2

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.

1
1

4
Unlabelled nodes Labelled nodes

Step 4. Mark node 2 as labelled.

Node we are currently exploring


Node 1 (0,-) (0,-) (0,-) 2 (,-) (1,1) (1,1) 3 (,-) (,-) (6,2) 4 (,-) (1,1) (1,1) 5 (,-) (,-) (9,2)

12

Lec 8

Network Models: Shortest Path Algorithms


Step 1. Initialise distance and predecessor labels 1

Find the shortest path from node 1 to node 5.

2
2

5 8 9

3
2

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.

1
1

4
Unlabelled nodes Labelled nodes

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.

Node we are currently exploring


Node 1 (0,-) (0,-) (0,-) (0,-) 2 (,-) (1,1) (1,1) (1,1) 3 (,-) (,-) (6,2) (6,2) 4 (,-) (1,1) (1,1) (1,1) 5 (,-) (,-) (9,2) (9,2)

Update distance and predecessor labels for neighbouring nodes of i: for all nodes j s.t. (i,j) is an arc if dj > di + cij then set dj to di + cij and set pj to i.

Lec 8

Network Models: Shortest Path Algorithms


Step 1. Initialise distance and predecessor labels 1

Find the shortest path from node 1 to node 5.

2
2

5 8 9

3
2

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.

1
1

4
Unlabelled nodes Labelled nodes

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.
4 (,-) (1,1) (1,1) (1,1) 5 (,-) (,-) (9,2) (9,2)

Node we are currently exploring


Node 1 (0,-) (0,-) (0,-) (0,-) 2 (,-) (1,1) (1,1) (1,1) 3 (,-) (,-) (6,2) (6,2)

13

Lec 8

Network Models: Shortest Path Algorithms


Step 1. Initialise distance and predecessor labels 1

Find the shortest path from node 1 to node 5.

2
2

5 8 9

3
2

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.

1
1

4
Unlabelled nodes Labelled nodes

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.
4 (,-) (1,1) (1,1) (1,1) (1,1) 5 (,-) (,-) (9,2) (9,2) (8,3)

Node we are currently exploring


Node 1 (0,-) (0,-) (0,-) (0,-) (0,-) 2 (,-) (1,1) (1,1) (1,1) (1,1) 3 (,-) (,-) (6,2) (6,2) (6,2)

Step 2. Pick unlabelled node with minimum distance label, i.e, node 3. Step 3. Update distance and predecessor labels for node 5.

Update distance and predecessor labels for neighbouring nodes of i: for all nodes j s.t. (i,j) is an arc if dj > di + cij then set dj to di + cij and set pj to i.

Lec 8

Network Models: Shortest Path Algorithms


Step 1. Initialise distance and predecessor labels 1

Find the shortest path from node 1 to node 5.

2
2

5 8 9

3
2

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.

1
1

4
Unlabelled nodes Labelled nodes

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.
4 (,-) (1,1) (1,1) (1,1) (1,1) 5 (,-) (,-) (9,2) (9,2) (8,3)

Node we are currently exploring


Node 1 (0,-) (0,-) (0,-) (0,-) (0,-) 2 (,-) (1,1) (1,1) (1,1) (1,1) 3 (,-) (,-) (6,2) (6,2) (6,2)

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.

14

Lec 8

Network Models: Shortest Path Algorithms


Step 1. Initialise distance and predecessor labels 1

Find the shortest path from node 1 to node 5.

2
2

5 8 9

3
2

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.

1
1

4
Unlabelled nodes Labelled nodes

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.
4 (,-) (1,1) (1,1) (1,1) (1,1) 5 (,-) (,-) (9,2) (9,2) (8,3)

Node we are currently exploring


Node 1 (0,-) (0,-) (0,-) (0,-) (0,-) 2 (,-) (1,1) (1,1) (1,1) (1,1) 3 (,-) (,-) (6,2) (6,2) (6,2)

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

Lec 8

Network Models: Shortest Path Algorithms


Step 1. Initialise distance and predecessor labels 1
Iteration 1 Iteration 2 Iteration 3 Iteration 4 Iteration 5

Find the shortest path from node 1 to node 5.

2
2

5 8 9

3
2

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

1
1

4
Unlabelled nodes Labelled nodes

Node we are currently exploring


Iterat ion

Node 1 2 (,-) (1,1) (1,1) (1,1) (1,1) 3 (,-) (,-) (6,2) (6,2) (6,2) 4 (,-) (1,1) (1,1) (1,1) (1,1) 5 (,-) (,-) (9,2) (9,2) (8,3)

0 1 2 3 4

(0,-) (0,-) (0,-) (0,-) (0,-)

15

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 5.

2
2

5 8 9

3
The shortest path from 1 to 5 is: (1,2,3,5) with cost 8
2

1
1

4
Unlabelled nodes Labelled nodes

Property of Distance and Predecessor Labels


The distance and predecessor labels inform us about not only the optimal path from s to t, but from s to every other node. 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

Node we are currently exploring


Iterat ion

Node 1 2 (,-) (1,1) (1,1) (1,1) (1,1) 3 (,-) (,-) (6,2) (6,2) (6,2) 4 (,-) (1,1) (1,1) (1,1) (1,1) 5 (,-) (,-) (9,2) (9,2) (8,3)

0 1 2 3 4

(0,-) (0,-) (0,-) (0,-) (0,-)

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 5.

2
2

5 8 9

3
The shortest path from 1 to 5 is: (1,2,3,5) with cost 8
2

1
1

4
Unlabelled nodes Labelled nodes

Property of Distance and Predecessor Labels


The distance and predecessor labels inform us about not only the optimal path from s to t, but from s to every other node. 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

Node we are currently exploring


Iterat ion

Node 1 2 (,-) (1,1) (1,1) (1,1) (1,1) 3 (,-) (,-) (6,2) (6,2) (6,2) 4 (,-) (1,1) (1,1) (1,1) (1,1) 5 (,-) (,-) (9,2) (9,2) (8,3)

0 1 2 3 4

(0,-) (0,-) (0,-) (0,-) (0,-)

16

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) 3 (,-) 4 (,-) 5 (,-) 6 (,-)

2 1
50

200

3
150

(0,-)

4
Unlabelled nodes Labelled nodes

40

Node we are currently exploring

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) (100,1) 3 (,-) (,-) 4 (,-) (200,1) 5 (,-) (,-) 6 (,-) (,-)

2
1
50

200

3
150

0 1

(0,-) (0,-)

4
Unlabelled nodes Labelled nodes

40

Node we are currently exploring

17

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) (100,1) (100,1) 3 (,-) (,-) (300,2) 4 (,-) (200,1) (150,2) 5 (,-) (,-) (200,2) 6 (,-) (,-) (,-)

2 1
50

200

3
150

0 1

(0,-) (0,-) (0,-)

4
Unlabelled nodes Labelled nodes

40

Node we are currently exploring

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) (100,1) (100,1) (100,1) 3 (,-) (,-) (300,2) (300,2) 4 (,-) (200,1) (150,2) (150,2) 5 (,-) (,-) (200,2) (190,4) 6 (,-) (,-) (,-) (,-)

2
1
50

200

3
150

0 1

(0,-) (0,-) (0,-) (0,-)

4
Unlabelled nodes Labelled nodes

40

2 3

Node we are currently exploring

18

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) (100,1) (100,1) (100,1) (100,1) 3 (,-) (,-) (300,2) (300,2) (300,2) 4 (,-) (200,1) (150,2) (150,2) (150,2) 5 (,-) (,-) (200,2) (190,4) (190,4) 6 (,-) (,-) (,-) (,-) (290,5)

2 1
50

200

3
150

0 1

(0,-) (0,-) (0,-) (0,-) (0,-)

4
Unlabelled nodes Labelled nodes

40

2 3 4

Node we are currently exploring

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) (100,1) (100,1) (100,1) (100,1) (100,1) 3 (,-) (,-) (300,2) (300,2) (300,2) (300,2) 4 (,-) (200,1) (150,2) (150,2) (150,2) (150,2) 5 (,-) (,-) (200,2) (190,4) (190,4) (190,4) 6 (,-) (,-) (,-) (,-) (290,5) (290,5)

2
1
50

200

3
150

0 1

(0,-) (0,-) (0,-) (0,-) (0,-) (0,-)

4
Unlabelled nodes Labelled nodes

40

2 3 4 5

Node we are currently exploring

19

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) (100,1) (100,1) (100,1) (100,1) (100,1) (100,1) 3 (,-) (,-) (300,2) (300,2) (300,2) (300,2) (300,2) 4 (,-) (200,1) (150,2) (150,2) (150,2) (150,2) (150,2) 5 (,-) (,-) (200,2) (190,4) (190,4) (190,4) (190,4) 6 (,-) (,-) (,-) (,-) (290,5) (290,5) (290,5)

2 1
50

200

3
150

0 1

(0,-) (0,-) (0,-) (0,-) (0,-) (0,-) (0,-)

4
Unlabelled nodes Labelled nodes

40

2 3 4 5 6

Node we are currently exploring

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) (100,1) (100,1) (100,1) (100,1) (100,1) (100,1) 3 (,-) (,-) (300,2) (300,2) (300,2) (300,2) (300,2) 4 (,-) (200,1) (150,2) (150,2) (150,2) (150,2) (150,2) 5 (,-) (,-) (200,2) (190,4) (190,4) (190,4) (190,4) 6 (,-) (,-) (,-) (,-) (290,5) (290,5) (290,5)

2
1
50

200

3
150

0 1

(0,-) (0,-) (0,-) (0,-) (0,-) (0,-) (0,-)

4
Unlabelled nodes Labelled nodes

40

2 3 4 5 6

Node we are currently exploring

The shortest path from 1 to 6 is: (1,2,4,5,6) with cost 290 Note: once a node is labelled, its distance and predecessor label is never changed. Hence, once a node is labelled, its distance label gives the shortest distance from s to that node. We could therefore have stopped at iteration 5.

20

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) (100,1) (100,1) (100,1) (100,1) (100,1) (100,1) 3 (,-) (,-) (300,2) (300,2) (300,2) (300,2) (300,2) 4 (,-) (200,1) (150,2) (150,2) (150,2) (150,2) (150,2) 5 (,-) (,-) (200,2) (190,4) (190,4) (190,4) (190,4) 6 (,-) (,-) (,-) (,-) (290,5) (290,5) (290,5)

2 1
50

200

3
150

0 1

(0,-) (0,-) (0,-) (0,-) (0,-) (0,-) (0,-)

4
Unlabelled nodes Labelled nodes

40

2 3 4 5 6

Node we are currently exploring

The shortest path from 1 to 6 is: (1,2,4,5,6) with cost 290 Note: once a node is labelled, its distance and predecessor label is never changed. Hence, once a node is labelled, its distance label gives the shortest distance from s to that node. We could therefore have stopped at iteration 5. Q. Does Dikstras algorithm always find the shortest path?

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) (100,1) (100,1) (100,1) (100,1) (100,1) (100,1) 3 (,-) (,-) (300,2) (300,2) (300,2) (300,2) (300,2) 4 (,-) (200,1) (150,2) (150,2) (150,2) (150,2) (150,2) 5 (,-) (,-) (200,2) (190,4) (190,4) (190,4) (190,4) 6 (,-) (,-) (,-) (,-) (290,5) (290,5) (290,5)

2
1
50

200

3
150

0 1

(0,-) (0,-) (0,-) (0,-) (0,-) (0,-) (0,-)

4
Unlabelled nodes Labelled nodes

40

2 3 4 5 6

Node we are currently exploring

The shortest path from 1 to 6 is: (1,2,4,5,6) with cost 290 Note: once a node is labelled, its distance and predecessor label is never changed. Hence, once a node is labelled, its distance label gives the shortest distance from s to that node. We could therefore have stopped at iteration 5. Q. Does Dikstras algorithm always find the shortest path? A. No.

21

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) 3 (,-) 4 (,-) 5 (,-) 6 (,-)

2 1
10

4
1

0 1

(0,-)

3
Unlabelled nodes Labelled nodes

-100

2 3 4 5 6

Node we are currently exploring

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) (1,1) 3 (,-) (,-) 4 (,-) (,-) 5 (,-) (,-) 6 (,-) (,-)

2
1
10

4
1

0 1

(0,-) (0,-)

3
Unlabelled nodes Labelled nodes

-100

2 3 4 5 6

Node we are currently exploring

22

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) (1,1) (1,1) 3 (,-) (,-) (11,2) 4 (,-) (,-) (2,2) 5 (,-) (,-) (,-) 6 (,-) (,-) (,-)

2 1
10

4
1

0 1

(0,-) (0,-) (0,-)

3
Unlabelled nodes Labelled nodes

-100

2 3 4 5 6

Node we are currently exploring

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) (1,1) (1,1) (1,1) 3 (,-) (,-) (11,2) (11,2) 4 (,-) (,-) (2,2) (2,2) 5 (,-) (,-) (,-) (,-) 6 (,-) (,-) (,-) (3,4)

2
1
10

4
1

0 1

(0,-) (0,-) (0,-) (0,-)

3
Unlabelled nodes Labelled nodes

-100

2 3 4 5 6

Node we are currently exploring

23

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) (1,1) (1,1) (1,1) (1,1) 3 (,-) (,-) (11,2) (11,2) (11,2) 4 (,-) (,-) (2,2) (2,2) (2,2) 5 (,-) (,-) (,-) (,-) (,-) 6 (,-) (,-) (,-) (3,4) (3,4)

2 1
10

4
1

0 1

(0,-) (0,-) (0,-) (0,-) (0,-)

3
Unlabelled nodes Labelled nodes

-100

2 3 4 5 6

Node we are currently exploring

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) (1,1) (1,1) (1,1) (1,1) (1,1) 3 (,-) (,-) (11,2) (11,2) (11,2) (11,2) 4 (,-) (,-) (2,2) (2,2) (2,2) (2,2) 5 (,-) (,-) (,-) (,-) (,-) (-89,3) 6 (,-) (,-) (,-) (3,4) (3,4) (3,4)

2
1
10

4
1

0 1

(0,-) (0,-) (0,-) (0,-) (0,-) (0,-)

3
Unlabelled nodes Labelled nodes

-100

2 3 4 5 6

Node we are currently exploring

24

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) (1,1) (1,1) (1,1) (1,1) (1,1) (1,1) 3 (,-) (,-) (11,2) (11,2) (11,2) (11,2) (11,2) 4 (,-) (,-) (2,2) (2,2) (2,2) (2,2) (-88,5) 5 (,-) (,-) (,-) (,-) (,-) (-89,3) (-89,3) 6 (,-) (,-) (,-) (3,4) (3,4) (3,4) (3,4)

2 1
10

4
1

0 1

(0,-) (0,-) (0,-) (0,-) (0,-) (0,-) (0,-)

3
Unlabelled nodes Labelled nodes

-100

2 3 4 5 6

Node we are currently exploring

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.


Iteration

Node 1 2 (,-) (1,1) (1,1) (1,1) (1,1) (1,1) (1,1) 3 (,-) (,-) (11,2) (11,2) (11,2) (11,2) (11,2) 4 (,-) (,-) (2,2) (2,2) (2,2) (2,2) (-88,5) 5 (,-) (,-) (,-) (,-) (,-) (-89,3) (-89,3) 6 (,-) (,-) (,-) (3,4) (3,4) (3,4) (3,4)

2
1
10

4
1

0 1

(0,-) (0,-) (0,-) (0,-) (0,-) (0,-) (0,-)

3
Unlabelled nodes Labelled nodes

-100

2 3 4 5 6

Node we are currently exploring

Q. Does Dikstras algorithm always find the shortest path? A. No. Not if there are negative cost arcs. Q. Are there other algorithms that can find the shortest path when there are negative cost arcs?

25

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.

2 1
50

200

3
150

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

40

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

Q. What is the shortest path from 1 to 6?

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.

2
1
50

200

3
150

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

40

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. 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?

26

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.

2 1
50

200

3
150

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

40

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. 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? Q. Are there algorithms that can find the shortest path when there are negative cost arcs? A. Yes, there are efficient algorithms when there are no negative cost cycles. Q. Are there algorithms that can find the shortest path that does not contain any cycles?

Lec 8

Network Models: Shortest Path Algorithms

Find the shortest path from node 1 to node 6.

2
1
50

200

3
150

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

40

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. 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? Q. Are there algorithms that can find the shortest path when there are negative cost arcs? A. Yes, there are efficient algorithms when there are no negative cost cycles. Q. Are there algorithms that can find the shortest path that does not contain any cycles? A. Yes but they are not efficient. This can be a very difficult problem.

27

Lec 8

Network Models: Shortest Path Algorithms

Practical variants of Dijkstras algorithm

Dijkstras algorithm on a road network

Lec 8

Network Models: Shortest Path Algorithms

Practical variants of Dijkstras algorithm

Bi-directional Dijkstras algorithm on a road network

28

Lec 8

Network Models: Shortest Path Algorithms

Practical variants of Dijkstras algorithm

Dijkstras algorithm with A* search on a road network

Lec 8

Network Models: Shortest Path Algorithms

Practical variants of Dijkstras algorithm

Dijkstra

Bi-directional Dijkstra

Bi-directional Dijkstra + A*

29

Lec 8

Network Models: Shortest Path Algorithms

Practical variants of Dijkstras algorithm

Hierarchy in a road network

Lec 8

Network Models: Shortest Path Algorithms

Practical variants of Dijkstras algorithm

Bi-directional Dijkstras algorithm + A* + Hierarchy on a road network

30

Lec 8

Network Models: Flows in Directed Graphs


Flow in Directed Graph
1

4 1 6

3
4

2
3

Think of arcs in network as conduits carrying flow. Given a network with nodes N and arcs A, for each arc e = (i,j) in A we 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 vector

Flow
For a graph with nodes N and arcs A, the vector X is called a flow.

Lec 8

Network Models: Flows in Directed Graphs


Flow in Directed Graph
1

4 1 6

3
4

2
3

Net flow in/out of a node


The net flow in/out of a node is the total amount of flow entering/leaving the node.

Q. What is the net flow into node 3? 8 Q. What is the net flow into node 4? 4 Q. What is the net flow out of node 3? 0 Q. What is the net flow out of node 4? 6

31

Lec 8

Network Models: Flows in Directed Graphs


Bounds on flow [0,5]
1 2

[1,3]
4

[0,4] [0,5]
3

Bounds on flow
For each arc e, we may be given a lower and/or upper bound le and ue respectively 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) Note: If a lower bound is not given then we can assume it is 0, i.e., we do not have ve flow.

Lec 8

Network Models: Flows in Directed Graphs


Bounds on flow [0,5]
1 2

[1,3]
4

[0,4] [0,5]
3

Feasible flow from source to sink


A flow from a source node s to a sink node t is feasible if: Flow balance requirement No leaks 1. for all nodes except s and 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.

32

Lec 8

Network Models: Flows in Directed Graphs


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 bounds are not satisfied on arcs (2,4) and (4,3). Bounds on flow [0,5]
1 2 1

Flow in Directed Graph 4 1 6


3 2

[1,3]
4

[0,4] [0,5]
3

3
4

Feasible flow from source to sink


A flow from a source node s to a sink node t is feasible if: 1. for all nodes except s and 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


Bounds on flow [0,5]
1 2

Find three feasible flows from node 1 to node 3:

[1,3]
4

[0,4] [0,5] Flow 2


3

Flow 1
1

Flow 3
2 1

2 2 3

3 2 4

5 2 5

1
4

0
3

2
4

1
3

3
4

3
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. This net flow out of s (or into t) is the amount of flow that is pushed through from s to t.

33

Lec 8

Network Models: Flows in Directed Graphs


Bounds on flow [0,5]
1 2

Find three feasible flows from node 1 to node 3:

[1,3]
4

[0,4] [0,5] Flow 2


3

Flow 1
1

Flow 3
2 1

2 2 3

3 2 4

5 2 5

1
4

0
3

2
4

1
3

3
4

3
3

Net flow out of s = net flow into t = 3

Net flow out of s = net flow into t = 5

Net flow out of s = net flow into t = 5

Flow from s to t = 3

Flow from s to t = 5

Flow from s to t = 8

Lec 8

Network Models: Flows in Directed Graphs


The Maximum Flow Problem
The maximum flow problem is one of finding a feasible flow from a node s to a node t where the net flow leaving s (or entering t) is the maximum possible, i.e. finding the maximum amount of flow that can be pushed through from s to t.

Flow 1
1

Flow 2
2 1

Flow 3
2 1

2 2 3

3 2 4

5 2 5

1
4

0
3

2
4

1
3

3
4

3
3

Net flow out of s = net flow into t = 3

Net flow out of s = net flow into t = 5

Net flow out of s = net flow into t = 5

Flow from s to t = 3

Flow from s to t = 5

Flow from s to t = 8

Q. Is 8 the maximum possible flow from s to t? Yes (why?)

34

Lec 8

Network Models: Applications of Maximum Flow


Transporting Natural Gas through Pipelines
Western Australia Natural Gas Co. has developed a pipeline network to transport Liquefied Natural Gas (LNG) from exploration fields to refineries and other locations. There are 10 pipelines in the network (see below). The maximum flow rate 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 10 1 8 3

12

10

6 12

Maximum flow rate in L/ hour.


8

10 10

35

Вам также может понравиться