From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/graph/example/eccentricity.cpp | 89 +++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/boost/libs/graph/example/eccentricity.cpp (limited to 'src/boost/libs/graph/example/eccentricity.cpp') diff --git a/src/boost/libs/graph/example/eccentricity.cpp b/src/boost/libs/graph/example/eccentricity.cpp new file mode 100644 index 00000000..3e16e6f2 --- /dev/null +++ b/src/boost/libs/graph/example/eccentricity.cpp @@ -0,0 +1,89 @@ +// (C) Copyright Andrew Sutton 2007 +// +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0 (See accompanying file +// LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) + + +//[eccentricity_example +#include +#include + +#include +#include +#include +#include +#include "helper.hpp" + +using namespace std; +using namespace boost; + +// The Actor type stores the name of each vertex in the graph. +struct Actor +{ + string name; +}; + +// Declare the graph type and its vertex and edge types. +typedef undirected_graph Graph; +typedef graph_traits::vertex_descriptor Vertex; +typedef graph_traits::edge_descriptor Edge; + +// The name map provides an abstract accessor for the names of +// each vertex. This is used during graph creation. +typedef property_map::type NameMap; + +// Declare a matrix type and its corresponding property map that +// will contain the distances between each pair of vertices. +typedef exterior_vertex_property DistanceProperty; +typedef DistanceProperty::matrix_type DistanceMatrix; +typedef DistanceProperty::matrix_map_type DistanceMatrixMap; + +// Declare the weight map so that each edge returns the same value. +typedef constant_property_map WeightMap; + +// Declare a container and its corresponding property map that +// will contain the resulting eccentricities of each vertex in +// the graph. +typedef boost::exterior_vertex_property EccentricityProperty; +typedef EccentricityProperty::container_type EccentricityContainer; +typedef EccentricityProperty::map_type EccentricityMap; + +int +main(int argc, char *argv[]) +{ + // Create the graph and a name map that provides access to + // then actor names. + Graph g; + NameMap nm(get(&Actor::name, g)); + + // Read the graph from standard input. + read_graph(g, nm, cin); + + // Compute the distances between all pairs of vertices using + // the Floyd-Warshall algorithm. Note that the weight map is + // created so that every edge has a weight of 1. + DistanceMatrix distances(num_vertices(g)); + DistanceMatrixMap dm(distances, g); + WeightMap wm(1); + floyd_warshall_all_pairs_shortest_paths(g, dm, weight_map(wm)); + + // Compute the eccentricities for graph - this computation returns + // both the radius and diameter as well. + int r, d; + EccentricityContainer eccs(num_vertices(g)); + EccentricityMap em(eccs, g); + boost::tie(r, d) = all_eccentricities(g, dm, em); + + // Print the closeness centrality of each vertex. + graph_traits::vertex_iterator i, end; + for(boost::tie(i, end) = vertices(g); i != end; ++i) { + cout << setw(12) << setiosflags(ios::left) + << g[*i].name << get(em, *i) << endl; + } + cout << "radius: " << r << endl; + cout << "diamter: " << d << endl; + + return 0; +} +//] -- cgit v1.2.3