Boost logo

Boost-Commit :

From: asutton_at_[hidden]
Date: 2007-08-10 12:18:44


Author: asutton
Date: 2007-08-10 12:18:43 EDT (Fri, 10 Aug 2007)
New Revision: 38572
URL: http://svn.boost.org/trac/boost/changeset/38572

Log:
Adding new examples (and build) for degree centrality

Added:
   sandbox/SOC/2007/graphs/libs/graph/examples/Jamfile.v2 (contents, props changed)
   sandbox/SOC/2007/graphs/libs/graph/examples/degree_centrality.cpp (contents, props changed)
   sandbox/SOC/2007/graphs/libs/graph/examples/influence_prestige.cpp (contents, props changed)
   sandbox/SOC/2007/graphs/libs/graph/examples/information_network.graph (contents, props changed)
   sandbox/SOC/2007/graphs/libs/graph/examples/social_network.graph (contents, props changed)

Added: sandbox/SOC/2007/graphs/libs/graph/examples/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/graphs/libs/graph/examples/Jamfile.v2 2007-08-10 12:18:43 EDT (Fri, 10 Aug 2007)
@@ -0,0 +1,10 @@
+
+project
+ : requirements
+ <include>../../../
+ <include>$BOOST_ROOT
+ ;
+
+exe degree_centrality : degree_centrality.cpp ;
+
+exe influence_prestige : influence_prestige.cpp ;
\ No newline at end of file

Added: sandbox/SOC/2007/graphs/libs/graph/examples/degree_centrality.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/graphs/libs/graph/examples/degree_centrality.cpp 2007-08-10 12:18:43 EDT (Fri, 10 Aug 2007)
@@ -0,0 +1,75 @@
+// (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 <string>
+#include <vector>
+#include <map>
+
+#include <boost/graph/undirected_graph.hpp>
+#include <boost/graph/exterior_property.hpp>
+#include <boost/graph/degree_centrality.hpp>
+
+#include "helper.hpp"
+
+using namespace std;
+using namespace boost;
+
+//[declare_social_network
+struct Person
+{
+ string name;
+};
+
+typedef undirected_graph<Person> Graph;
+typedef graph_traits<Graph>::vertex_descriptor Vertex;
+
+typedef exterior_vertex_property<Graph, size_t> CentralityProperty;
+typedef CentralityProperty::container_type CentralityContainer;
+typedef CentralityProperty::map_type CentralityMap;
+
+typedef map<string, Vertex> VertexMap;
+//]
+
+int
+main(int argc, char *argv[])
+{
+ //[setup_social_network
+ Graph g;
+ map<string, Vertex> verts;
+ //]
+
+ //[build_social_network
+ // 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);
+ }
+ //]
+
+ //[measure_social_network
+ // Compute the degree centrality for graph
+ CentralityContainer cents(num_vertices(g));
+ CentralityMap cm(cents, g);
+ degree_centrality(g, cm);
+ //]
+
+ //[print_social_network
+ // Print the degree centrality of each vertex
+ graph_traits<Graph>::vertex_iterator i, end;
+ for(tie(i, end) = vertices(g); i != end; ++i) {
+ cout << g[*i].name << ": " << cm[*i] << "\n";
+ }
+ //]
+
+ return 0;
+}

Added: sandbox/SOC/2007/graphs/libs/graph/examples/influence_prestige.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/graphs/libs/graph/examples/influence_prestige.cpp 2007-08-10 12:18:43 EDT (Fri, 10 Aug 2007)
@@ -0,0 +1,84 @@
+// (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 <iomanip>
+#include <string>
+#include <vector>
+#include <map>
+
+#include <boost/graph/directed_graph.hpp>
+#include <boost/graph/exterior_property.hpp>
+#include <boost/graph/degree_centrality.hpp>
+
+#include "helper.hpp"
+
+using namespace std;
+using namespace boost;
+
+//[declare_information_network
+struct Person
+{
+ string name;
+};
+
+typedef directed_graph<Person> Graph;
+typedef graph_traits<Graph>::vertex_descriptor Vertex;
+
+typedef exterior_vertex_property<Graph, size_t> CentralityProperty;
+typedef CentralityProperty::container_type CentralityContainer;
+typedef CentralityProperty::map_type CentralityMap;
+
+typedef map<string, Vertex> VertexMap;
+//]
+
+int
+main(int argc, char *argv[])
+{
+ //[setup_information_network
+ Graph g;
+ map<string, Vertex> verts;
+ //]
+
+ //[build_information_network
+ // 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);
+ }
+ //]
+
+ //[measure_information_network
+ // Compute the influence and prestige for the graph
+ CentralityContainer influence(num_vertices(g));
+ CentralityMap im(influence, g);
+ degree_centrality(g, im, measure_influence(g));
+
+ CentralityContainer prestige(num_vertices(g));
+ CentralityMap pm(prestige, g);
+ degree_centrality(g, pm, measure_prestige(g));
+ //]
+
+ //[print_information_network
+ // Print the degree centrality of each vertex
+ graph_traits<Graph>::vertex_iterator i, end;
+ for(tie(i, end) = vertices(g); i != end; ++i) {
+ Vertex v = *i;
+ cout << setiosflags(ios::left) << setw(12)
+ << g[v].name << "\t"
+ << im[v] << "\t"
+ << pm[v] << "\n";
+ }
+ //]
+
+ return 0;
+}

Added: sandbox/SOC/2007/graphs/libs/graph/examples/information_network.graph
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/graphs/libs/graph/examples/information_network.graph 2007-08-10 12:18:43 EDT (Fri, 10 Aug 2007)
@@ -0,0 +1,11 @@
+myspace,digg
+blogger,digg
+blogger,slahsdot
+blogger,wikipedia
+digg,slashdot
+digg,wikipedia
+blogspot,slashdot
+blogspot,wikipedia
+slashdot,bbc
+slashdot,wikipedia
+bbc,wikipedia
\ No newline at end of file

Added: sandbox/SOC/2007/graphs/libs/graph/examples/social_network.graph
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/graphs/libs/graph/examples/social_network.graph 2007-08-10 12:18:43 EDT (Fri, 10 Aug 2007)
@@ -0,0 +1,11 @@
+Scott,Jill
+Mary,Scott
+Jill,Mary
+Bill,Scott
+Josh,Bill
+Scott,Frank
+Laurie,Frank
+Anne,Frank
+Howard,Anne
+Frank,Howard
+Josh,Frank
\ No newline at end of file


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