11/* PGR-GNU*****************************************************************
2- File: pgr_cuthillMckeeOrdering_driver .hpp
2+ File: cuthillMckeeOrdering .hpp
33
44Generated with Template by:
55Copyright (c) 2022 pgRouting developers
@@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3232#pragma once
3333
3434/* TODO remove unnecessary includes */
35+ #include < boost/config.hpp>
3536#include < boost/property_map/property_map.hpp>
3637#include < boost/graph/graph_traits.hpp>
3738#include < boost/property_map/vector_property_map.hpp>
@@ -62,8 +63,10 @@ namespace functions {
6263
6364// *************************************************************
6465
66+ template <class G >
6567class CuthillMckeeOrdering : public Pgr_messages {
6668 public:
69+ #if 0
6770 using G = pgrouting::UndirectedGraph;
6871 using vertices_size_type = G::vertices_size_type;
6972
@@ -88,7 +91,7 @@ class CuthillMckeeOrdering : public Pgr_messages{
8891 std::vector<II_t_rt>results;
8992
9093 // get source
91- if (!graph.has_vertex (start_vid)) {
94+ if (!graph.has_vertex(start_vid)) {
9295 return results;
9396 }
9497
@@ -115,7 +118,8 @@ class CuthillMckeeOrdering : public Pgr_messages{
115118 results = get_results(ordering, graph);
116119#endif
117120#if 0
118- { // TODO delete boost example
121+ {
122+ // delete boost example
119123 using namespace boost;
120124 typedef adjacency_list< vecS, vecS, undirectedS,
121125 property< vertex_color_t, default_color_type,
@@ -176,8 +180,61 @@ class CuthillMckeeOrdering : public Pgr_messages{
176180#endif
177181 return results;
178182 }
179-
183+ # endif
180184 // @}
185+ #if 1
186+ typedef typename G::V V;
187+ typedef typename G::E E;
188+ typedef boost::adjacency_list<boost::vecS,boost::vecS,boost::undirectedS,
189+ boost::property<boost::vertex_color_t ,boost::default_color_type,
190+ boost::property<boost::vertex_degree_t , int >>>
191+ Graph;
192+ typedef boost::graph_traits<Graph>::vertices_size_type vertices_size_type;
193+ typedef boost::graph_traits<Graph>::vertices_size_type size_type;
194+
195+ // documentation todo
196+
197+ std::vector<II_t_rt>
198+ cuthillMckeeOrdering (G &graph, int64_t start_vid) {
199+ std::vector<II_t_rt>results;
200+ #if 0
201+ auto d_map = boost::get(boost::vertex_index, graph.graph);
202+ auto c_map = boost::get(boost::vertex_color, graph.graph);
203+ boost::graph_traits<Graph>::vertex_iterator ui, ui_end;
204+
205+ property_map< Graph, vertex_degree_t >::type deg = get(vertex_degree, G);
206+ for (boost::tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui)
207+ deg[*ui] = degree(*ui, G);
208+
209+ property_map< Graph, vertex_index_t >::type index_map
210+ = get(vertex_index, G);
211+
212+ std::vector<size_type> inv_perm(boost::num_vertices(graph.graph));
213+ std::vector<size_type> perm(boost::num_vertices(graph.graph));
214+ #endif
215+
216+ std::vector <vertices_size_type> ordering (boost::num_vertices (graph.graph ));
217+
218+ /* abort in case of an interruption occurs (e.g. the query is being cancelled) */
219+ CHECK_FOR_INTERRUPTS ();
220+
221+ try {
222+ boost::cuthill_mckee_ordering (graph.graph , start_vid);
223+ } catch (boost::exception const & ex) {
224+ (void )ex;
225+ throw ;
226+ } catch (std::exception &e) {
227+ (void )e;
228+ throw ;
229+ } catch (...) {
230+ throw ;
231+ }
232+
233+ results = get_results (ordering, graph);
234+
235+ return results;
236+ }
237+ #endif
181238
182239 private:
183240 /* * @brief to get the results
@@ -190,28 +247,31 @@ class CuthillMckeeOrdering : public Pgr_messages{
190247 * @returns `results` vector
191248 */
192249 std::vector <II_t_rt> get_results (
193- std::vector <vertices_size_type> & /* ordering*/ ,
194- const G & /* graph*/ ) {
195- std::vector <II_t_rt> results;
250+ std::vector <vertices_size_type> & /* ordering*/ ,
251+ const G & graph) {
252+ std::vector <II_t_rt> results;
196253
197254#if 0
198- typename boost::graph_traits < Graph > ::vertex_iterator v, vend;
255+ typename boost::graph_traits <Graph> ::vertex_iterator v, vend;
199256
257+ for (std::vector<Vertex>::const_iterator i = inv_perm.begin();
258+ i != inv_perm.end(); ++i) {
259+ log << index_map[*i] << " ";
260+ results.push_back({index_map[*i], index_map[*i]});
261+ }
262+
200263 for (boost::tie(v, vend) = vertices(graph.graph); v != vend; ++v) {
201264 int64_t node = graph[*v].id;
202265 auto orderings = ordering[*v];
203266 results.push_back({{node}, {static_cast<int64_t>(orderings + 1)}});
204267 }
205-
206- // ordering the results in an reverse ordering
207- std::sort(results.begin(), results.end(),
208- [](const II_t_rt row1, const II_t_rt row2) {
209- return row1.d1.id < row2.d1.id;
210- });
268+ for (size_type c = 0; c != inv_perm.size(); ++c)
269+ perm[index_map[inv_perm[c]]] = c;
270+ }
271+
211272#endif
212-
213- return results;
214- }
273+ return results;
274+ }
215275};
216276} // namespace functions
217277} // namespace pgrouting
0 commit comments