Boost logo

Boost-Commit :

From: asutton_at_[hidden]
Date: 2007-07-31 09:33:08


Author: asutton
Date: 2007-07-31 09:33:06 EDT (Tue, 31 Jul 2007)
New Revision: 7615
URL: http://svn.boost.org/trac/boost/changeset/7615

Log:
Added test for degree centrality.
Varios fixes/modifications.

Added:
   sandbox/SOC/2007/graphs/libs/graph/test/degree_centrality.cpp (contents, props changed)
Text files modified:
   sandbox/SOC/2007/graphs/libs/graph/test/Jamfile.v2 | 6 ++++++
   sandbox/SOC/2007/graphs/libs/graph/test/distance.cpp | 33 ++++++++++++++++++++++++++++++++-
   2 files changed, 38 insertions(+), 1 deletions(-)

Modified: sandbox/SOC/2007/graphs/libs/graph/test/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/graphs/libs/graph/test/Jamfile.v2 (original)
+++ sandbox/SOC/2007/graphs/libs/graph/test/Jamfile.v2 2007-07-31 09:33:06 EDT (Tue, 31 Jul 2007)
@@ -35,6 +35,12 @@
     : <include>../../../
     ;
 
+exe degree_centrality
+ : degree_centrality.cpp
+ : <include>$BOOST_ROOT
+ : <include>../../../
+ ;
+
 exe distance
     : distance.cpp
     : <include>$BOOST_ROOT

Added: sandbox/SOC/2007/graphs/libs/graph/test/degree_centrality.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/graphs/libs/graph/test/degree_centrality.cpp 2007-07-31 09:33:06 EDT (Tue, 31 Jul 2007)
@@ -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)
+
+#include <iostream>
+#include <iterator>
+#include <algorithm>
+#include <vector>
+#include <map>
+#include <tr1/unordered_map>
+
+#include <boost/graph/undirected_graph.hpp>
+#include <boost/graph/directed_graph.hpp>
+#include <boost/graph/exterior_property.hpp>
+#include <boost/graph/degree_centrality.hpp>
+
+using namespace std;
+using namespace boost;
+
+template <typename Graph>
+void build_graph(Graph& g)
+{
+ typedef typename Graph::vertex_descriptor Vertex;
+ typedef typename Graph::edge_descriptor Edge;
+
+ static const unsigned N = 5;
+ vector<Vertex> v(N);
+ vector<Edge> e;
+
+ // add some vertices
+ for(size_t i = 0; i < N; ++i) {
+ // v[i] = add_vertex(g);
+ v[i] = add_vertex(g);
+ }
+
+ // add some edges (with weights)
+ add_edge(v[0], v[1], g);
+ add_edge(v[1], v[2], g);
+ add_edge(v[2], v[0], g);
+ add_edge(v[3], v[4], g);
+ add_edge(v[4], v[0], g);
+};
+
+template <typename Graph, typename PropertyMap>
+void print_map(const Graph& g, PropertyMap pm)
+{
+ typename Graph::vertex_iterator i, end;
+ cout << "{ ";
+ for(tie(i, end) = vertices(g); i != end; ++i) {
+ cout << pm[*i] << " ";
+ }
+ cout << "}\n";
+}
+
+template <typename Graph>
+void test()
+{
+ typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
+ typedef typename graph_traits<Graph>::edge_descriptor Edge;
+
+
+ typedef exterior_vertex_property<Graph, unsigned> CentralityProperty;
+ typedef typename CentralityProperty::container_type CentralityContainer;
+ typedef typename CentralityProperty::map_type CentralityMap;
+
+ Graph g;
+ build_graph(g);
+
+ CentralityContainer centralities(num_vertices(g));
+ CentralityMap cents(centralities);
+ degree_centrality(g, cents);
+
+ print_map(g, cents);
+}
+
+int
+main(int argc, char *argv[])
+{
+ typedef undirected_graph<> Graph;
+ typedef directed_graph<> Digraph;
+
+ cout << "\n*** undirected_graph<> *** \n";
+ test<Graph>();
+
+ cout << "\n*** directed_graph<> *** \n";
+ test<Digraph>();
+}

Modified: sandbox/SOC/2007/graphs/libs/graph/test/distance.cpp
==============================================================================
--- sandbox/SOC/2007/graphs/libs/graph/test/distance.cpp (original)
+++ sandbox/SOC/2007/graphs/libs/graph/test/distance.cpp 2007-07-31 09:33:06 EDT (Tue, 31 Jul 2007)
@@ -21,7 +21,7 @@
 #include <boost/graph/johnson_all_pairs_shortest.hpp>
 #include <boost/graph/floyd_warshall_shortest.hpp>
 #include <boost/graph/distance.hpp>
-#include <boost/graph/geodesic.hpp>
+#include <boost/graph/closeness_centrality.hpp>
 
 using namespace std;
 using namespace boost;
@@ -139,6 +139,37 @@
 
         print_matrix(g, dists);
 
+ typedef exterior_vertex_property<Graph, float> ClosenessProperty;
+ typedef typename ClosenessProperty::container_type ClosenessContainer;
+ typedef typename ClosenessProperty::map_type ClosenessMap;
+
+ {
+ ClosenessContainer c(num_vertices(g));
+ ClosenessMap m(c);
+ all_total_geodesic_distances(g, dists, m);
+ std::cout << "all total geodesics: "; print_map(g, m);
+ }
+
+ {
+ ClosenessContainer c(num_vertices(g));
+ ClosenessMap m(c);
+ all_mean_geodesic_distances(g, dists, m);
+ std::cout << "all mean geodesics: "; print_map(g, m);
+ }
+
+ {
+ ClosenessContainer c(num_vertices(g));
+ ClosenessMap m(c);
+ all_inverse_geodesic_distances(g, dists, m);
+ std::cout << "all inverse geodesics: "; print_map(g, m);
+ }
+
+ {
+ ClosenessContainer c(num_vertices(g));
+ ClosenessMap m(c);
+ all_closenesses(g, dists, m);
+ std::cout << "all closenesses: "; print_map(g, m);
+ }
     }
 }
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk