|
Boost-Commit : |
From: asutton_at_[hidden]
Date: 2007-07-31 08:36:54
Author: asutton
Date: 2007-07-31 08:36:51 EDT (Tue, 31 Jul 2007)
New Revision: 7613
URL: http://svn.boost.org/trac/boost/changeset/7613
Log:
Completely rewriting degree distribution
Text files modified:
sandbox/SOC/2007/graphs/boost/graph/closeness_centrality.hpp | 4
sandbox/SOC/2007/graphs/boost/graph/degree_distribution.hpp | 85 ++++++++++++++++++++++++++++++++++++++-
sandbox/SOC/2007/graphs/boost/graph/numeric_values.hpp | 40 ++++++++++++++++++
3 files changed, 123 insertions(+), 6 deletions(-)
Modified: sandbox/SOC/2007/graphs/boost/graph/closeness_centrality.hpp
==============================================================================
--- sandbox/SOC/2007/graphs/boost/graph/closeness_centrality.hpp (original)
+++ sandbox/SOC/2007/graphs/boost/graph/closeness_centrality.hpp 2007-07-31 08:36:51 EDT (Tue, 31 Jul 2007)
@@ -4,8 +4,8 @@
// Boost Software License, Version 1.0 (See accompanying file
// LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_GRAPH_GEODESIC_HPP
-#define BOOST_GRAPH_GEODESIC_HPP
+#ifndef BOOST_GRAPH_CLOSENESS_CENTRALITY_HPP
+#define BOOST_GRAPH_CLISENESS_CENTRALITY_HPP
#include <limits>
Modified: sandbox/SOC/2007/graphs/boost/graph/degree_distribution.hpp
==============================================================================
--- sandbox/SOC/2007/graphs/boost/graph/degree_distribution.hpp (original)
+++ sandbox/SOC/2007/graphs/boost/graph/degree_distribution.hpp 2007-07-31 08:36:51 EDT (Tue, 31 Jul 2007)
@@ -4,13 +4,90 @@
// Boost Software License, Version 1.0 (See accompanying file
// LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_GRAPH_DEGREE_DISTRIBUTION_HXX
-#define BOOST_GRAPH_DEGREE_DISTRIBUTION_HXX
-
-#include <boost/graph/named_parameters.hpp>
+#ifndef BOOST_GRAPH_DEGREE_CENTRALITY_HXX
+#define BOOST_GRAPH_DEGREE_CENTRALITY_HXX
namespace boost
{
+ template <typename Graph>
+ struct degree_centrality_measure
+ {
+ typedef graph_traits<Graph>::degree_size_type value_type;
+ typedef graph_traits<Graph>::vertex_descriptor vertex_type;
+ };
+
+ template <typename Graph>
+ struct basic_degree_centrality
+ : public degree_centrality_measure<Graph>
+ {
+ typedef degree_centrality_measure<Graph> base_type;
+ typedef typename base_type::value_type value_type;
+ typedef typename base_type::vertex_descriptor vertex_type;
+
+ inline value_type operator ()(const Graph& g, vertex_type v)
+ {
+ return get_degree(g, v, typename Graph::directed_category());
+ }
+
+ private:
+ inline value_type
+ get_degree(const Graph& g, vertex_type v, undirected_graph_tag)
+ {
+ return degree(v, g);
+ }
+
+ inline value_type
+ get_degree(const Graph& g, vertex_type v, directed_graph_tag)
+ {
+ return out_degree(v, g);
+ }
+ };
+
+ template <typename Graph>
+ inline basic_degree_centrality<Graph>
+ measure_basic_degree_centrality(const Graph&)
+ {
+ return basic_degree_centrality<Graph>();
+ }
+
+
+ template <typename Graph, typename Measure>
+ inline typename graph_traits<Graph>::degree_size_type
+ vertex_degree_centrality(const Graph& g,
+ typename graph_traits<Graph>::vertex_descriptor v,
+ Measure measure)
+ {
+ return measure(g, v);
+ }
+
+ template <typename Graph>
+ inline typename graph_traits<Graph>::degree_size_type
+ vertex_degree_centrality(const Graph& g,
+ typename graph_traits<Graph>::vertex_descriptor v)
+ {
+ return vertex_degree_centrality(g, v,
+ measure_basic_degree_centrality(g));
+ }
+
+
+ template <typename Graph, typename CentralityMap, typename Measure>
+ void degree_centrality(const Graph& g,
+ CentralityMap cent,
+ Measure measure)
+ {
+ typename graph_traits<Graph>::vertex_iterator i, end;
+ for(tie(i, end) = vertices(g); i != end; ++i) {
+ cent[*i] = vertex_centrality(g, *i, measure);
+ }
+ }
+
+ template <typename Graph, typename CentralityMap>
+ void degree_centrality(const Graph& g,
+ CentralityMap cent)
+ {
+ degree_centrality(g, cent, measure_basic_degree_centrality(g));
+ }
+
// Helper functions for computing degree distributions, histograms. Note
// that when passed a not_given argumemt, all of these operations are
// no-ops. The effect is that the actual computations shouldn't add hidden
Modified: sandbox/SOC/2007/graphs/boost/graph/numeric_values.hpp
==============================================================================
--- sandbox/SOC/2007/graphs/boost/graph/numeric_values.hpp (original)
+++ sandbox/SOC/2007/graphs/boost/graph/numeric_values.hpp 2007-07-31 08:36:51 EDT (Tue, 31 Jul 2007)
@@ -18,6 +18,10 @@
// semantics of zero and infinity. This classd essentially
// builds abstractions for zero and infinity out of types
// that don't necessarily support it.
+ //
+ // Specializations are provided for float and double types
+ // since they actually have an infinity value.
+
template <typename T>
struct numeric_values
{
@@ -29,6 +33,42 @@
static inline T infinity()
{ return std::numeric_limits<T>::max(); }
};
+
+ template <>
+ struct numeric_values<float>
+ {
+ typedef float value_type;
+
+ static inline float zero()
+ { return float(0.0); }
+
+ static inline float infinity()
+ { return std::numeric_limits<float>::infinity(); }
+ };
+
+ template <>
+ struct numeric_values<double>
+ {
+ typedef double value_type;
+
+ static inline double zero()
+ { return double(0.0); }
+
+ static inline double infinity()
+ { return std::numeric_limits<double>::infinity(); }
+ };
+
+ template <>
+ struct numeric_values<long double>
+ {
+ typedef long double value_type;
+
+ static inline long double zero()
+ { return value_type(0.0); }
+
+ static inline long double infinity()
+ { return std::numeric_limits<long double>::infinity(); }
+ };
}
#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