Skip to content

Commit 9eaba2d

Browse files
authored
Merge pull request #244 from shobhit162/shobhit-week-7
GSoC 2022 : Shobhit Chaurasia Week 7
2 parents 5c596d1 + e21a6df commit 9eaba2d

File tree

2 files changed

+93
-19
lines changed

2 files changed

+93
-19
lines changed

include/ordering/cuthillMckeeOrdering.hpp

Lines changed: 77 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*PGR-GNU*****************************************************************
2-
File: pgr_cuthillMckeeOrdering_driver.hpp
2+
File: cuthillMckeeOrdering.hpp
33
44
Generated with Template by:
55
Copyright (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>
6567
class 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

src/ordering/cuthillMckeeOrdering_driver.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,19 @@ std::vector <II_t_rt>
4444
cuthillMckeeOrdering(pgrouting::UndirectedGraph &graph, int64_t start_vid) {
4545
pgrouting::functions::CuthillMckeeOrdering fn;
4646
auto results = fn.cuthillMckeeOrdering(graph, start_vid);
47+
#if 0
4748
log << fn.get_log();
49+
#endif
50+
return results;
51+
}
52+
#endif
53+
54+
#if 1
55+
template <class G>
56+
std::vector <II_t_rt>
57+
cuthillMckeeOrdering(G &graph, int64_t start_vid) {
58+
pgrouting::functions::CuthillMckeeOrdering <G> fn_cuthillMckeeOrdering;
59+
auto results = fn_cuthillMckeeOrdering.cuthillMckeeOrdering(graph, start_vid);
4860
return results;
4961
}
5062
#endif
@@ -75,16 +87,18 @@ void do_cuthillMckeeOrdering(
7587

7688
pgrouting::UndirectedGraph undigraph(gType);
7789
undigraph.insert_edges(data_edges, total_edges);
78-
90+
auto results = cuthillMckeeOrdering(undigraph, start_vid); // might cause error bcz of type
91+
#if 0
7992
pgrouting::functions::CuthillMckeeOrdering fn;
8093
auto results = fn.cuthillMckeeOrdering(undigraph, start_vid);
8194
log << fn.get_log();
95+
#endif
8296

8397
auto count = results.size();
8498

8599
if (count == 0) {
86100
(*return_tuples) = NULL;
87-
(*return_count) = 0;
101+
(*return_count) = 0;
88102
notice << "No results found";
89103
*log_msg = pgr_msg(log.str().c_str());
90104
return;

0 commit comments

Comments
 (0)