File: max_flow.Rd

package info (click to toggle)
r-cran-igraph 1.0.1-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 18,232 kB
  • sloc: ansic: 173,538; cpp: 19,365; fortran: 4,550; yacc: 1,164; tcl: 931; lex: 484; makefile: 149; sh: 9
file content (77 lines) | stat: -rw-r--r-- 3,314 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/flow.R
\name{max_flow}
\alias{graph.maxflow}
\alias{max_flow}
\title{Maximum flow in a graph}
\usage{
max_flow(graph, source, target, capacity = NULL)
}
\arguments{
\item{graph}{The input graph.}

\item{source}{The id of the source vertex.}

\item{target}{The id of the target vertex (sometimes also called sink).}

\item{capacity}{Vector giving the capacity of the edges. If this is
\code{NULL} (the default) then the \code{capacity} edge attribute is used.}
}
\value{
A named list with components:
  \item{value}{A numeric scalar, the value of the maximum flow.}
  \item{flow}{A numeric vector, the flow itself, one entry for each
    edge. For undirected graphs this entry is bit trickier, since for
    these the flow direction is not predetermined by the edge
    direction. For these graphs the elements of the this vector can be
    negative, this means that the flow goes from the bigger vertex id to
    the smaller one. Positive values mean that the flow goes from
    the smaller vertex id to the bigger one.}
  \item{cut}{A numeric vector of edge ids, the minimum cut corresponding
    to the maximum flow.}
  \item{partition1}{A numeric vector of vertex ids, the vertices in the
    first partition of the minimum cut corresponding to the maximum
    flow.}
  \item{partition2}{A numeric vector of vertex ids, the vertices in the
    second partition of the minimum cut corresponding to the maximum
    flow.}
  \item{stats}{A list with some statistics from the push-relabel
    algorithm. Five integer values currently: \code{nopush} is the
    number of push operations, \code{norelabel} the number of
    relabelings, \code{nogap} is the number of times the gap heuristics
    was used, \code{nogapnodes} is the total number of gap nodes omitted
    because of the gap heuristics and \code{nobfs} is the number of
    times a global breadth-first-search update was performed to assign
    better height (=distance) values to the vertices.}
}
\description{
In a graph where each edge has a given flow capacity the maximal flow
between two vertices is calculated.
}
\details{
\code{max_flow} 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.
}
\examples{
E <- rbind( c(1,3,3), c(3,4,1), c(4,2,2), c(1,5,1), c(5,6,2), c(6,2,10))
colnames(E) <- c("from", "to", "capacity")
g1 <- graph_from_data_frame(as.data.frame(E))
max_flow(g1, source=V(g1)["1"], target=V(g1)["2"])
}
\references{
A. V. Goldberg and R. E. Tarjan: A New Approach to the Maximum
Flow Problem \emph{Journal of the ACM} 35:921-940, 1988.
}
\seealso{
\code{\link{min_cut}} for minimum cut calculations,
  \code{\link{distances}}, \code{\link{edge_connectivity}},
  \code{\link{vertex_connectivity}}
}