Loading...

PPT – EMIS 8374 Shortest Path Problems: Introduction Updated 9 February 2008 PowerPoint presentation | free to view - id: 260560-ZDc1Z

The Adobe Flash plugin is needed to view this content

EMIS 8374 Shortest Path Problems Introduction

Updated 9 February 2008

Assumptions

- All arc costs (cij) are integers.
- The network contains a directed path from the

source node to every other node in the network. - No negative (directed) cycles

A Network with Negative Cycles

3

2

4

1

1

2

1

6

-3

3

-3

3

1

3

5

7

Shortest Path Problems

- Acyclic Networks

Topological Ordering

- Renumber the nodes so that for every arc (i,j), i

lt j - Let k 1
- Find a node i with in-degree 0
- If no such node then quit (no T.O.)
- Else let order(i) k, k k1
- Remove i and all incident arcs (i,j)
- Goto Step 2

A Network with no Topological Ordering

Theorem

- A network is acyclic if and only if it has a

topological ordering of its nodes. - Complexity of T.O. Algorithm
- O(m)

T.O. Algorithm

2

4

1

6

1

3

5

T.O. Algorithm

2

T.O. Algorithm

2

4

6

5

3

T.O. Algorithm

4

5

2

4

6

6

Topological Ordering

4

5

2

4

1

6

1

6

3

5

2

3

The Reaching Algorithm Initialization

- Number the nodes by a topological ordering.
- Let d(s) 0 d(i) ? for all other nodes.
- d(i) indicates the length of the shortest path

found so far from s to i. - When d(i) ?, it means we have not yet found a

path from s to i. - Pred(s) 0

The Reaching Algorithm Main Loop

- for i 1 to n do
- for (i,j) in A(i) do
- if d(j) gt d(i) cij then
- begin
- let d(j) d(i) cij
- pred(j) i
- end

Reaching Algorithm Example

?

?

2

4

5

7

1

1

6

2

?

0

1

6

5

2

3

-2

?

?

Examine A(1)

7

?

?

2

4

5

7

1

1

6

2

?

0

1

6

5

2

3

-2

?

?

5

Examine A(2)

7

6

?

2

4

5

7

1

1

6

2

?

0

1

6

5

2

3

-2

?

3

5

Examine A(3)

5

6

?

2

4

5

7

1

1

6

2

?

9

0

1

6

5

2

3

-2

3

5

Examine A(4)

7

5

?

2

4

5

7

1

1

6

2

9

0

1

6

5

2

3

-2

3

5

Examine A(5)

7

5

2

4

5

7

1

1

6

2

9

8

0

1

6

5

2

3

-2

3

5

Examine A(5)

7

5

2

4

5

7

1

1

6

2

8

0

1

6

5

2

3

-2

3

5

Complexity of the Reaching Algorithm

- for i 1 to n do
- for (i,j) in A(i) do
- if d(j) gt d(i) cij then
- begin
- let d(j) d(i) cij
- pred(j) i
- end
- Outer loop (for i i1) executes n times.
- Examining an arc is O(1).
- Comparison, updates of d(j) and pred(j) are O(1).
- Each arc is examined once.
- O(nm) O(m)

Shortest Path Tree

- We can store a set of shortest paths from s to

all other nodes in a tree - Use the pred(j) label to keep track of the last

arc (i,j) that sets d(j) d(i) cij

Shortest Path Tree

7

6

7

5

?

2

4

5

1

1

6

2

?

8

0

5

2

3

-2

?

5

3

?