Commit cc6a4ca2 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Enable generation of self_loops in condensation_graph()

parent 07911562
...@@ -101,7 +101,7 @@ extern void community_network(GraphInterface& gi, GraphInterface& cgi, ...@@ -101,7 +101,7 @@ extern void community_network(GraphInterface& gi, GraphInterface& cgi,
boost::any condensed_community_property, boost::any condensed_community_property,
boost::any vertex_count, boost::any vertex_count,
boost::any edge_count, boost::any vweight, boost::any edge_count, boost::any vweight,
boost::any eweight); boost::any eweight, bool self_loops);
BOOST_PYTHON_MODULE(libgraph_tool_community) BOOST_PYTHON_MODULE(libgraph_tool_community)
{ {
......
...@@ -43,6 +43,9 @@ typedef DynamicPropertyMapWrap<python::object,GraphInterface::edge_t> eoweight_m ...@@ -43,6 +43,9 @@ typedef DynamicPropertyMapWrap<python::object,GraphInterface::edge_t> eoweight_m
struct get_community_network_dispatch struct get_community_network_dispatch
{ {
get_community_network_dispatch(bool self_loops): _self_loops(self_loops) {}
bool _self_loops;
template <class Graph, class CommunityGraph, class CommunityMap, template <class Graph, class CommunityGraph, class CommunityMap,
class VertexWeightMap, class EdgeWeightMap, class EdgeIndex, class VertexWeightMap, class EdgeWeightMap, class EdgeIndex,
class VertexIndex> class VertexIndex>
...@@ -66,7 +69,7 @@ struct get_community_network_dispatch ...@@ -66,7 +69,7 @@ struct get_community_network_dispatch
get_community_network()(g, cg, cvertex_index, cedge_index, s_map, get_community_network()(g, cg, cvertex_index, cedge_index, s_map,
cs_map, vweight, eweight, vertex_count, cs_map, vweight, eweight, vertex_count,
edge_count); edge_count, _self_loops);
} }
struct get_checked_t struct get_checked_t
...@@ -104,7 +107,7 @@ void community_network(GraphInterface& gi, GraphInterface& cgi, ...@@ -104,7 +107,7 @@ void community_network(GraphInterface& gi, GraphInterface& cgi,
boost::any condensed_community_property, boost::any condensed_community_property,
boost::any vertex_count, boost::any vertex_count,
boost::any edge_count, boost::any vweight, boost::any edge_count, boost::any vweight,
boost::any eweight) boost::any eweight, bool self_loops)
{ {
typedef typename mpl::vector<vweight_map_t, voweight_map_t, no_vweight_map_t>::type typedef typename mpl::vector<vweight_map_t, voweight_map_t, no_vweight_map_t>::type
vweight_properties; vweight_properties;
...@@ -149,8 +152,8 @@ void community_network(GraphInterface& gi, GraphInterface& cgi, ...@@ -149,8 +152,8 @@ void community_network(GraphInterface& gi, GraphInterface& cgi,
} }
} }
run_action<>()(gi, bind<void>(get_community_network_dispatch(), _1, run_action<>()(gi, bind<void>(get_community_network_dispatch(self_loops),
ref(cgi.GetGraph()), cgi.GetVertexIndex(), _1, ref(cgi.GetGraph()), cgi.GetVertexIndex(),
cgi.GetEdgeIndex(), _2, cgi.GetEdgeIndex(), _2,
condensed_community_property, condensed_community_property,
_3, _4, make_pair(vertex_count, edge_count)), _3, _4, make_pair(vertex_count, edge_count)),
......
...@@ -44,7 +44,8 @@ struct get_community_network ...@@ -44,7 +44,8 @@ struct get_community_network
VertexIndex cvertex_index, EdgeIndex cedge_index, VertexIndex cvertex_index, EdgeIndex cedge_index,
CommunityMap s_map, CCommunityMap cs_map, CommunityMap s_map, CCommunityMap cs_map,
VertexWeightMap vweight, EdgeWeightMap eweight, VertexWeightMap vweight, EdgeWeightMap eweight,
VertexProperty vertex_count, EdgeProperty edge_count) const VertexProperty vertex_count, EdgeProperty edge_count,
bool self_loops) const
{ {
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t; typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
typedef typename graph_traits<Graph>::edge_descriptor edge_t; typedef typename graph_traits<Graph>::edge_descriptor edge_t;
...@@ -98,7 +99,7 @@ struct get_community_network ...@@ -98,7 +99,7 @@ struct get_community_network
{ {
vertex_t t = target(*e, g); vertex_t t = target(*e, g);
cvertex_t ct = comm_vertices[get(s_map, t)]; cvertex_t ct = comm_vertices[get(s_map, t)];
if (ct == cs) // self-loops are pointless if (ct == cs && !self_loops)
continue; continue;
cedge_t ce; cedge_t ce;
if (comm_edges.find(make_pair(cs, ct)) != comm_edges.end()) if (comm_edges.find(make_pair(cs, ct)) != comm_edges.end())
......
...@@ -278,7 +278,7 @@ def modularity(g, prop, weight=None): ...@@ -278,7 +278,7 @@ def modularity(g, prop, weight=None):
return m return m
def condensation_graph(g, prop, vweight=None, eweight=None): def condensation_graph(g, prop, vweight=None, eweight=None, self_loops=False):
r""" r"""
Obtain the condensation graph, where each vertex with the same 'prop' value Obtain the condensation graph, where each vertex with the same 'prop' value
is condensed in one vertex. is condensed in one vertex.
...@@ -293,6 +293,9 @@ def condensation_graph(g, prop, vweight=None, eweight=None): ...@@ -293,6 +293,9 @@ def condensation_graph(g, prop, vweight=None, eweight=None):
Vertex property map with the optional vertex weights. Vertex property map with the optional vertex weights.
eweight : :class:`~graph_tool.PropertyMap` (optional, default: None) eweight : :class:`~graph_tool.PropertyMap` (optional, default: None)
Edge property map with the optional edge weights. Edge property map with the optional edge weights.
self_loops : ``bool`` (optional, default: ``False``)
If ``True``, self-loops due to intra-block edges are also included in
the condensation graph.
Returns Returns
------- -------
...@@ -355,5 +358,6 @@ def condensation_graph(g, prop, vweight=None, eweight=None): ...@@ -355,5 +358,6 @@ def condensation_graph(g, prop, vweight=None, eweight=None):
_prop("v", gp, vcount), _prop("v", gp, vcount),
_prop("e", gp, ecount), _prop("e", gp, ecount),
_prop("v", g, vweight), _prop("v", g, vweight),
_prop("e", g, eweight)) _prop("e", g, eweight),
self_loops)
return gp, cprop, vcount, ecount return gp, cprop, vcount, ecount
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment