\HeaderA{graph.maxflow}{Maximum flow in a network}{graph.maxflow}
\aliasA{graph.mincut}{graph.maxflow}{graph.mincut}
\keyword{graphs}{graph.maxflow}
\begin{Description}\relax
In a graph where each edge has a given flow capacity the
maximal flow between two vertices is calculated.
\end{Description}
\begin{Usage}
\begin{verbatim}
graph.maxflow(graph, source, target, capacity=NULL)
graph.mincut(graph, source=NULL, target=NULL, capacity=NULL,
       value.only = TRUE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{graph}] The input graph.
\item[\code{source}] The id of the source vertex.
\item[\code{target}] The id of the target vertex (sometimes also called sink).
\item[\code{capacity}] Vector giving the capacity of the edges. If this is
\code{NULL} (the default) then the \code{capacity} edge attribute is
used.
\item[\code{value.only}] Logical scalar, if \code{TRUE} only the minumum cut
value is returned, if \code{FALSE} the edges in the cut and a the
two (or more) partitions are also returned. This currently only
works for undirected graphs.

\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{graph.maxflow} calculates the maximum flow between two vertices
in a weighted (ie. valued) graph. A flow from \code{source} to
\code{target} is an assignment of non-negative real numbers to the
edges of the graph, satisfying two properties: (1) for each edge the
flow (ie. the assigned number) is not more than the capacity of the
edge (the \code{capacity} parameter or edge attribute), (2) for every
vertex, except the source and the target the incoming flow is the same
as the outgoing flow. The value of the flow is the incoming flow of
the \code{target} vertex. The maximum flow is the flow of maximum
value.

\code{graph.mincut} calculates the minimum st-cut between two vertices
in a graph (if the \code{source} and \code{target} arguments are
given) or the minimum cut of the graph (if both \code{source} and
\code{target} are \code{NULL}).

The minimum st-cut between \code{source} and \code{target} is the
minimum total weight of edges needed to remove to eliminate all paths from
\code{source} to \code{target}.

The minimum cut of a graph is the minimum total weight of the edges
needed to remove to separate the graph into (at least) two
components. (Which is to make the graph \emph{not} strongly connected
in the directed case.)

The maximum flow between two vertices in a graph is the same as the minimum
st-cut, so \code{graph.maxflow} and \code{graph.mincut} essentially
calculate the same quantity, the only difference is that
\code{graph.mincut} can be invoked without giving the \code{source}
and \code{target} arguments and then minimum of all possible minimum
cuts is calculated.

Starting from version 0.5 igraph can return the edges in the minimum
cut for undirected graphs.
\end{Details}
\begin{Value}
A numeric constant, the maximum flow, or the minimum cut, except if
\code{value.only=FALSE} for \code{graph.mincut}. In this case a named
list with components:
\begin{ldescription}
\item[\code{value}] Numeric scalar, the cut value.
\item[\code{cut}] Numeric vector, the edges in the cut.
\item[\code{partition1}] The vertices in the first partition after the cut
edges are removed. Note that these vertices might be actually in
different components (after the cut edges are removed), as the
graph may fall apart into more than two components.
\item[\code{partition2}] The vertices in the second partition after the cut
edges are removed. Note that these vertices might be actually in
different components (after the cut edges are removed), as the
graph may fall apart into more than two components.
\end{ldescription}
\end{Value}
\begin{Author}\relax
Gabor Csardi \email{csardi@rmki.kfki.hu}
\end{Author}
\begin{References}\relax
A. V. Goldberg and R. E. Tarjan: ``A New Approach to the Maximum Flow
Problem'' Journal of the ACM 35:921-940, 1988.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{shortest.paths}{shortest.paths}}, \code{\LinkA{edge.connectivity}{edge.connectivity}},
\code{\LinkA{vertex.connectivity}{vertex.connectivity}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
g <- graph.ring(100)
graph.mincut(g, capacity=rep(1,vcount(g)))
graph.mincut(g, value.only=FALSE, capacity=rep(1,vcount(g)))
\end{ExampleCode}
\end{Examples}

