Skip to content

Commit 4956c27

Browse files
authored
Merge pull request pgRouting#457 from bipashabg/week-4-sloanordering
Week 4 sloanordering
2 parents 7494831 + de1f21a commit 4956c27

File tree

5 files changed

+194
-205
lines changed

5 files changed

+194
-205
lines changed

doc/ordering/ordering-family.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Ordering - Family of functions
2222
.. official-start
2323
2424
* :doc:`pgr_cuthillMckeeOrdering` - Return reverse Cuthill-McKee ordering of an undirected graph.
25-
* :doc:`pgr_sloanOrdering` - Return sloanordering of an undirected graph.
25+
* :doc:`pgr_sloanOrdering` - Return sloan ordering of an undirected graph.
2626
* :doc:`pgr_topologicalSort` - Linear ordering of the vertices for directed
2727
acyclic graph.
2828

include/ordering/ordering.hpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*PGR-GNU*****************************************************************
2+
File: ordering.hpp
3+
4+
Generated with Template by:
5+
Copyright (c) 2015 pgRouting developers
6+
Mail: project@pgrouting.org
7+
8+
Developer:
9+
Copyright (c) 2025 Bipasha Gayary
10+
Mail: bipashagayary at gmail.com
11+
12+
------
13+
14+
This program is free software; you can redistribute it and/or modify
15+
it under the terms of the GNU General Public License as published by
16+
the Free Software Foundation; either version 2 of the License, or
17+
(at your option) any later version.
18+
19+
This program is distributed in the hope that it will be useful,
20+
but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
GNU General Public License for more details.
23+
24+
You should have received a copy of the GNU General Public License
25+
along with this program; if not, write to the Free Software
26+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27+
28+
********************************************************************PGR-GNU*/
29+
30+
#ifndef INCLUDE_ORDERING_ORDERING_HPP_
31+
#define INCLUDE_ORDERING_ORDERING_HPP_
32+
#pragma once
33+
34+
#include <vector>
35+
#include <limits>
36+
#include <iterator>
37+
38+
39+
#include <boost/config.hpp>
40+
#include <boost/graph/adjacency_list.hpp>
41+
#include <boost/property_map/property_map.hpp>
42+
#include <boost/graph/sloan_ordering.hpp>
43+
44+
#include "cpp_common/base_graph.hpp"
45+
#include "cpp_common/interruption.hpp"
46+
47+
48+
namespace pgrouting {
49+
namespace detail {
50+
51+
template <typename T>
52+
struct inf_plus {
53+
T operator()(const T& a, const T& b) const {
54+
T inf = (std::numeric_limits<T>::max)();
55+
if (a == inf || b == inf) return inf;
56+
return a + b;
57+
}
58+
};
59+
60+
} // namespace detail
61+
62+
63+
template <class G>
64+
std::vector<std::vector<int64_t>>
65+
sloan(G &graph) {
66+
67+
CHECK_FOR_INTERRUPTS();
68+
69+
std::pair<typename G::V, typename G::V> starting_nodes =
70+
boost::sloan_starting_nodes(graph.graph);
71+
72+
std::vector<typename G::V> inv_perm(graph.num_vertices());
73+
74+
boost::sloan_ordering(
75+
graph.graph,
76+
inv_perm.begin(),
77+
boost::get(boost::vertex_color_t(), graph.graph),
78+
boost::make_degree_map(graph.graph),
79+
starting_nodes.first,
80+
starting_nodes.second
81+
);
82+
83+
CHECK_FOR_INTERRUPTS();
84+
85+
std::vector<int64_t> result;
86+
result.reserve(inv_perm.size());
87+
88+
for (const auto& vertex_desc : inv_perm) {
89+
result.push_back(graph[vertex_desc].id);
90+
}
91+
92+
return result;
93+
} // namespace ordering
94+
95+
} // namespace pgrouting
96+
97+
#endif // INCLUDE_ORDERING_ORDERING_HPP_

include/ordering/sloanOrdering.hpp

Lines changed: 0 additions & 175 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
/*PGR-GNU*****************************************************************
3+
4+
Copyright (c) 2018 pgRouting developers
5+
Mail: project@pgrouting.org
6+
7+
------
8+
This program is free software; you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation; either version 2 of the License, or
11+
(at your option) any later version.
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
You should have received a copy of the GNU General Public License
17+
along with this program; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
********************************************************************PGR-GNU*/
20+
BEGIN;
21+
22+
SELECT CASE WHEN min_version('4.0.0') THEN plan(1) ELSE plan(5) END;
23+
24+
CREATE OR REPLACE FUNCTION types_check()
25+
RETURNS SETOF TEXT AS
26+
$BODY$
27+
BEGIN
28+
29+
IF NOT min_version('4.0.0') THEN
30+
RETURN QUERY
31+
SELECT skip(1, 'Function is new on 4.0.0');
32+
RETURN;
33+
END IF;
34+
35+
RETURN QUERY SELECT has_function('pgr_sloanordering');
36+
RETURN QUERY SELECT has_function('pgr_sloanordering', ARRAY['text']);
37+
RETURN QUERY SELECT function_returns('pgr_sloanordering', ARRAY['text'], 'setof record');
38+
39+
RETURN QUERY
40+
SELECT function_args_eq('pgr_sloanordering',
41+
$$SELECT '{"","seq","node"}'::TEXT[] $$
42+
);
43+
44+
RETURN QUERY
45+
SELECT function_types_eq('pgr_sloanordering',
46+
$$VALUES
47+
('{text,int8,int8}'::TEXT[])
48+
$$
49+
);
50+
END;
51+
$BODY$
52+
LANGUAGE plpgsql;
53+
54+
SELECT types_check();
55+
56+
SELECT * FROM finish();
57+
ROLLBACK;

0 commit comments

Comments
 (0)