|
6 | 6 | g3 = path_graph(5) |
7 | 7 | d = [0 1 2 3 4; 1 0 1 0 1; 2 1 0 11 12; 3 0 11 0 5; 4 1 19 5 0] |
8 | 8 |
|
9 | | - for g in testgraphs(g3) |
10 | | - z = floyd_warshall_shortest_paths(g, d) |
11 | | - zp = @inferred(Parallel.dijkstra_shortest_paths(g, collect(1:5), d)) |
12 | | - @test all(isapprox(z.dists, zp.dists)) |
| 9 | + for parallel in [:threads, :distributed] |
| 10 | + for g in testgraphs(g3) |
| 11 | + z = floyd_warshall_shortest_paths(g, d) |
| 12 | + zp = @inferred(Parallel.dijkstra_shortest_paths(g, collect(1:5), d; parallel)) |
| 13 | + @test all(isapprox(z.dists, zp.dists)) |
13 | 14 |
|
14 | | - for i in 1:5 |
15 | | - state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true) |
16 | | - for j in 1:5 |
17 | | - if zp.parents[i, j] != 0 |
18 | | - @test zp.parents[i, j] in state.predecessors[j] |
| 15 | + for i in 1:5 |
| 16 | + state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true) |
| 17 | + for j in 1:5 |
| 18 | + if zp.parents[i, j] != 0 |
| 19 | + @test zp.parents[i, j] in state.predecessors[j] |
| 20 | + end |
19 | 21 | end |
20 | 22 | end |
21 | | - end |
22 | 23 |
|
23 | | - z = floyd_warshall_shortest_paths(g) |
24 | | - zp = @inferred(Parallel.dijkstra_shortest_paths(g)) |
25 | | - @test all(isapprox(z.dists, zp.dists)) |
| 24 | + z = floyd_warshall_shortest_paths(g) |
| 25 | + zp = @inferred(Parallel.dijkstra_shortest_paths(g; parallel)) |
| 26 | + @test all(isapprox(z.dists, zp.dists)) |
26 | 27 |
|
27 | | - for i in 1:5 |
28 | | - state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true) |
29 | | - for j in 1:5 |
30 | | - if zp.parents[i, j] != 0 |
31 | | - @test zp.parents[i, j] in state.predecessors[j] |
| 28 | + for i in 1:5 |
| 29 | + state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true) |
| 30 | + for j in 1:5 |
| 31 | + if zp.parents[i, j] != 0 |
| 32 | + @test zp.parents[i, j] in state.predecessors[j] |
| 33 | + end |
32 | 34 | end |
33 | 35 | end |
34 | | - end |
35 | 36 |
|
36 | | - z = floyd_warshall_shortest_paths(g) |
37 | | - zp = @inferred(Parallel.dijkstra_shortest_paths(g, [1, 2])) |
38 | | - @test all(isapprox(z.dists[1:2, :], zp.dists)) |
| 37 | + z = floyd_warshall_shortest_paths(g) |
| 38 | + zp = @inferred(Parallel.dijkstra_shortest_paths(g, [1, 2]; parallel)) |
| 39 | + @test all(isapprox(z.dists[1:2, :], zp.dists)) |
39 | 40 |
|
40 | | - for i in 1:2 |
41 | | - state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true) |
42 | | - for j in 1:5 |
43 | | - if zp.parents[i, j] != 0 |
44 | | - @test zp.parents[i, j] in state.predecessors[j] |
| 41 | + for i in 1:2 |
| 42 | + state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true) |
| 43 | + for j in 1:5 |
| 44 | + if zp.parents[i, j] != 0 |
| 45 | + @test zp.parents[i, j] in state.predecessors[j] |
| 46 | + end |
45 | 47 | end |
46 | 48 | end |
47 | 49 | end |
|
51 | 53 | g3 = path_digraph(5) |
52 | 54 | d = float([0 1 2 3 4; 5 0 6 7 8; 9 10 0 11 12; 13 14 15 0 16; 17 18 19 20 0]) |
53 | 55 |
|
54 | | - for g in testdigraphs(g3) |
55 | | - z = floyd_warshall_shortest_paths(g, d) |
56 | | - zp = @inferred(Parallel.dijkstra_shortest_paths(g, collect(1:5), d)) |
57 | | - @test all(isapprox(z.dists, zp.dists)) |
| 56 | + for parallel in [:threads, :distributed] |
| 57 | + for g in testdigraphs(g3) |
| 58 | + z = floyd_warshall_shortest_paths(g, d) |
| 59 | + zp = @inferred(Parallel.dijkstra_shortest_paths(g, collect(1:5), d; parallel)) |
| 60 | + @test all(isapprox(z.dists, zp.dists)) |
58 | 61 |
|
59 | | - for i in 1:5 |
60 | | - state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true) |
61 | | - for j in 1:5 |
62 | | - if z.parents[i, j] != 0 |
63 | | - @test zp.parents[i, j] in state.predecessors[j] |
| 62 | + for i in 1:5 |
| 63 | + state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true) |
| 64 | + for j in 1:5 |
| 65 | + if z.parents[i, j] != 0 |
| 66 | + @test zp.parents[i, j] in state.predecessors[j] |
| 67 | + end |
64 | 68 | end |
65 | 69 | end |
66 | | - end |
67 | 70 |
|
68 | | - z = floyd_warshall_shortest_paths(g) |
69 | | - zp = @inferred(Parallel.dijkstra_shortest_paths(g)) |
70 | | - @test all(isapprox(z.dists, zp.dists)) |
| 71 | + z = floyd_warshall_shortest_paths(g) |
| 72 | + zp = @inferred(Parallel.dijkstra_shortest_paths(g; parallel)) |
| 73 | + @test all(isapprox(z.dists, zp.dists)) |
71 | 74 |
|
72 | | - for i in 1:5 |
73 | | - state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true) |
74 | | - for j in 1:5 |
75 | | - if zp.parents[i, j] != 0 |
76 | | - @test zp.parents[i, j] in state.predecessors[j] |
| 75 | + for i in 1:5 |
| 76 | + state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true) |
| 77 | + for j in 1:5 |
| 78 | + if zp.parents[i, j] != 0 |
| 79 | + @test zp.parents[i, j] in state.predecessors[j] |
| 80 | + end |
77 | 81 | end |
78 | 82 | end |
79 | | - end |
80 | 83 |
|
81 | | - z = floyd_warshall_shortest_paths(g) |
82 | | - zp = @inferred(Parallel.dijkstra_shortest_paths(g, [1, 2])) |
83 | | - @test all(isapprox(z.dists[1:2, :], zp.dists)) |
| 84 | + z = floyd_warshall_shortest_paths(g) |
| 85 | + zp = @inferred(Parallel.dijkstra_shortest_paths(g, [1, 2]; parallel)) |
| 86 | + @test all(isapprox(z.dists[1:2, :], zp.dists)) |
84 | 87 |
|
85 | | - for i in 1:2 |
86 | | - state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true) |
87 | | - for j in 1:5 |
88 | | - if zp.parents[i, j] != 0 |
89 | | - @test zp.parents[i, j] in state.predecessors[j] |
| 88 | + for i in 1:2 |
| 89 | + state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true) |
| 90 | + for j in 1:5 |
| 91 | + if zp.parents[i, j] != 0 |
| 92 | + @test zp.parents[i, j] in state.predecessors[j] |
| 93 | + end |
90 | 94 | end |
91 | 95 | end |
92 | 96 | end |
|
0 commit comments