Boost logo

Boost-Commit :

From: asutton_at_[hidden]
Date: 2007-08-15 10:34:01


Author: asutton
Date: 2007-08-15 10:34:00 EDT (Wed, 15 Aug 2007)
New Revision: 38678
URL: http://svn.boost.org/trac/boost/changeset/38678

Log:
Added missing geodesic example
Added new example for eccentricity

Added:
   sandbox/SOC/2007/graphs/libs/graph/examples/eccentricity.cpp (contents, props changed)
   sandbox/SOC/2007/graphs/libs/graph/examples/mean_geodesic.cpp (contents, props changed)
Text files modified:
   sandbox/SOC/2007/graphs/libs/graph/examples/Jamfile.v2 | 4 +++-
   sandbox/SOC/2007/graphs/libs/graph/examples/closeness_centrality.cpp | 2 +-
   sandbox/SOC/2007/graphs/libs/graph/examples/social_network.hpp | 12 ++++++++++++
   3 files changed, 16 insertions(+), 2 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-15 10:34:00 EDT (Wed, 15 Aug 2007)
@@ -8,4 +8,6 @@
 exe degree_centrality : degree_centrality.cpp ;
 exe influence_prestige : influence_prestige.cpp ;
 exe closeness_centrality : closeness_centrality.cpp ;
-exe norm_closeness : norm_closeness.cpp ;
+exe norm_closeness_centrality : norm_closeness_centrality.cpp ;
+exe mean_geodesic : mean_geodesic.cpp ;
+exe eccentricity : eccentricity.cpp ;
\ No newline at end of file

Modified: sandbox/SOC/2007/graphs/libs/graph/examples/closeness_centrality.cpp
==============================================================================
--- sandbox/SOC/2007/graphs/libs/graph/examples/closeness_centrality.cpp (original)
+++ sandbox/SOC/2007/graphs/libs/graph/examples/closeness_centrality.cpp 2007-08-15 10:34:00 EDT (Wed, 15 Aug 2007)
@@ -41,7 +41,7 @@
     //]
 
     // Compute the degree centrality for graph
- //[compute_closeness
+ //[compute_closeness_centrality
     ClosenessContainer cents(num_vertices(g));
     ClosenessMap cm(cents, g);
     closeness_centrality(g, dm, cm);

Added: sandbox/SOC/2007/graphs/libs/graph/examples/eccentricity.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/graphs/libs/graph/examples/eccentricity.cpp 2007-08-15 10:34:00 EDT (Wed, 15 Aug 2007)
@@ -0,0 +1,56 @@
+// (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 "social_network.hpp"
+#include "helper.hpp"
+
+#include <iostream>
+#include <iomanip>
+#include <boost/graph/floyd_warshall_shortest.hpp>
+#include <boost/graph/eccentricity.hpp>
+
+using namespace std;
+using namespace boost;
+
+int
+main(int argc, char *argv[])
+{
+ Graph g;
+ map<string, Vertex> verts;
+
+ // Read in and build the graph
+ for(string line; getline(cin, line); ) {
+ if(line.empty()) continue;
+ size_t index = line.find_first_of(',');
+ string first(line, 0, index);
+ string second(line, index + 1);
+
+ Vertex u = add_named_vertex(g, first, verts);
+ Vertex v = add_named_vertex(g, second, verts);
+ add_edge(u, v, g);
+ }
+
+ 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 degree centrality for graph
+ //[compute_eccentricity
+ EccentricityContainer eccs(num_vertices(g));
+ EccentricityMap em(eccs, g);
+ eccentricity(g, dm, em);
+ int radius = graph_radius(g, em);
+ int diameter = graph_diameter(g, em);
+ //]
+
+ //[print_radius_diameter
+ cout << setw(10) << setiosflags(ios::left) << "radius" << radius << "\n";
+ cout << setw(10) << setiosflags(ios::left) << "diameter" << diameter << "\n";
+ //]
+
+ return 0;
+}

Added: sandbox/SOC/2007/graphs/libs/graph/examples/mean_geodesic.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/graphs/libs/graph/examples/mean_geodesic.cpp 2007-08-15 10:34:00 EDT (Wed, 15 Aug 2007)
@@ -0,0 +1,60 @@
+// (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 "social_network.hpp"
+#include "helper.hpp"
+
+#include <iostream>
+#include <iomanip>
+#include <boost/graph/floyd_warshall_shortest.hpp>
+#include <boost/graph/geodesic_distance.hpp>
+
+using namespace std;
+using namespace boost;
+
+int
+main(int argc, char *argv[])
+{
+ Graph g;
+ map<string, Vertex> verts;
+
+ // Read in and build the graph
+ for(string line; getline(cin, line); ) {
+ if(line.empty()) continue;
+ size_t index = line.find_first_of(',');
+ string first(line, 0, index);
+ string second(line, index + 1);
+
+ Vertex u = add_named_vertex(g, first, verts);
+ Vertex v = add_named_vertex(g, second, verts);
+ add_edge(u, v, g);
+ }
+
+ 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 degree centrality for graph
+ //[compute_mean_geodesics
+ GeodesicContainer geodesics(num_vertices(g));
+ GeodesicMap gm(geodesics, g);
+ mean_geodesic(g, dm, gm);
+ float geo = graph_mean_geodesic(g, gm);
+ //]
+
+ graph_traits<Graph>::vertex_iterator i, end;
+ for(tie(i, end) = vertices(g); i != end; ++i) {
+ cout << g[*i].name << " : " << get(gm, *i) << "\n";
+ }
+
+ //[print_graph_mean_geodesic
+ cout << "mean geodesic distance: " << geo << endl;
+ //]
+
+
+ return 0;
+}

Modified: sandbox/SOC/2007/graphs/libs/graph/examples/social_network.hpp
==============================================================================
--- sandbox/SOC/2007/graphs/libs/graph/examples/social_network.hpp (original)
+++ sandbox/SOC/2007/graphs/libs/graph/examples/social_network.hpp 2007-08-15 10:34:00 EDT (Wed, 15 Aug 2007)
@@ -47,4 +47,16 @@
 typedef ClosenessProperty::map_type ClosenessMap;
 //]
 
+//[geodesic_map_types
+typedef boost::exterior_vertex_property<Graph, float> GeodesicProperty;
+typedef GeodesicProperty::container_type GeodesicContainer;
+typedef GeodesicProperty::map_type GeodesicMap;
+//]
+
+//[eccentricity_map_types
+typedef boost::exterior_vertex_property<Graph, int> EccentricityProperty;
+typedef EccentricityProperty::container_type EccentricityContainer;
+typedef EccentricityProperty::map_type EccentricityMap;
+//]
+
 #endif


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