// graph-tool -- a general graph modification and manipulation thingy // // Copyright (C) 2007-2012 Tiago de Paula Peixoto // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 3 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . #include "graph_filtering.hh" #include "graph.hh" #include "graph_selectors.hh" #include "graph_properties.hh" #include #include #include "graph_community.hh" using namespace std; using namespace boost; using namespace graph_tool; void community_structure(GraphInterface& g, double gamma, string corr_name, size_t n_iter, double Tmin, double Tmax, size_t Nspins, bool new_spins, size_t seed, bool verbose, string history_file, boost::any weight, boost::any property) { typedef property_map_types::apply, GraphInterface::vertex_index_map_t, mpl::bool_ >::type allowed_spin_properties; if (!belongs()(property)) throw ValueException("vertex property is not of integer type int32_t " "or int64_t"); typedef DynamicPropertyMapWrap weight_map_t; typedef ConstantPropertyMap no_weight_map_t; typedef mpl::vector weight_properties; if (weight.empty()) weight = no_weight_map_t(1.0); else weight = weight_map_t(weight, edge_scalar_properties()); comm_corr_t corr; if (corr_name == "erdos") corr = ERDOS_REYNI; else if (corr_name == "uncorrelated") corr = UNCORRELATED; else if (corr_name == "correlated") corr = CORRELATED; else throw ValueException("invalid correlation type: " + corr_name); run_action() (g, bind(get_communities_selector(corr, g.GetVertexIndex()), _1, _2, _3, gamma, n_iter, make_pair(Tmin, Tmax), Nspins, seed, make_pair(verbose,history_file)), weight_properties(), allowed_spin_properties()) (weight, property); } double modularity(GraphInterface& g, boost::any weight, boost::any property) { double modularity = 0; typedef ConstantPropertyMap weight_map_t; typedef mpl::push_back::type edge_props_t; if(weight.empty()) weight = weight_map_t(1); run_action() (g, bind(get_modularity(), _1, _2, _3, ref(modularity)), edge_props_t(), vertex_properties()) (weight, property); return modularity; } using namespace boost::python; extern void community_network(GraphInterface& gi, GraphInterface& cgi, boost::any community_property, boost::any condensed_community_property, boost::any vertex_count, boost::any edge_count, boost::any vweight, boost::any eweight, bool self_loops); BOOST_PYTHON_MODULE(libgraph_tool_community) { def("community_structure", &community_structure); def("modularity", &modularity); def("community_network", &community_network); }