351 lines
8.7 KiB
TeX
Raw Normal View History

2022-11-21 22:01:21 -08:00
\section{Network Flow}
\generic{Networks}
2023-01-08 09:10:54 -08:00
Say have a network: a sequence of pipes, a set of cities and highways, an electrical circuit, etc.
2022-11-21 22:01:21 -08:00
\vspace{1ex}
2023-01-08 09:10:54 -08:00
We can draw this network as a directed weighted graph. If we take a transporation network, for example, edges will represent highways and nodes will be cities. There are a few conditions for a valid network graph:
2022-11-21 22:01:21 -08:00
\begin{itemize}
2023-01-08 09:10:54 -08:00
\item The weight of each edge represents its capacity, e.g, the number of lanes in the highway.
2022-11-21 22:01:21 -08:00
\item Edge capacities are always positive integers.\hspace{-0.5ex}\footnotemark{}
\item Node $S$ is a \textit{source}: it produces flow.
\item Node $T$ is a \textit{sink}: it consumes flow.
2023-01-08 09:10:54 -08:00
\item All other nodes \textit{conserve} flow. The sum of flow coming in must equal the sum of flow going out.
2022-11-21 22:01:21 -08:00
\end{itemize}
\footnotetext{An edge with capacity zero is equivalent to an edge that does not exist; An edge with negative capacity is equivalent to an edge in the opposite direction.}
2023-01-08 09:10:54 -08:00
Here is an example of such a graph:
2022-11-21 22:01:21 -08:00
\begin{center}
\begin{tikzpicture}
% Nodes
\begin{scope}[layer = nodes]
\node[main] (S) at (+00mm, +00mm) {$S$};
\node[main] (A) at (+15mm, +15mm) {$A$};
\node[main] (B) at (+15mm, -15mm) {$B$};
\node[main] (T) at (+30mm, +00mm) {$T$};
\end{scope}
% Edges
\draw[->]
(S) edge node[label] {$1$} (A)
(A) edge node[label] {$4$} (T)
(B) edge node[label] {$2$} (A)
(S) edge node[label] {$2$} (B)
(B) edge node[label] {$1$} (T)
;
\end{tikzpicture}
\end{center}
\hrule{}
\generic{Flow}
2023-01-08 09:10:54 -08:00
In our city example, traffic represents \textit{flow}. Let's send one unit of traffic along the topmost highway:
2022-11-21 22:01:21 -08:00
\vspace{2ex}
\begin{minipage}{0.33\textwidth}
\begin{center}
\begin{tikzpicture}
% Nodes
\begin{scope}[layer = nodes]
\node[main] (S) at (+00mm, +00mm) {$S$};
\node[main] (A) at (+15mm, +15mm) {$A$};
\node[main] (B) at (+15mm, -15mm) {$B$};
\node[main] (T) at (+30mm, +00mm) {$T$};
\end{scope}
% Edges
\draw[->]
(S) edge node[label] {$1$} (A)
(A) edge node[label] {$4$} (T)
(B) edge node[label] {$2$} (A)
(S) edge node[label] {$2$} (B)
(B) edge node[label] {$1$} (T)
;
% Flow
\draw[path]
(S) -- node[above left, flow] {$(1)$} (A)
-- node[above right, flow] {$(1)$} (T)
;
\end{tikzpicture}
\end{center}
\end{minipage}
\begin{minipage}{0.65\textwidth}
There are a few things to notice here:
2022-11-13 13:03:14 -08:00
\begin{itemize}
2022-11-21 22:01:21 -08:00
\item Highlighted edges carry flow.
\item Numbers in parentheses tell us how much flow each edge carries.
\item The flow along an edge is always positive or zero.
\item Flow comes from $S$ and goes towards $T$.
\item Flow is conserved: all flow produced by $S$ enters $T$.
2022-11-13 13:03:14 -08:00
\end{itemize}
2022-11-21 22:01:21 -08:00
\end{minipage}
\vspace{1ex}
2023-01-08 09:10:54 -08:00
The \textit{magnitude} of a flow is the number of \say{flow-units} that go from $S$ to $T$. \\
2022-11-21 22:01:21 -08:00
2023-01-08 09:10:54 -08:00
We are interested in the \textit{maximum flow} through this network: what is the greatest amount of flow we can get from $S$ to $T$?
2022-11-21 22:01:21 -08:00
\problem{}
What is the magnitude of the flow above?
\vfill
\pagebreak
\problem{}
Find a flow with magnitude 2 on the graph below.
\begin{center}
\begin{tikzpicture}
% Nodes
\begin{scope}[layer = nodes]
\node[main] (S) at (+00mm, +00mm) {$S$};
\node[main] (A) at (+15mm, +15mm) {$A$};
\node[main] (B) at (+15mm, -15mm) {$B$};
\node[main] (T) at (+30mm, +00mm) {$T$};
\end{scope}
% Edges
\draw[->]
(S) edge node[label] {$1$} (A)
(A) edge node[label] {$4$} (T)
(B) edge node[label] {$2$} (A)
(S) edge node[label] {$2$} (B)
(B) edge node[label] {$1$} (T)
;
\end{tikzpicture}
\end{center}
\vfill
\problem{}
Find a maximal flow on the graph below. \\
\hint{The total capacity coming out of $S$ is 3, so any flow must have magnitude $\leq 3$.}
\begin{center}
\begin{tikzpicture}
% Nodes
\begin{scope}[layer = nodes]
\node[main] (S) at (+00mm, +00mm) {$S$};
\node[main] (A) at (+15mm, +15mm) {$A$};
\node[main] (B) at (+15mm, -15mm) {$B$};
\node[main] (T) at (+30mm, +00mm) {$T$};
\end{scope}
% Edges
\draw[->]
(S) edge node[label] {$1$} (A)
(A) edge node[label] {$4$} (T)
(B) edge node[label] {$2$} (A)
(S) edge node[label] {$2$} (B)
(B) edge node[label] {$1$} (T)
;
\end{tikzpicture}
\end{center}
\vfill
\pagebreak
\section{Combining Flows}
2023-01-08 09:10:54 -08:00
It is fairly easy to combine two flows on a graph. All we need to do is add the flows along each edge. \\
Consider the following flows:
2022-11-21 22:01:21 -08:00
\vspace{2ex}
\begin{minipage}[t]{0.48\textwidth}
\begin{center}
\begin{tikzpicture}
% Nodes
\begin{scope}[layer = nodes]
\node[main] (S) at (+00mm, +00mm) {$S$};
\node[main] (A) at (+15mm, +15mm) {$A$};
\node[main] (B) at (+15mm, -15mm) {$B$};
\node[main] (T) at (+30mm, +00mm) {$T$};
\end{scope}
% Edges
\draw[->]
(S) edge node[label] {$1$} (A)
(A) edge node[label] {$2$} (T)
(B) edge node[label] {$2$} (A)
(S) edge node[label] {$2$} (B)
(B) edge node[label] {$1$} (T)
;
% Flow
\draw[path]
(S) -- node[above left, flow] {$(1)$} (A)
-- node[above right, flow] {$(1)$} (T)
;
\end{tikzpicture}
\end{center}
\end{minipage}
\hfill
\begin{minipage}[t]{0.48\textwidth}
\begin{center}
\begin{tikzpicture}
% Nodes
\begin{scope}[layer = nodes]
\node[main] (S) at (+00mm, +00mm) {$S$};
\node[main] (A) at (+15mm, +15mm) {$A$};
\node[main] (B) at (+15mm, -15mm) {$B$};
\node[main] (T) at (+30mm, +00mm) {$T$};
\end{scope}
% Edges
\draw[->]
(S) edge node[label] {$1$} (A)
(A) edge node[label] {$2$} (T)
(B) edge node[label] {$2$} (A)
(S) edge node[label] {$2$} (B)
(B) edge node[label] {$1$} (T)
;
% Flow
\draw[path]
(S)
-- node[below left, flow] {$(1)$} (B)
-- node[left, flow] {$(1)$} (A)
-- node[above right, flow] {$(1)$} (T)
;
\end{tikzpicture}
\end{center}
\end{minipage}
\vspace{1cm}
\begin{minipage}[t]{0.48\textwidth}
\begin{center}
Combining these, we get the following:
2022-11-13 13:03:14 -08:00
\vspace{2ex}
2022-11-21 22:01:21 -08:00
\begin{tikzpicture}
% Nodes
\begin{scope}[layer = nodes]
\node[main] (S) at (+00mm, +00mm) {$S$};
\node[main] (A) at (+15mm, +15mm) {$A$};
\node[main] (B) at (+15mm, -15mm) {$B$};
\node[main] (T) at (+30mm, +00mm) {$T$};
\end{scope}
% Edges
\draw[->]
(S) edge node[label] {$1$} (A)
(A) edge node[label] {$2$} (T)
(B) edge node[label] {$2$} (A)
(S) edge node[label] {$2$} (B)
(B) edge node[label] {$1$} (T)
;
% Flow
\draw[path]
(S)
-- node[below left, flow] {$(1)$} (B)
-- node[left, flow] {$(1)$} (A)
-- node[above right, flow] {$(2) = (1) + (1)$} (T)
(S)
-- node[above left, flow] {$(1)$} (A)
;
\end{tikzpicture}
\end{center}
\end{minipage}
\hfill
\begin{minipage}[t]{0.48\textwidth}
\raggedright
When adding flows, we must respect edge capacities.
2022-11-13 13:03:14 -08:00
\vspace{1ex}
2023-01-08 09:10:54 -08:00
For example, we could not add these graphs if the magnitude of flow in the right graph above was 2, since the capacity of the top-right edge is 2, and $2 + 1 > 2$.
2022-11-21 22:01:21 -08:00
\end{minipage}
\vspace{2ex}
\hrule
\vspace{2ex}
\problem{}
2023-01-08 09:10:54 -08:00
Combine the flows below, ensuring that the flow along each edge remains within capacity.
2022-11-21 22:01:21 -08:00
\vspace{2ex}
\begin{minipage}[t]{0.48\textwidth}
\begin{center}
\begin{tikzpicture}[node distance = 20mm]
% Nodes
\begin{scope}[layer = nodes]
\node[main] (S) {$S$};
\node[main] (A) [above right of = S] {$A$};
\node[main] (B) [below right of = S] {$B$};
\node[main] (C) [right of = A] {$C$};
\node[main] (D) [right of = B] {$D$};
\node[main] (T) [above right of = D] {$T$};
\end{scope}
% Edges
\draw[->]
(S) edge node[label] {$5$} (A)
(A) edge node[label] {$3$} (C)
(C) edge node[label] {$2$} (T)
(A) edge node[label] {$4$} (D)
(S) edge node[label] {$4$} (B)
(B) edge node[label] {$1$} (D)
(D) edge node[label] {$2$} (T)
;
% Flow
\draw[path]
(S)
-- node[above left, flow] {$(2)$} (A)
-- node[above, flow] {$(2)$} (C)
-- node[above right, flow] {$(2)$} (T)
;
\end{tikzpicture}
\end{center}
\end{minipage}
\hfill
\begin{minipage}[t]{0.48\textwidth}
\begin{center}
\begin{tikzpicture}[node distance = 20mm]
% Nodes
\begin{scope}[layer = nodes]
\node[main] (S) {$S$};
\node[main] (A) [above right of = S] {$A$};
\node[main] (B) [below right of = S] {$B$};
\node[main] (C) [right of = A] {$C$};
\node[main] (D) [right of = B] {$D$};
\node[main] (T) [above right of = D] {$T$};
\end{scope}
% Edges
\draw[->]
(S) edge node[label] {$5$} (A)
(A) edge node[label] {$3$} (C)
(C) edge node[label] {$2$} (T)
(A) edge node[label] {$4$} (D)
(S) edge node[label] {$4$} (B)
(B) edge node[label] {$1$} (D)
(D) edge node[label] {$2$} (T)
;
% Flow
\draw[path]
(S)
-- node[above left, flow] {$(2)$} (A)
-- node[above right, flow] {$(2)$} (D)
-- node[below right, flow] {$(2)$} (T)
;
\end{tikzpicture}
\end{center}
\end{minipage}
\vfill
\pagebreak