Changeset ba2aee


Ignore:
Timestamp:
06/30/07 23:39:31 (6 years ago)
Author:
Tiago de Paula Peixoto <tiago@…>
Branches:
master, python3
Children:
0075ec
Parents:
d199d4
git-author:
Tiago de Paula Peixoto <tiago@…> (06/30/07 23:39:31)
git-committer:
Tiago de Paula Peixoto <tiago@…> (06/30/07 23:39:31)
Message:
* add support for betweenness centrality 
* change from HashedDescriptorMap to vector_property_map in several
  algorithms to save memory and increase speed in the most common
  case, where the graph is unfiltered.




git-svn-id: https://svn.forked.de/graph-tool/trunk@102 d4600afd-f417-0410-95de-beed9576f240
Location:
src
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • src/graph-tool

    rd199d4 rba2aee  
    11#! /usr/bin/env python 
     2# graph-tool -- a general graph modification and manipulation thingy 
     3# 
    24# Copyright (C) 2007 Tiago de Paula Peixoto <tiago@forked.de> 
    35# 
     
    112114statistics.add_option("--minimum-spanning-tree", action="callback", callback=push_option, type="string", metavar="[WEIGHT|]PROPERTY", help="mark the minimum spanning tree edges in PROPERTY") 
    113115statistics.add_option("--line-graph", action="callback", callback=push_option, type="string", metavar="FILE[|FORMAT]", help="save the corresponding line graph to FILE") 
     116statistics.add_option("--betweenness-centrality", action="callback", callback=push_option, type="string", metavar="VERTEX_BETWEENESS[EDGE_BETWEENESS]", help="calculate and store the vertex and/or edge betweenness centrality") 
    114117 
    115118correlations =  parser.add_option_group("Correlations") 
     
    504507            format = "" 
    505508        graph.GetLineGraph(values[0], format) 
     509    elif opt.name == "betweenness-centrality": 
     510        values = parse_values(opt.value) 
     511        if len(values) < 1 or len(values) > 3: 
     512            raise OptionError(opt.name, "invalid value '%s'" % opt.value) 
     513        if just_file: 
     514            return None 
     515        vertex_centrality = values[0] 
     516        if len(values) > 1: 
     517            edge_centrality = values[1] 
     518        else: 
     519            edge_centrality = "" 
     520        if len(values) > 2: 
     521            weight = values[2] 
     522        else: 
     523            weight = "" 
     524        graph.GetBetweenness(weight, vertex_centrality, edge_centrality) 
    506525    elif opt.name == "vertex-correlation-histogram": 
    507526        values = parse_values(opt.value) 
  • src/graph/Makefile.am

    r0c9826 rba2aee  
    4141    graph_community_network.cc\ 
    4242    graph_line_graph.cc\ 
     43    graph_betweenness.cc\ 
    4344    graph_io.cc\ 
    4445    graph_bind.cc\ 
  • src/graph/graph.hh

    rd199d4 rba2aee  
    9898    void   GetMinimumSpanningTree(std::string weight, std::string property); 
    9999    void   GetLineGraph(std::string out_file, std::string format); 
     100    void   GetBetweenness(std::string weight, std::string edge_betweenness, std::string vertex_betweenness); 
    100101 
    101102    // community structure 
  • src/graph/graph_adaptor.hh

    rd199d4 rba2aee  
    358358}; 
    359359 
     360template <class Graph> 
     361struct graph_traits< const UndirectedAdaptor<Graph> >: public graph_traits< UndirectedAdaptor<Graph> > {}; 
     362 
    360363//============================================================================== 
    361364// Nonmember functions 
  • src/graph/graph_bind.cc

    rd199d4 rba2aee  
    240240        .def("GetMinimumSpanningTree", &GraphInterfaceWrap::GetMinimumSpanningTree) 
    241241        .def("GetLineGraph", &GraphInterfaceWrap::GetLineGraph) 
     242        .def("GetBetweenness", &GraphInterfaceWrap::GetBetweenness) 
    242243        .def("GetCommunityStructure", &GraphInterfaceWrap::GetCommunityStructure) 
    243244        .def("GetCommunityNetwork", &GraphInterfaceWrap::GetCommunityNetwork) 
  • src/graph/graph_clustering.cc

    rd199d4 rba2aee  
    198198void GraphInterface::SetLocalClusteringToProperty(string property) 
    199199{ 
    200     typedef HashedDescriptorMap<vertex_index_map_t,double> clust_map_t; 
     200    typedef vector_property_map<double,vertex_index_map_t> clust_map_t; 
    201201    clust_map_t clust_map(_vertex_index); 
    202202 
  • src/graph/graph_community.cc

    rd199d4 rba2aee  
    652652void GraphInterface::GetCommunityStructure(double gamma, comm_corr_t corr, size_t n_iter, double Tmin, double Tmax, size_t Nspins, size_t seed, bool verbose, string history_file, string weight, string property) 
    653653{ 
    654     typedef HashedDescriptorMap<vertex_index_map_t,size_t> comm_map_t; 
     654    typedef vector_property_map<size_t,vertex_index_map_t> comm_map_t; 
    655655    comm_map_t comm_map(_vertex_index); 
    656656 
  • src/graph/graph_extended_clustering.cc

    rd199d4 rba2aee  
    159159void GraphInterface::SetExtendedClusteringToProperty(string property_prefix, size_t max_depth) 
    160160{ 
    161     typedef HashedDescriptorMap<vertex_index_map_t,double> cmap_t; 
     161    typedef vector_property_map<double, vertex_index_map_t> cmap_t; 
    162162    vector<cmap_t> cmaps(max_depth); 
    163163    for (size_t i = 0; i < cmaps.size(); ++i) 
  • src/graph/graph_filtering.hh

    rd199d4 rba2aee  
    4141#endif 
    4242 
     43// some additional functions... 
     44namespace boost 
     45{ 
     46//============================================================================== 
     47// vertex(i, filtered_graph<G>) 
     48//============================================================================== 
     49template <class Graph, class EdgePredicate, class VertexPredicate>  
     50typename graph_traits<filtered_graph<Graph,EdgePredicate,VertexPredicate> >::vertex_descriptor 
     51vertex(size_t i, const filtered_graph<Graph,EdgePredicate,VertexPredicate>& g) 
     52{ 
     53    typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g.m_g); 
     54    if (g.m_vertex_pred(v)) 
     55        return v; 
     56    else 
     57        return graph_traits<Graph>::null_vertex(); 
     58} 
     59 
     60//============================================================================== 
     61// vertex(i, reverse_graph<G>) 
     62//============================================================================== 
     63template <class Graph>  
     64typename graph_traits<reverse_graph<Graph> >::vertex_descriptor 
     65vertex(size_t i, const reverse_graph<Graph>& g) 
     66{ 
     67    return vertex(i, g.m_g); 
     68} 
     69 
     70} // namespace boost 
     71 
     72 
    4373namespace graph_tool 
    4474{ 
     
    97127}; 
    98128 
    99  
    100 //============================================================================== 
    101 // vertex(i, filtered_graph<G>) 
    102 //============================================================================== 
    103 template <class Graph, class EdgePredicate, class VertexPredicate>  
    104 typename graph_traits<filtered_graph<Graph,EdgePredicate,VertexPredicate> >::vertex_descriptor 
    105 vertex(size_t i, const filtered_graph<Graph,EdgePredicate,VertexPredicate>& g) 
    106 { 
    107     typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g.m_g); 
    108     if (g.m_vertex_pred(v)) 
    109         return v; 
    110     else 
    111         return graph_traits<Graph>::null_vertex(); 
    112 } 
    113  
    114 //============================================================================== 
    115 // vertex(i, reverse_graph<G>) 
    116 //============================================================================== 
    117 template <class Graph>  
    118 typename graph_traits<reverse_graph<Graph> >::vertex_descriptor 
    119 vertex(size_t i, const reverse_graph<Graph>& g) 
    120 { 
    121     return vertex(i, g.m_g); 
    122 } 
    123  
    124  
    125129//============================================================================== 
    126130// RangeFilter 
  • src/graph/graph_io.cc

    rd199d4 rba2aee  
    6767//============================================================================== 
    6868 
    69 typedef mpl::vector<bool, int, long, float, double, string> value_types; 
    70  
    7169template <class VertexIndexMap, class EdgeIndexMap> 
    7270struct create_dynamic_map 
  • src/graph/graph_minimum_spanning_tree.cc

    rd199d4 rba2aee  
    5656void GraphInterface::GetMinimumSpanningTree(string weight, string property) 
    5757{ 
    58     typedef HashedDescriptorMap<edge_index_map_t,size_t> tree_map_t; 
     58    typedef vector_property_map<size_t, edge_index_map_t> tree_map_t; 
    5959    tree_map_t tree_map(_edge_index); 
    6060 
  • src/graph/graph_properties.cc

    rd199d4 rba2aee  
    3535using namespace graph_tool; 
    3636 
    37 typedef mpl::vector<bool, int, long, size_t, float, double, std::string> value_types; 
     37namespace graph_tool 
     38{ 
     39// global property types 
    3840const char* type_names[] = {"boolean", "int", "long", "long", "float", "double", "string"}; 
    3941 
     42// scalar types 
     43const char* scalar_names[] = {"boolean", "int", "long", "long", "float", "double"}; 
     44} 
    4045 
    4146//============================================================================== 
  • src/graph/graph_properties.hh

    rd199d4 rba2aee  
    3232{ 
    3333 
     34// global property types 
     35typedef boost::mpl::vector<bool, int, long, size_t, float, double, std::string> value_types; 
     36extern const char* type_names[]; 
     37 
     38// scalar types 
     39typedef boost::mpl::vector<bool, int, long, size_t, float, double> scalar_types; 
     40extern const char* scalar_names[]; 
     41 
     42 
     43 
    3444//============================================================================== 
    3545// Property Map Utility Functions 
Note: See TracChangeset for help on using the changeset viewer.