• Aucun résultat trouvé

Episode 22 – The shortest path problem European section – Season 2

N/A
N/A
Protected

Academic year: 2022

Partager "Episode 22 – The shortest path problem European section – Season 2"

Copied!
19
0
0

Texte intégral

(1)

Episode 22 – The shortest path problem

European section – Season 2

(2)

A weighted graph

2

3

5

6 A

B

C

D

b b b b

(3)

The shortest path problem

(4)

Task sheet #1

2

5

3 1 2

6 4

bA

bB

b C

b

D

b E

(5)

Task sheet #1

8

3

5 2

3 2

3

5 2

2

bA

b

B

b C

bD

bE

bF

bG

(6)

Task sheet #1

4 3

5 5 3

4 2

4 2

2 1

5 3 3

5 4 4

4

3

b A

b B

b C

bD

bE

bF

bG

b

H

b I

bJ

b K b L

bM

(7)

Dijkstra’s algorithm

Vertex we are starting from : initial vertex.

Distance of a vertex Y : distance from the initial vertex to it.

(8)

Dijkstra’s algorithm

Vertex we are starting from : initial vertex.

Distance of a vertex Y : distance from the initial vertex to it.

1 Assign to every vertex a distance value : 0 for the initial vertex and∞) for all other vertices.

(9)

Dijkstra’s algorithm

Vertex we are starting from : initial vertex.

Distance of a vertex Y : distance from the initial vertex to it.

1 Assign to every vertex a distance value : 0 for the initial vertex and∞) for all other vertices.

2 Mark all vertices as unvisited. Set initial vertex as current.

(10)

Dijkstra’s algorithm

Vertex we are starting from : initial vertex.

Distance of a vertex Y : distance from the initial vertex to it.

1 Assign to every vertex a distance value : 0 for the initial vertex and∞) for all other vertices.

2 Mark all vertices as unvisited. Set initial vertex as current.

3 For current node, consider all its unvisited neighbours and calculate their distance. If this distance is less than the previously recorded distance, overwrite the distance.

(11)

Dijkstra’s algorithm

Vertex we are starting from : initial vertex.

Distance of a vertex Y : distance from the initial vertex to it.

1 Assign to every vertex a distance value : 0 for the initial vertex and∞) for all other vertices.

2 Mark all vertices as unvisited. Set initial vertex as current.

3 For current node, consider all its unvisited neighbours and calculate their distance. If this distance is less than the previously recorded distance, overwrite the distance.

4 When all neighbours of the current node have been considered, mark it as visited.

(12)

Dijkstra’s algorithm

Vertex we are starting from : initial vertex.

Distance of a vertex Y : distance from the initial vertex to it.

1 Assign to every vertex a distance value : 0 for the initial vertex and∞) for all other vertices.

2 Mark all vertices as unvisited. Set initial vertex as current.

3 For current node, consider all its unvisited neighbours and calculate their distance. If this distance is less than the previously recorded distance, overwrite the distance.

4 When all neighbours of the current node have been considered, mark it as visited.

5 Set the unvisited vertex with the smallest distance (from the initial node) as the next current vertex and continue from step 3.

(13)

Dijkstra’s algorithm : An example

2

3

5

6 A(0)

B(∞)

C(∞)

D(∞)

b b b b

(14)

Dijkstra’s algorithm : An example

2

3

5

6 A(0)

B(2)

C(3)

D(∞)

b b b b

(15)

Dijkstra’s algorithm : An example

2

3

5

6 A(0)

B(2)

C(3)

D(7)

b b b b

(16)

Dijkstra’s algorithm : An example

2

3

5

6 A(0)

B(2)

C(3)

D(7)

b b b b

(17)

Task sheet #2

(18)

Task sheet #3

(19)

Dijkstra’s algorithm in pseudo-code

1 function Dijkstra(Graph, source):

2 for each vertex v in Graph: // Initializations 3 dist[v] := infinity

// Unknown distance function from source to v 4 previous[v] := undefined

// Previous node in optimal path from source 5 dist[source] := 0

// Distance from source to source 6 Q := the set of all nodes in Graph

// All nodes in the graph are unoptimized - thus are in Q 7 while Q is not empty: // The main loop

8 u := vertex in Q with smallest dist[]

9 if dist[u] = infinity:

10 break

// all remaining vertices are inaccessible 11 remove u from Q

12 for each neighbor v of u:

// where v has not yet been removed from Q.

13 alt := dist[u] + dist_between(u, v) 14 if alt < dist[v]: // Relax (u,v,a)

15 dist[v] := alt

Références

Documents relatifs

The fourth column contains the value of the objective function obtained by the branch-and-bound proce- dure (BB), actually, the optimal solution.. The fifth column gives the

Table 3 shows the computational results on the 104 traditional instances obtained by our PR-VSP algorithm along with the results of four reference algorithms: breakout local

administrators suspect that the two consultants do not interpret and apply the scheme in the same way, resulting in differences in scores between the exams scored by the

Episode 05 – Venn diagrams... Episode 05 –

Let R be the set of all sets that don’t contain themselves,

Revisit Proposition 5 and remark that if m &lt; (log 1.5874/ log 3)opt(G) ≈ 0.42opt(G), then the parameterized algorithm of Proposition 5 runs faster than that of Proposition 4

More precisely, Alice follows the strategy S, with the slight change that if, at some turn, she is supposed to colour an edge that she has already coloured (such as uv), then

Given an n-vertex and m-edge non-negatively real-weighted graph G = (V, E, w), whose vertices are partitioned into a set of k clusters, a clustered network design problem on G