optimal.community(graph)
optimal.community
returns a communities
object, please see the communities
manual page for
details.Note that modularity optimization is an NP-complete problem, and all known algorithms for it have exponential time complexity. This means that you probably don't want to run this function on larger graphs. Graphs with up to fifty vertices should be fine, graphs with a couple of hundred vertices might be possible.
communities
for the documentation of the result,
modularity
. See also fastgreedy.community
for a fast greedy optimizer.## Zachary's karate club
g <- graph.famous("Zachary")
## We put everything into a big 'try' block, in case
## igraph was compiled without GLPK support
try({
## The calculation only takes a couple of seconds
oc <- optimal.community(g)
## Double check the result
print(modularity(oc))
print(modularity(g, membership(oc)))
## Compare to the greedy optimizer
fc <- fastgreedy.community(g)
print(modularity(fc))
}, silent=TRUE)
Run the code above in your browser using DataLab