363 lines
9.2 KiB
TeX
Executable File
363 lines
9.2 KiB
TeX
Executable File
\documentclass[../main.tex]{subfiles}
|
|
|
|
|
|
\begin{document}
|
|
|
|
\section{Network Flow}
|
|
|
|
\generic{Networks}
|
|
Say have a network: a sequence of pipes, a set of cities and highways, an electrical circuit, server infrastructure, etc.
|
|
|
|
\vspace{1ex}
|
|
|
|
We'll represent our network with a connected directed weighted graph. If we take a city, edges will be highways and cities will be nodes. There are a few conditions for a valid network graph:
|
|
|
|
\begin{itemize}
|
|
\item The weight of each edge represents its capacity, the number of lanes in the highway.
|
|
\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.
|
|
\item All other nodes \textit{conserve} flow. In other words, the sum of flow coming in must equal the sum of flow going out.
|
|
\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.}
|
|
|
|
Here is an example of a such a graph:
|
|
\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}
|
|
In our city example, cars represent \textit{flow}. Let's send one unit of cars along the topmost highway:
|
|
|
|
\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:
|
|
\begin{itemize}
|
|
\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$.
|
|
\end{itemize}
|
|
\end{minipage}
|
|
|
|
\vspace{1ex}
|
|
|
|
The \textit{magnitude} of a flow\footnotemark{} is the number of \say{flow-units} that go from $S$ to $T$. \\
|
|
|
|
We are interested in the \textit{maximum flow} through this network: what is the greatest amount of flow we can push from $S$ to $T$?
|
|
|
|
\footnotetext{you could also think of \say{flow} as a directed weighted graph on top of our network.}
|
|
|
|
\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}
|
|
It is fairly easy to combine two flows on a graph. All we need to do is add the flows along each edge. For example, consider the following flows:
|
|
|
|
\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:
|
|
\vspace{2ex}
|
|
|
|
\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.
|
|
|
|
\vspace{1ex}
|
|
|
|
For example, we could not add these graphs if the magnitude of flow in the right graph above was 2.
|
|
|
|
\vspace{1ex}
|
|
|
|
This is because the capacity of the top-right edge is 2, and $2 + 1 > 2$.
|
|
\end{minipage}
|
|
|
|
\vspace{2ex}
|
|
\hrule
|
|
\vspace{2ex}
|
|
|
|
\problem{}
|
|
Combine the following flows and ensure that the flow along all edges remains within capacity.
|
|
|
|
\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
|
|
|
|
\end{document} |