Commit cc6a4ca2 authored by Tiago Peixoto's avatar Tiago Peixoto

Enable generation of self_loops in condensation_graph()

parent 07911562
......@@ -101,7 +101,7 @@ extern void community_network(GraphInterface& gi, GraphInterface& cgi,
boost::any condensed_community_property,
boost::any vertex_count,
boost::any edge_count, boost::any vweight,
boost::any eweight);
boost::any eweight, bool self_loops);
BOOST_PYTHON_MODULE(libgraph_tool_community)
{
......
......@@ -43,6 +43,9 @@ typedef DynamicPropertyMapWrap<python::object,GraphInterface::edge_t> eoweight_m
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,
class VertexWeightMap, class EdgeWeightMap, class EdgeIndex,
class VertexIndex>
......@@ -66,7 +69,7 @@ struct get_community_network_dispatch
get_community_network()(g, cg, cvertex_index, cedge_index, s_map,
cs_map, vweight, eweight, vertex_count,
edge_count);
edge_count, _self_loops);
}
struct get_checked_t
......@@ -104,7 +107,7 @@ void community_network(GraphInterface& gi, GraphInterface& cgi,
boost::any condensed_community_property,
boost::any vertex_count,
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
vweight_properties;
......@@ -149,8 +152,8 @@ void community_network(GraphInterface& gi, GraphInterface& cgi,
}
}
run_action<>()(gi, bind<void>(get_community_network_dispatch(), _1,
ref(cgi.GetGraph()), cgi.GetVertexIndex(),
run_action<>()(gi, bind<void>(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)),
......
......@@ -44,7 +44,8 @@ struct get_community_network
VertexIndex cvertex_index, EdgeIndex cedge_index,
CommunityMap s_map, CCommunityMap cs_map,
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>::edge_descriptor edge_t;
......@@ -98,7 +99,7 @@ struct get_community_network
{
vertex_t t = target(*e, g);
cvertex_t ct = comm_vertices[get(s_map, t)];
if (ct == cs) // self-loops are pointless
if (ct == cs && !self_loops)
continue;
cedge_t ce;
if (comm_edges.find(make_pair(cs, ct)) != comm_edges.end())
......
......@@ -278,7 +278,7 @@ def modularity(g, prop, weight=None):
return m
def condensation_graph(g, prop, vweight=None, eweight=None):
def condensation_graph(g, prop, vweight=None, eweight=None, self_loops=False):
r"""
Obtain the condensation graph, where each vertex with the same 'prop' value
is condensed in one vertex.
......@@ -293,6 +293,9 @@ def condensation_graph(g, prop, vweight=None, eweight=None):
Vertex property map with the optional vertex weights.
eweight : :class:`~graph_tool.PropertyMap` (optional, default: None)
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
-------
......@@ -355,5 +358,6 @@ def condensation_graph(g, prop, vweight=None, eweight=None):
_prop("v", gp, vcount),
_prop("e", gp, ecount),
_prop("v", g, vweight),
_prop("e", g, eweight))
_prop("e", g, eweight),
self_loops)
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