Commit 19d972a1 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Use GraphView in community structure code to obtain undirected graphhs

parent 35c18b6a
......@@ -65,8 +65,6 @@ void community_structure(GraphInterface& g, double gamma, string corr_name,
else
throw ValueException("invalid correlation type: " + corr_name);
bool directed = g.GetDirected();
g.SetDirected(false);
run_action<graph_tool::detail::never_directed>()
(g, bind<void>(get_communities_selector(corr, g.GetVertexIndex()),
_1, _2, _3, gamma, n_iter,
......@@ -74,7 +72,6 @@ void community_structure(GraphInterface& g, double gamma, string corr_name,
seed, make_pair(verbose,history_file)),
weight_properties(), allowed_spin_properties())
(weight, property);
g.SetDirected(directed);
}
......@@ -89,14 +86,10 @@ double modularity(GraphInterface& g, boost::any weight, boost::any property)
if(weight.empty())
weight = weight_map_t(1);
bool directed = g.GetDirected();
g.SetDirected(false);
run_action<graph_tool::detail::never_directed>()
(g, bind<void>(get_modularity(), _1, _2, _3, ref(modularity)),
edge_props_t(), vertex_scalar_properties())
(weight, property);
g.SetDirected(directed);
return modularity;
}
......
......@@ -42,7 +42,7 @@ Contents
from .. dl_import import dl_import
dl_import("import libgraph_tool_community")
from .. import _degree, _prop, Graph, libcore
from .. import _degree, _prop, Graph, GraphView, libcore
import random
import sys
......@@ -207,12 +207,13 @@ def community_structure(g, n_iter, n_spins, gamma=1.0, corr="erdos",
if history_file == None:
history_file = ""
seed = random.randint(0, sys.maxint)
libgraph_tool_community.community_structure(g._Graph__graph, gamma, corr,
ug = GraphView(g, directed=False)
libgraph_tool_community.community_structure(ug._Graph__graph, gamma, corr,
n_iter, t_range[1], t_range[0],
n_spins, new_spins, seed,
verbose, history_file,
_prop("e", g, weight),
_prop("v", g, spins))
_prop("e", ug, weight),
_prop("v", ug, spins))
return spins
......@@ -260,7 +261,7 @@ def modularity(g, prop, weight=None):
>>> from pylab import *
>>> from numpy.random import seed
>>> seed(42)
>>> g = gt.load_graph("community.dot")
>>> g = gt.load_graph("community.xml")
>>> spins = gt.community_structure(g, 10000, 10)
>>> gt.modularity(g, spins)
0.535314188562404
......@@ -272,9 +273,10 @@ def modularity(g, prop, weight=None):
:doi:`10.1073/pnas.0601602103`, :arxiv:`physics/0602124`
"""
m = libgraph_tool_community.modularity(g._Graph__graph,
_prop("e", g, weight),
_prop("v", g, prop))
ug = GraphView(directed=False)
m = libgraph_tool_community.modularity(ug._Graph__graph,
_prop("e", ug, weight),
_prop("v", ug, prop))
return m
......
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