This documentation is being rewritten. If something looks off, please cross-check with the Boost 1.91.0 Boost.Graph docs and open an issue.

Graph Statistics

Utility functions for computing basic structural statistics of a graph.

Defined in: <boost/graph/graph_stats.hpp>

Example

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_stats.hpp>
#include <iostream>
#include <map>

using Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS>;

int main() {
    Graph g(4);
    boost::add_edge(0, 1, g);
    boost::add_edge(0, 2, g);
    boost::add_edge(1, 2, g);
    boost::add_edge(0, 1, g); // duplicate edge

    unsigned long dups = boost::graph::num_dup_edges(g);
    std::cout << "Duplicate edges: " << dups << "\n";

    auto dist = boost::graph::degree_dist(g);
    std::cout << "Degree distribution:\n";
    for (auto& p : dist) {
        std::cout << "  degree " << p.first << ": " << p.second << " vertices\n";
    }
}
Duplicate edges: 1
Degree distribution:
  degree 0: 2 vertices
  degree 1: 1 vertices
  degree 3: 1 vertices

Functions

Function What it computes

graph::num_dup_edges(g)

Number of duplicate (parallel) edges in the graph.

graph::degree_dist(g)

Degree distribution: a std::map<unsigned long, unsigned long> mapping each degree value to the number of vertices with that degree.

graph::dup_edge_dist(g)

Distribution of duplicate edges per vertex.

graph::weight_degree_dist(g)

Average edge weight by vertex degree. Requires an internal edge_weight property.

Synopsis

namespace boost { namespace graph {

template <typename Graph>
unsigned long num_dup_edges(Graph& g);

template <typename Graph>
std::map<unsigned long, unsigned long> degree_dist(Graph& g);

template <typename Graph>
std::map<unsigned long, unsigned long> dup_edge_dist(Graph& g);

template <typename Graph>
std::map<unsigned long, double> weight_degree_dist(Graph& g);

}}
Direction Parameter Description

IN

Graph& g

Must model VertexListGraph and IncidenceGraph. weight_degree_dist additionally requires an internal edge_weight_t property.