Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/ordering/pgr_sloanOrdering.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The Sloan ordering algorithm reorders the vertices of a graph to reduce bandwidt
*Aims to mininimize bandwidth (maximum difference between connected vertex indices.
*The implementation is for undirected graphs
*Typically produces better orderings than simple breadth-first approaches.
*Run time is 0.115846 seconds.
|Boost| Boost Graph inside

Signatures
Expand Down
38 changes: 38 additions & 0 deletions docqueries/ordering/sloanOrdering.pg
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,41 @@ SELECT * FROM pgr_sloanOrdering(
);
/* -- q2 */

CREATE TABLE example_edges1 (
id SERIAL PRIMARY KEY,
source INTEGER,
target INTEGER,
cost DOUBLE PRECISION,
reverse_cost DOUBLE PRECISION
);
/* --q3 */
INSERT INTO example_edges1 (source, target, cost, reverse_cost) VALUES
(4, 7, 1, 1),
(7, 4, 1, 1),
(7, 9, 1, 1),
(9, 7, 1, 1),
(7, 0, 1, 1),
(0, 7, 1, 1),
(0, 2, 1, 1),
(2, 0, 1, 1),
(2, 5, 1, 1),
(5, 2, 1, 1),
(5, 9, 1, 1),
(9, 5, 1, 1),
(9, 8, 1, 1),
(8, 9, 1, 1),
(9, 1, 1, 1),
(1, 9, 1, 1),
(5, 1, 1, 1),
(1, 5, 1, 1),
(9, 6, 1, 1),
(6, 9, 1, 1),
(6, 3, 1, 1),
(3, 6, 1, 1),
(1, 3, 1, 1),
(3, 1, 1, 1);
/* --q4 */
SELECT * FROM pgr_sloanOrdering(
'SELECT id, source, target, cost, reverse_cost FROM example_edges1'
);
/* --q5 */
70 changes: 62 additions & 8 deletions docqueries/ordering/sloanOrdering.result
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,77 @@ SELECT * FROM pgr_sloanOrdering(
-----+------
1 | 1
2 | 3
3 | 6
4 | 5
5 | 10
3 | 8
4 | 9
5 | 12
6 | 7
7 | 9
8 | 15
9 | 8
7 | 5
8 | 17
9 | 6
10 | 11
11 | 16
12 | 12
13 | 17
12 | 10
13 | 15
14 | 1
15 | 1
16 | 1
17 | 1
(17 rows)

/* -- q2 */
CREATE TABLE example_edges1 (
id SERIAL PRIMARY KEY,
source INTEGER,
target INTEGER,
cost DOUBLE PRECISION,
reverse_cost DOUBLE PRECISION
);
CREATE TABLE
/* --q3 */
INSERT INTO example_edges1 (source, target, cost, reverse_cost) VALUES
(4, 7, 1, 1),
(7, 4, 1, 1),
(7, 9, 1, 1),
(9, 7, 1, 1),
(7, 0, 1, 1),
(0, 7, 1, 1),
(0, 2, 1, 1),
(2, 0, 1, 1),
(2, 5, 1, 1),
(5, 2, 1, 1),
(5, 9, 1, 1),
(9, 5, 1, 1),
(9, 8, 1, 1),
(8, 9, 1, 1),
(9, 1, 1, 1),
(1, 9, 1, 1),
(5, 1, 1, 1),
(1, 5, 1, 1),
(9, 6, 1, 1),
(6, 9, 1, 1),
(6, 3, 1, 1),
(3, 6, 1, 1),
(1, 3, 1, 1),
(3, 1, 1, 1);
INSERT 0 24
/* --q4 */
SELECT * FROM pgr_sloanOrdering(
'SELECT id, source, target, cost, reverse_cost FROM example_edges1'
);
seq | node
-----+------
1 | 4
2 | 0
3 | 2
4 | 7
5 | 8
6 | 5
7 | 9
8 | 3
9 | 1
10 | 6
(10 rows)

/* --q5 */
ROLLBACK;
ROLLBACK
6 changes: 6 additions & 0 deletions src/ordering/ordering_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ do_ordering(

std::vector<int64_t> results;

#if 0
pgrouting::UndirectedGraph undigraph;
#else
auto vertices(pgrouting::extract_vertices(edges));
pgrouting::UndirectedGraph undigraph(vertices);
#endif
undigraph.insert_edges(edges);

// log << undigraph;
if (which == 0) {
results = sloanOrdering(undigraph);
}
Expand Down
Loading