Changeset 38749


Ignore:
Timestamp:
Aug 17, 2007, 7:21:24 PM (11 years ago)
Author:
Andrew Sutton
Message:

Renamed almost every function in these files

Location:
sandbox/SOC/2007/graphs/boost/graph
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sandbox/SOC/2007/graphs/boost/graph/closeness_centrality.hpp

    r38625 r38749  
    7373    }
    7474
    75     template <typename Graph,
    76               typename DistanceMap,
    77               typename Measure,
    78               typename Combinator>
     75    template <typename Graph, typename DistanceMap,
     76              typename Measure, typename Combinator>
    7977    inline typename Measure::result_type
    80     vertex_closeness_centrality(const Graph& g,
    81                                 DistanceMap dist,
    82                                 Measure measure,
    83                                 Combinator combine)
     78    closeness_centrality(const Graph& g,
     79                         DistanceMap dist,
     80                         Measure measure,
     81                         Combinator combine)
    8482    {
    8583        function_requires< VertexListGraphConcept<Graph> >();
     
    9290        // NOTE: we could further reduce the requirements on this function
    9391        // by removing the call to num_vertices() and passing that as a
    94         // parameter.
     92        // parameter. I don't know if its worthwhile...
    9593
    9694        Distance n = detail::combine_distances(g, dist, combine, Distance(0));
     
    9896    }
    9997
    100     template <typename Graph,
    101               typename DistanceMap,
    102               typename Measure>
     98    template <typename Graph, typename DistanceMap, typename Measure>
    10399    inline typename Measure::result_type
    104     vertex_closeness_centrality(const Graph& g,
    105                                 DistanceMap dist,
    106                                 Measure measure)
     100    closeness_centrality(const Graph& g, DistanceMap dist, Measure measure)
    107101    {
    108102        function_requires< GraphConcept<Graph> >();
     
    111105        typedef typename property_traits<DistanceMap>::value_type Distance;
    112106
    113         return vertex_closeness_centrality(g, dist, measure, std::plus<Distance>());
     107        return closeness_centrality(g, dist, measure, std::plus<Distance>());
    114108    }
    115109
    116110    template <typename Graph, typename DistanceMap>
    117     inline float
    118     vertex_closeness_centrality(const Graph& g, DistanceMap dist)
     111    inline float closeness_centrality(const Graph& g, DistanceMap dist)
    119112    {
    120         return vertex_closeness_centrality(g, dist, measure_closeness(g, dist));
     113        return closeness_centrality(g, dist, measure_closeness(g, dist));
    121114    }
    122115
    123116    template <typename T, typename Graph, typename DistanceMap>
    124     inline T
    125     vertex_closeness_centrality(const Graph& g, DistanceMap dist)
     117    inline T closeness_centrality(const Graph& g, DistanceMap dist)
    126118    {
    127         return vertex_closeness_centrality(g, dist, measure_closeness<T>(g, dist));
     119        return closeness_centrality(g, dist, measure_closeness<T>(g, dist));
    128120    }
    129121
     
    133125              typename Measure>
    134126    inline void
    135     closeness_centrality(const Graph& g,
    136                          const DistanceMatrixMap& dist,
    137                          CentralityMap cent,
    138                          Measure measure)
     127    all_closeness_centralities(const Graph& g,
     128                               DistanceMatrixMap dist,
     129                               CentralityMap cent,
     130                               Measure measure)
    139131    {
    140132        function_requires< VertexListGraphConcept<Graph> >();
     
    150142        for(tie(i, end) = vertices(g); i != end; ++i) {
    151143            DistanceMap dm = get(dist, *i);
    152             Centrality c = vertex_closeness_centrality(g, dm, measure);
     144            Centrality c = closeness_centrality(g, dm, measure);
    153145            put(cent, *i, c);
    154146        }
     
    159151              typename CentralityMap>
    160152    inline void
    161     closeness_centrality(const Graph& g,
    162                          const DistanceMatrixMap& dist,
    163                          CentralityMap cent)
     153    all_closeness_centralities(const Graph& g,
     154                               DistanceMatrixMap dist,
     155                               CentralityMap cent)
    164156    {
    165157        function_requires< GraphConcept<Graph> >();
     
    171163        typedef typename property_traits<CentralityMap>::value_type Result;
    172164
    173         closeness_centrality(g, dist, cent, measure_closeness<Result>(g, DistanceMap()));
     165        all_closeness_centralities(g, dist, cent, measure_closeness<Result>(g, DistanceMap()));
    174166    }
    175167}
  • sandbox/SOC/2007/graphs/boost/graph/degree_centrality.hpp

    r38601 r38749  
    6363    template <typename Graph, typename Vertex, typename Measure>
    6464    inline typename Measure::degree_type
    65     vertex_degree_centrality(const Graph& g,
    66                              Vertex v,
    67                              Measure measure)
     65    degree_centrality(const Graph& g, Vertex v, Measure measure)
    6866    {
    6967        function_requires< DegreeMeasureConcept<Measure, Graph> >();
     
    7371    template <typename Graph, typename Vertex>
    7472    inline typename graph_traits<Graph>::degree_size_type
    75     vertex_degree_centrality(const Graph& g,
    76                              Vertex v)
     73    degree_centrality(const Graph& g, Vertex v)
    7774    {
    78         return vertex_degree_centrality(g, v, measure_influence(g));
     75        return degree_centrality(g, v, measure_influence(g));
     76    }
     77
     78
     79    // These are just alias functions, intended to provide a more
     80    // "semantic" interface.
     81
     82    template <typename Graph, typename Vertex>
     83    inline typename graph_traits<Graph>::degree_size_type
     84    influence(const Graph& g, Vertex v)
     85    {
     86        return degree_centrality(g, v, measure_influence(g));
     87    }
     88
     89
     90    template <typename Graph, typename Vertex>
     91    inline typename graph_traits<Graph>::degree_size_type
     92    prestige(const Graph& g, Vertex v)
     93    {
     94        return degree_centrality(g, v, measure_prestige(g));
    7995    }
    8096
     
    8298    template <typename Graph, typename CentralityMap, typename Measure>
    8399    inline void
    84     degree_centrality(const Graph& g,
    85                       CentralityMap cent,
    86                       Measure measure)
     100    all_degree_centralities(const Graph& g, CentralityMap cent, Measure measure)
    87101    {
    88102        function_requires< VertexListGraphConcept<Graph> >();
     
    94108        VertexIterator i, end;
    95109        for(tie(i, end) = vertices(g); i != end; ++i) {
    96             Centrality c = vertex_degree_centrality(g, *i, measure);
     110            Centrality c = degree_centrality(g, *i, measure);
    97111            put(cent, *i, c);
    98112        }
     
    100114
    101115    template <typename Graph, typename CentralityMap>
    102     inline void degree_centrality(const Graph& g,
    103                                   CentralityMap cent)
     116    inline void all_degree_centralities(const Graph& g, CentralityMap cent)
    104117    {
    105         degree_centrality(g, cent, measure_influence(g));
     118        all_degree_centralities(g, cent, measure_influence(g));
     119    }
     120
     121    // More helper functions for computing influence and prestige.
     122    // I hate the names of these functions, but influence and prestige
     123    // don't pluralize too well.
     124
     125    template <typename Graph, typename CentralityMap>
     126    inline void all_influence_values(const Graph& g, CentralityMap cent)
     127    {
     128        all_degree_centralities(g, cent, measure_influence(g));
     129    }
     130
     131    template <typename Graph, typename CentralityMap>
     132    inline void all_prestige_values(const Graph& g, CentralityMap cent)
     133    {
     134        all_degree_centralities(g, cent, measure_prestige(g));
    106135    }
    107136}
  • sandbox/SOC/2007/graphs/boost/graph/eccentricity.hpp

    r38681 r38749  
    1717              typename Combinator>
    1818    inline typename property_traits<DistanceMap>::value_type
    19     vertex_eccentricity(const Graph& g,
    20                         DistanceMap dist,
    21                         Combinator combine)
     19    eccentricity(const Graph& g, DistanceMap dist, Combinator combine)
    2220    {
    2321        function_requires< GraphConcept<Graph> >();
     
    3129    template <typename Graph, typename DistanceMap>
    3230    inline typename property_traits<DistanceMap>::value_type
    33     vertex_eccentricity(const Graph& g, DistanceMap dist)
     31    eccentricity(const Graph& g, DistanceMap dist)
    3432    {
    3533        function_requires< GraphConcept<Graph> >();
     
    3836        typedef typename property_traits<DistanceMap>::value_type Distance;
    3937
    40         return vertex_eccentricity(g, dist, detail::maximize<Distance>());
     38        return eccentricity(g, dist, detail::maximize<Distance>());
    4139    }
    4240
    4341    template <typename Graph, typename DistanceMatrix, typename EccentricityMap>
    44     inline void
    45     eccentricity(const Graph& g, const DistanceMatrix& dist, EccentricityMap ecc)
     42    inline std::pair<typename property_traits<EccentricityMap>::value_type,
     43                     typename property_traits<EccentricityMap>::value_type>
     44    all_eccentricities(const Graph& g, const DistanceMatrix& dist, EccentricityMap ecc)
    4645    {
    4746        function_requires< VertexListGraphConcept<Graph> >();
     
    5352        typedef typename property_traits<EccentricityMap>::value_type Eccentricity;
    5453
     54        Eccentricity
     55                r = numeric_values<Eccentricity>::infinity(),
     56                d = numeric_values<Eccentricity>::zero();
    5557        VertexIterator i, end;
     58        tie(i, end) = vertices(g);
    5659        for(tie(i, end) = vertices(g); i != end; ++i) {
    5760            DistanceMap dm = get(dist, *i);
    58             Eccentricity e = vertex_eccentricity(g, dm);
     61            Eccentricity e = eccentricity(g, dm);
    5962            put(ecc, *i, e);
     63
     64            // track the radius and diameter at the same time
     65            r = std::min(r, e);
     66            d = std::max(d, e);
    6067        }
     68        return make_pair(r, d);
    6169    }
    6270
     
    6472    template <typename Graph, typename EccentricityMap>
    6573    inline typename property_traits<EccentricityMap>::value_type
    66     graph_radius(const Graph& g, EccentricityMap ecc)
     74    radius(const Graph& g, EccentricityMap ecc)
    6775    {
    6876        function_requires< VertexListGraphConcept<Graph> >();
     
    8593    template <typename Graph, typename EccentricityMap>
    8694    inline typename property_traits<EccentricityMap>::value_type
    87     graph_diameter(const Graph& g, EccentricityMap ecc)
     95    diameter(const Graph& g, EccentricityMap ecc)
    8896    {
    8997        function_requires< VertexListGraphConcept<Graph> >();
     
    107115    inline std::pair<typename property_traits<EccentricityMap>::value_type,
    108116                     typename property_traits<EccentricityMap>::value_type>
    109     graph_radius_diameter(const Graph& g, EccentricityMap ecc)
     117    radius_diameter(const Graph& g, EccentricityMap ecc)
    110118    {
    111119        function_requires< VertexListGraphConcept<Graph> >();
  • sandbox/SOC/2007/graphs/boost/graph/geodesic_distance.hpp

    r38674 r38749  
    1313namespace boost
    1414{
    15 
    1615    template <typename Graph,
    1716              typename DistanceType,
     
    9695              typename Combinator>
    9796    inline typename Measure::result_type
    98     vertex_mean_geodesic(const Graph& g,
    99                          DistanceMap dist,
    100                          Measure measure,
    101                          Combinator combine)
     97    mean_geodesic(const Graph& g,
     98                  DistanceMap dist,
     99                  Measure measure,
     100                  Combinator combine)
    102101    {
    103102        function_requires< DistanceMeasureConcept<Measure,Graph> >();
     
    112111              typename Measure>
    113112    inline typename Measure::result_type
    114     vertex_mean_geodesic(const Graph& g,
    115                          DistanceMap dist,
    116                          Measure measure)
     113    mean_geodesic(const Graph& g, DistanceMap dist, Measure measure)
    117114    {
    118115        function_requires< DistanceMeasureConcept<Measure,Graph> >();
    119116        typedef typename Measure::distance_type Distance;
    120         return vertex_mean_geodesic(g, dist, measure, std::plus<Distance>());
     117
     118        return mean_geodesic(g, dist, measure, std::plus<Distance>());
    121119    }
    122120
    123121    template <typename Graph, typename DistanceMap>
    124122    inline float
    125     vertex_mean_geodesic(const Graph& g, DistanceMap dist)
    126     {
    127         return vertex_mean_geodesic(g, dist, measure_mean_geodesic(g, dist));
     123    mean_geodesic(const Graph& g, DistanceMap dist)
     124    {
     125        return mean_geodesic(g, dist, measure_mean_geodesic(g, dist));
    128126    }
    129127
    130128    template <typename T, typename Graph, typename DistanceMap>
    131129    inline T
    132     vertex_mean_geodesic(const Graph& g, DistanceMap dist)
    133     {
    134         return vertex_mean_geodesic(g, dist, measure_mean_geodesic<T>(g, dist));
     130    mean_geodesic(const Graph& g, DistanceMap dist)
     131    {
     132        return mean_geodesic(g, dist, measure_mean_geodesic<T>(g, dist));
    135133    }
    136134
     
    140138              typename GeodesicMap,
    141139              typename Measure>
    142     inline void
    143     mean_geodesic(const Graph& g,
    144                   const DistanceMatrixMap& dist,
    145                   GeodesicMap geo,
    146                   Measure measure)
     140    inline typename property_traits<GeodesicMap>::value_type
     141    all_mean_geodesics(const Graph& g,
     142                       DistanceMatrixMap dist,
     143                       GeodesicMap geo,
     144                       Measure measure)
    147145    {
    148146        function_requires< VertexListGraphConcept<Graph> >();
     
    154152        typedef typename Measure::result_type Result;
    155153        function_requires< WritablePropertyMapConcept<GeodesicMap,Vertex> >();
    156 
     154        function_requires< NumericValueConcept<Result> >();
     155
     156        // NOTE: We could compute the mean geodesic here by performing additional
     157        // computations (i.e., adding and dividing). However, I don't really feel
     158        // like fully genericizing the entire operation yet so I'm not going to.
     159
     160        Result inf = numeric_values<Result>::infinity();
     161        Result sum = numeric_values<Result>::zero();
    157162        VertexIterator i, end;
    158163        for(tie(i, end) = vertices(g); i != end; ++i) {
    159164            DistanceMap dm = get(dist, *i);
    160             Result r = vertex_mean_geodesic(g, dm, measure);
     165            Result r = mean_geodesic(g, dm, measure);
    161166            put(geo, *i, r);
     167
     168            // compute the sum along with geodesics
     169            if(r == inf) {
     170                sum = inf;
     171            }
     172            else if(sum != inf) {
     173                sum += r;
     174            }
    162175        }
    163     }
    164 
    165     template <typename Graph,
    166               typename DistanceMatrixMap,
    167               typename GeodesicMap>
    168     inline void
    169     mean_geodesic(const Graph& g,
    170                   const DistanceMatrixMap& dist,
    171                   GeodesicMap geo)
     176
     177        // return the average of averages.
     178        return sum / Result(num_vertices(g));
     179    }
     180
     181    template <typename Graph, typename DistanceMatrixMap, typename GeodesicMap>
     182    inline typename property_traits<GeodesicMap>::value_type
     183    all_mean_geodesics(const Graph& g, DistanceMatrixMap dist, GeodesicMap geo)
    172184    {
    173185        function_requires< GraphConcept<Graph> >();
     
    178190        typedef typename property_traits<GeodesicMap>::value_type Result;
    179191
    180         mean_geodesic(g, dist, geo,
    181                       measure_mean_geodesic<Result>(g, DistanceMap()));
     192        return all_mean_geodesics(g, dist, geo, measure_mean_geodesic<Result>(g, DistanceMap()));
    182193    }
    183194
     
    185196    template <typename Graph, typename GeodesicMap, typename Measure>
    186197    inline typename Measure::result_type
    187     graph_mean_geodesic(const Graph& g, GeodesicMap geo, Measure measure)
     198    small_world_distance(const Graph& g, GeodesicMap geo, Measure measure)
    188199    {
    189200        function_requires< DistanceMeasureConcept<Measure,Graph> >();
     
    196207    template <typename Graph, typename GeodesicMap>
    197208    inline typename property_traits<GeodesicMap>::value_type
    198     graph_mean_geodesic(const Graph& g, GeodesicMap geo)
    199     {
    200         return graph_mean_geodesic(g, geo, measure_graph_mean_geodesic(g, geo));
     209    small_world_distance(const Graph& g, GeodesicMap geo)
     210    {
     211        return small_world_distance(g, geo, measure_graph_mean_geodesic(g, geo));
    201212    }
    202213}
Note: See TracChangeset for help on using the changeset viewer.