Skip to content

Commit

Permalink
[centrality] fixed all linting errors in driver code
Browse files Browse the repository at this point in the history
  • Loading branch information
bedupako12mas committed Aug 5, 2024
1 parent 6486142 commit a333230
Showing 1 changed file with 46 additions and 50 deletions.
96 changes: 46 additions & 50 deletions include/metrics/betweennessCentrality.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,59 +68,55 @@ pgr_betweennesscentrality(
template <class G>
class Pgr_metrics {
public:
using Graph = typename G::B_G;
using Graph = typename G::B_G;
using Vertex = typename G::V;
typedef typename boost::graph_traits<Graph>::directed_category directed_category;

void betweennessCentrality (
const G &graph,
size_t &result_tuple_count,
IID_t_rt **postgres_rows ){

std::vector<double> centrality(boost::num_vertices(graph.graph), 0.0);

auto centrality_map = boost::make_iterator_property_map(centrality.begin(),
boost::get(boost::vertex_index, graph.graph)
);


/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
boost::brandes_betweenness_centrality(
graph.graph,
centrality_map

);
if(boost::num_vertices(graph.graph) > 2) {
boost::relative_betweenness_centrality(
graph.graph,
centrality_map
);
}

generate_results(graph, centrality, result_tuple_count, postgres_rows);
}
typedef typename boost::graph_traits<Graph>::directed_category directed_category;

void betweennessCentrality(
const G &graph,
size_t &result_tuple_count,
IID_t_rt **postgres_rows ) {
std::vector<double> centrality(boost::num_vertices(graph.graph), 0.0);

auto centrality_map = boost::make_iterator_property_map(centrality.begin(),
boost::get(boost::vertex_index, graph.graph));


/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
boost::brandes_betweenness_centrality(
graph.graph,
centrality_map);

if (boost::num_vertices(graph.graph) > 2) {
boost::relative_betweenness_centrality(
graph.graph,
centrality_map);
}

generate_results(graph, centrality, result_tuple_count, postgres_rows);
}

private:
void generate_results(
const G &graph,
const std::vector<double> centrality_results,
size_t &result_tuple_count,
IID_t_rt **postgres_rows) const {
result_tuple_count = centrality_results.size();
*postgres_rows = pgr_alloc(result_tuple_count, (*postgres_rows));

size_t seq = 0;
for(typename G::V v_i = 0; v_i < graph.num_vertices(); ++v_i) {
(*postgres_rows)[seq].from_vid = graph[v_i].id;
(*postgres_rows)[seq].to_vid = 0;
(*postgres_rows)[seq].cost = centrality_results[v_i];
if(std::is_same<directed_category, boost::bidirectional_tag>::value) {
(*postgres_rows)[seq].cost = centrality_results[v_i]/2.0;
}
seq++;
}
}
void generate_results(
const G &graph,
const std::vector<double> centrality_results,
size_t &result_tuple_count,
IID_t_rt **postgres_rows) const {
result_tuple_count = centrality_results.size();
*postgres_rows = pgr_alloc(result_tuple_count, (*postgres_rows));

size_t seq = 0;
for (typename G::V v_i = 0; v_i < graph.num_vertices(); ++v_i) {
(*postgres_rows)[seq].from_vid = graph[v_i].id;
(*postgres_rows)[seq].to_vid = 0;
(*postgres_rows)[seq].cost = centrality_results[v_i];
if (std::is_same<directed_category, boost::bidirectional_tag>::value) {
(*postgres_rows)[seq].cost = centrality_results[v_i]/2.0;
}
seq++;
}
}
};

} // namespace pgrouting
Expand Down

0 comments on commit a333230

Please sign in to comment.