Boost logo

Boost-Commit :

From: asutton_at_[hidden]
Date: 2007-08-22 11:01:30


Author: asutton
Date: 2007-08-22 11:01:27 EDT (Wed, 22 Aug 2007)
New Revision: 38846
URL: http://svn.boost.org/trac/boost/changeset/38846

Log:
Added clustering coef example

Added:
   sandbox/SOC/2007/graphs/libs/graph/examples/clustering_coefficient.cpp (contents, props changed)
Text files modified:
   sandbox/SOC/2007/graphs/libs/graph/examples/Jamfile.v2 | 1 +
   1 files changed, 1 insertions(+), 0 deletions(-)

Modified: sandbox/SOC/2007/graphs/libs/graph/examples/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/graphs/libs/graph/examples/Jamfile.v2 (original)
+++ sandbox/SOC/2007/graphs/libs/graph/examples/Jamfile.v2 2007-08-22 11:01:27 EDT (Wed, 22 Aug 2007)
@@ -12,6 +12,7 @@
 exe mean_geodesic : mean_geodesic.cpp ;
 exe inclusive_mean_geodesic : inclusive_mean_geodesic.cpp ;
 exe eccentricity : eccentricity.cpp ;
+exe clustering_coefficient : clustering_coefficient.cpp ;
 exe tiernan_print_cycles : tiernan_print_cycles.cpp ;
 exe tiernan_girth_circumference : tiernan_girth_circumference.cpp ;
 exe bron_kerbosch_print_cliques : bron_kerbosch_print_cliques.cpp ;

Added: sandbox/SOC/2007/graphs/libs/graph/examples/clustering_coefficient.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/graphs/libs/graph/examples/clustering_coefficient.cpp 2007-08-22 11:01:27 EDT (Wed, 22 Aug 2007)
@@ -0,0 +1,69 @@
+// (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)
+
+
+//[code_clustering_coefficient
+#include <iostream>
+#include <iomanip>
+
+#include <boost/graph/undirected_graph.hpp>
+#include <boost/graph/exterior_property.hpp>
+#include <boost/graph/clustering_coefficient.hpp>
+#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<Actor> Graph;
+typedef graph_traits<Graph>::vertex_descriptor Vertex;
+typedef graph_traits<Graph>::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<Graph, string Actor::*>::type NameMap;
+
+// The clustering property, container, and map define the containment
+// and abstract accessor for the clustering coefficients of vertices.
+typedef exterior_vertex_property<Graph, float> ClusteringProperty;
+typedef ClusteringProperty::container_type ClusteringContainer;
+typedef ClusteringProperty::map_type ClusteringMap;
+
+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 clustering coefficients of each vertex in the graph
+ // and the mean clustering coefficient which is returned from the
+ // computation.
+ ClusteringContainer coefs(num_vertices(g));
+ ClusteringMap cm(coefs, g);
+ float cc = all_clustering_coefficients(g, cm);
+
+ // Print the clustering coefficient of each vertex.
+ graph_traits<Graph>::vertex_iterator i, end;
+ for(tie(i, end) = vertices(g); i != end; ++i) {
+ cout << setw(12) << setiosflags(ios::left)
+ << g[*i].name << get(cm, *i) << endl;
+ }
+ cout << "mean clustering coefficient: " << cc << endl;
+
+ return 0;
+}
+//]


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