// 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 #include #include "graph_community_network.hh" using namespace std; using namespace boost; using namespace graph_tool; typedef ConstantPropertyMap no_eweight_map_t; typedef ConstantPropertyMap no_vweight_map_t; typedef DynamicPropertyMapWrap viweight_map_t; typedef DynamicPropertyMapWrap vweight_map_t; typedef DynamicPropertyMapWrap eiweight_map_t; typedef DynamicPropertyMapWrap eweight_map_t; typedef DynamicPropertyMapWrap voweight_map_t; typedef DynamicPropertyMapWrap eoweight_map_t; struct get_community_network_dispatch { get_community_network_dispatch(bool self_loops): _self_loops(self_loops) {} bool _self_loops; template void operator()(const Graph& g, CommunityGraph& cg, VertexIndex cvertex_index, EdgeIndex cedge_index, CommunityMap s_map, boost::any acs_map, VertexWeightMap vweight, EdgeWeightMap eweight, pair count) const { typedef typename get_prop_type::type comm_t; comm_t cs_map = boost::any_cast(acs_map); typedef typename mpl::if_, viweight_map_t, VertexWeightMap>::type vweight_t; typedef typename mpl::if_, eiweight_map_t, EdgeWeightMap>::type eweight_t; vweight_t vertex_count = boost::any_cast(count.first); eweight_t edge_count = boost::any_cast(count.second); get_community_network()(g, cg, cvertex_index, cedge_index, s_map, cs_map, vweight, eweight, vertex_count, edge_count, _self_loops); } struct get_checked_t { template struct apply { typedef typename PropertyMap::checked_t type; }; }; struct get_identity { template struct apply { typedef PropertyMap type; }; }; template struct get_prop_type { typedef typename mpl::if_::type, get_identity, get_checked_t>::type extract; typedef typename extract::template apply::type type; }; }; 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) { typedef typename mpl::vector::type vweight_properties; typedef typename mpl::vector::type eweight_properties; if (eweight.empty()) { eweight = no_eweight_map_t(1); edge_count = eiweight_map_t(edge_count, edge_scalar_properties()); } else { try { eweight = eweight_map_t(eweight, edge_scalar_properties()); edge_count = eweight_map_t(edge_count, edge_scalar_properties()); } catch (...) { eweight = eoweight_map_t(eweight, edge_properties()); edge_count = eoweight_map_t(edge_count, edge_properties()); } } if (vweight.empty()) { vweight = no_vweight_map_t(1); vertex_count = viweight_map_t(vertex_count, vertex_scalar_properties()); } else { try { vweight = vweight_map_t(vweight, vertex_scalar_properties()); vertex_count = vweight_map_t(vertex_count, vertex_scalar_properties()); } catch (...) { vweight = voweight_map_t(vweight, vertex_properties()); vertex_count = voweight_map_t(vertex_count, vertex_properties()); } } run_action<>()(gi, bind(get_community_network_dispatch(self_loops), _1, ref(cgi.GetGraph()), cgi.GetVertexIndex(), cgi.GetEdgeIndex(), _2, condensed_community_property, _3, _4, make_pair(vertex_count, edge_count)), vertex_scalar_properties(), vweight_properties(), eweight_properties()) (community_property, vweight, eweight); cgi.ReIndexEdges(); }