Skip to content

Commit

Permalink
Merge pull request #402 from bedupako12mas/Centrality-Week11
Browse files Browse the repository at this point in the history
Centrality Week 11
  • Loading branch information
bedupako12mas authored Aug 13, 2024
2 parents 906e104 + 466ffd4 commit 2d398b3
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions include/metrics/betweennessCentrality.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "cpp_common/pgr_base_graph.hpp"
#include "cpp_common/interruption.hpp"

// TODO(arun) don't keep it here
#include "cpp_common/pgr_alloc.hpp"

/**
* @ brief The main file which calls the respective boost function
*
* Contains actual implementation of the function and the calling
* of the respective boost function
*/

namespace pgrouting {
template <class G> class Pgr_metrics;

Expand All @@ -68,26 +74,39 @@ pgr_betweennesscentrality(
template <class G>
class Pgr_metrics {
public:
/** @name betweennessCentrality
* @{
*
*/

/** @brief betweennessCentrality function
*
* It does all the processing and returns the results.
*
* @param graph the graph containing the edges
*
* @see [boost::brandes_betweenness_centrality]
* (https://www.boost.org/doc/libs/1_85_0/libs/graph/doc/betweenness_centrality.html)
*/
using Graph = typename G::B_G;
using Vertex = typename G::V;
using V = typename G::V;
using E = typename G::E;
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);

// stores the centrality values for all vertices of the graph
auto centrality_map = boost::make_iterator_property_map(centrality.begin(),
boost::get(boost::vertex_index, graph.graph));

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,
Expand Down

0 comments on commit 2d398b3

Please sign in to comment.