Skip to content

Commit f7bee7b

Browse files
authored
Merge pull request pgRouting#482 from bipashabg/week-11-sloanordering
week 11 sloan ordering
2 parents aa4d7ef + 423aa90 commit f7bee7b

File tree

4 files changed

+107
-8
lines changed

4 files changed

+107
-8
lines changed

doc/ordering/pgr_sloanOrdering.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The Sloan ordering algorithm reorders the vertices of a graph to reduce bandwidt
4040
*Aims to mininimize bandwidth (maximum difference between connected vertex indices.
4141
*The implementation is for undirected graphs
4242
*Typically produces better orderings than simple breadth-first approaches.
43+
*Run time is 0.115846 seconds.
4344
|Boost| Boost Graph inside
4445
4546
Signatures

docqueries/ordering/sloanOrdering.pg

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,41 @@ SELECT * FROM pgr_sloanOrdering(
66
);
77
/* -- q2 */
88

9+
CREATE TABLE example_edges1 (
10+
id SERIAL PRIMARY KEY,
11+
source INTEGER,
12+
target INTEGER,
13+
cost DOUBLE PRECISION,
14+
reverse_cost DOUBLE PRECISION
15+
);
16+
/* --q3 */
17+
INSERT INTO example_edges1 (source, target, cost, reverse_cost) VALUES
18+
(4, 7, 1, 1),
19+
(7, 4, 1, 1),
20+
(7, 9, 1, 1),
21+
(9, 7, 1, 1),
22+
(7, 0, 1, 1),
23+
(0, 7, 1, 1),
24+
(0, 2, 1, 1),
25+
(2, 0, 1, 1),
26+
(2, 5, 1, 1),
27+
(5, 2, 1, 1),
28+
(5, 9, 1, 1),
29+
(9, 5, 1, 1),
30+
(9, 8, 1, 1),
31+
(8, 9, 1, 1),
32+
(9, 1, 1, 1),
33+
(1, 9, 1, 1),
34+
(5, 1, 1, 1),
35+
(1, 5, 1, 1),
36+
(9, 6, 1, 1),
37+
(6, 9, 1, 1),
38+
(6, 3, 1, 1),
39+
(3, 6, 1, 1),
40+
(1, 3, 1, 1),
41+
(3, 1, 1, 1);
42+
/* --q4 */
43+
SELECT * FROM pgr_sloanOrdering(
44+
'SELECT id, source, target, cost, reverse_cost FROM example_edges1'
45+
);
46+
/* --q5 */

docqueries/ordering/sloanOrdering.result

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,77 @@ SELECT * FROM pgr_sloanOrdering(
1010
-----+------
1111
1 | 1
1212
2 | 3
13-
3 | 6
14-
4 | 5
15-
5 | 10
13+
3 | 8
14+
4 | 9
15+
5 | 12
1616
6 | 7
17-
7 | 9
18-
8 | 15
19-
9 | 8
17+
7 | 5
18+
8 | 17
19+
9 | 6
2020
10 | 11
2121
11 | 16
22-
12 | 12
23-
13 | 17
22+
12 | 10
23+
13 | 15
2424
14 | 1
2525
15 | 1
2626
16 | 1
2727
17 | 1
2828
(17 rows)
2929

3030
/* -- q2 */
31+
CREATE TABLE example_edges1 (
32+
id SERIAL PRIMARY KEY,
33+
source INTEGER,
34+
target INTEGER,
35+
cost DOUBLE PRECISION,
36+
reverse_cost DOUBLE PRECISION
37+
);
38+
CREATE TABLE
39+
/* --q3 */
40+
INSERT INTO example_edges1 (source, target, cost, reverse_cost) VALUES
41+
(4, 7, 1, 1),
42+
(7, 4, 1, 1),
43+
(7, 9, 1, 1),
44+
(9, 7, 1, 1),
45+
(7, 0, 1, 1),
46+
(0, 7, 1, 1),
47+
(0, 2, 1, 1),
48+
(2, 0, 1, 1),
49+
(2, 5, 1, 1),
50+
(5, 2, 1, 1),
51+
(5, 9, 1, 1),
52+
(9, 5, 1, 1),
53+
(9, 8, 1, 1),
54+
(8, 9, 1, 1),
55+
(9, 1, 1, 1),
56+
(1, 9, 1, 1),
57+
(5, 1, 1, 1),
58+
(1, 5, 1, 1),
59+
(9, 6, 1, 1),
60+
(6, 9, 1, 1),
61+
(6, 3, 1, 1),
62+
(3, 6, 1, 1),
63+
(1, 3, 1, 1),
64+
(3, 1, 1, 1);
65+
INSERT 0 24
66+
/* --q4 */
67+
SELECT * FROM pgr_sloanOrdering(
68+
'SELECT id, source, target, cost, reverse_cost FROM example_edges1'
69+
);
70+
seq | node
71+
-----+------
72+
1 | 4
73+
2 | 0
74+
3 | 2
75+
4 | 7
76+
5 | 8
77+
6 | 5
78+
7 | 9
79+
8 | 3
80+
9 | 1
81+
10 | 6
82+
(10 rows)
83+
84+
/* --q5 */
3185
ROLLBACK;
3286
ROLLBACK

src/ordering/ordering_driver.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,15 @@ do_ordering(
8989

9090
std::vector<int64_t> results;
9191

92+
#if 0
9293
pgrouting::UndirectedGraph undigraph;
94+
#else
95+
auto vertices(pgrouting::extract_vertices(edges));
96+
pgrouting::UndirectedGraph undigraph(vertices);
97+
#endif
9398
undigraph.insert_edges(edges);
9499

100+
// log << undigraph;
95101
if (which == 0) {
96102
results = sloanOrdering(undigraph);
97103
}

0 commit comments

Comments
 (0)