\HeaderA{graph.density}{Graph density}{graph.density}
\keyword{graphs}{graph.density}
\begin{Description}\relax
The density of a graph is the ratio of the number of edges
and the number of possible edges.
\end{Description}
\begin{Usage}
\begin{verbatim}
graph.density(graph, loops=FALSE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{graph}] The input graph.
\item[\code{loops}] Logical constant, whether to allow loop edges in the
graph. If this is TRUE then self loops are considered to be possible. If
this is FALSE then we assume that the graph does not contain any
loop edges and that loop edges are not meaningful.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Note that this function may return strange results for graph with
multiple edges, density is ill-defined for graphs with multiple
edges.
\end{Details}
\begin{Value}
A real constant. This function returns \code{NaN} (=0.0/0.0) for an
empty graph with zero vertices.
\end{Value}
\begin{Author}\relax
Gabor Csardi \email{csardi@rmki.kfki.hu}
\end{Author}
\begin{References}\relax
Wasserman, S., and Faust, K.  (1994).  Social Network Analysis:
Methods and Applications.  Cambridge: Cambridge University Press.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{vcount}{vcount}}, \code{\LinkA{ecount}{ecount}},
\code{\LinkA{simplify}{simplify}} to get rid of the multiple and/or loop edges.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
g1 <- graph.empty(n=10)
g2 <- graph.full(n=10)
g3 <- erdos.renyi.game(n=10, 0.4)

# loop edges
g <- graph( c(0,1, 1,1, 1,2) )
graph.density(g, loops=FALSE)              # this is wrong!!!
graph.density(g, loops=TRUE)               # this is right!!!
graph.density(simplify(g), loops=FALSE)    # this is also right, but different
\end{ExampleCode}
\end{Examples}

