\HeaderA{fastgreedy.community}{Community structure via greedy optimization of modularity}{fastgreedy.community}
\keyword{graphs}{fastgreedy.community}
\begin{Description}\relax
This function tries to find dense subgraph, also called communities in
graphs via directly optimizing a modularity score.
\end{Description}
\begin{Usage}
\begin{verbatim}
fastgreedy.community(graph, merges=TRUE, modularity=TRUE,
      weights=E(graph)$weight)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{graph}] The input graph
\item[\code{merges}] Logical scalar, whether to return the merge matrix.
\item[\code{modularity}] Logcal scalar, whether to return a vector containing
the modularity after each merge.
\item[\code{weights}] If not \code{NULL}, then a numeric vector of edge
weights. The length must match the number of edges in the graph.
By default the \sQuote{\code{weight}} edge attribute is used as
weights. If it is not present, then all edges are considered to have
the same weight.

\end{ldescription}
\end{Arguments}
\begin{Details}\relax
This function implements the fast greedy modularity optimization
algorithm for finding community structure, see 
A Clauset, MEJ Newman, C Moore: Finding community structure in very
large networks, http://www.arxiv.org/abs/cond-mat/0408187 for the
details.
\end{Details}
\begin{Value}
A named list with the following members:
\begin{ldescription}
\item[\code{merges}] A matrix with two column, this represents a dendogram
and contains all the merges the algorithm performed. Each line is
one merge and it is given by the ids of the two communities
merged. The community ids are integer numbers starting from zero
and the communities between zero and the number of vertices
(\code{N}) minus one belong to individual vertices. The first line
of the matrix gives the first merge, this merge creates community
\code{N}, the number of vertices, the second merge creates
community \code{N+1}, etc.

\item[\code{modularity}] A numeric vector containing the modularity value 
of the community structure after performing every merge.

\end{ldescription}
\end{Value}
\begin{Author}\relax
Tamas Nepusz \email{ntamas@rmki.kfki.hu} and Gabor Csardi
\email{csardi@rmki.kfki.hu} for the R interface.
\end{Author}
\begin{References}\relax
A Clauset, MEJ Newman, C Moore: Finding community structure in very
large networks, http://www.arxiv.org/abs/cond-mat/0408187
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{walktrap.community}{walktrap.community}},
\code{\LinkA{spinglass.community}{spinglass.community}},
\code{\LinkA{leading.eigenvector.community}{leading.eigenvector.community}},
\code{\LinkA{edge.betweenness.community}{edge.betweenness.community}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
g <- graph.full(5) %du% graph.full(5) %du% graph.full(5)
g <- add.edges(g, c(0,5, 0,10, 5, 10))
fastgreedy.community(g)
# The highest value of modularity is before performing the last two
# merges. So this network naturally has three communities.
\end{ExampleCode}
\end{Examples}

