\section{Residual Graphs}
It is hard to find a maximum flow for a large network by hand. \\
We need to create an algorithm to accomplish this task.

\vspace{1ex}

The first thing we'll need is the notion of a \textit{residual graph}.

\vspace{2ex}
\hrule

\begin{center}
	\begin{minipage}[t]{0.48\textwidth}
	We'll start with the following network and flow:
	\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] (T) [above right of = B] {$T$};
			\end{scope}

			% Edges
			\draw[->]
				(S) edge node[label] {$1$} (A)
				(A) edge node[label] {$3$} (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}
	First, we'll copy all nodes and \say{unused} edges:
	\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] (T) [above right of = B] {$T$};
			\end{scope}

			% Edges
			\draw[->]
				(B) edge node[label] {$2$} (A)
				(S) edge node[label] {$2$} (B)
				(B) edge node[label] {$1$} (T)
			;
		\end{tikzpicture}
	\end{center}
	\end{minipage}
\end{center}

\hrule

\begin{center}
	\begin{minipage}[t]{0.48\textwidth}
	Then, we'll add the unused capacity of \say{used} edges: (Note that $3 - 1 = 2$)
	\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] (T) [above right of = B] {$T$};
			\end{scope}

			% Edges
			\draw[->]
				(A) edge node[label] {$2$} (T)
				(B) edge node[label] {$2$} (A)
				(S) edge node[label] {$2$} (B)
				(B) edge node[label] {$1$} (T)
			;
		\end{tikzpicture}
	\end{center}
	\end{minipage}
	\hfill
	\begin{minipage}[t]{0.48\textwidth}
	Finally, we'll add \say{used} capacity as edges in the opposite direction:
	\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] (T) [above right of = B] {$T$};
			\end{scope}

			% Edges
			\draw[->]
				(A) edge node[label] {$1$} (S)
				(T) edge [bend right] node[label] {$1$} (A)
				(A) edge [bend right] node[label] {$2$} (T)
				(B) edge node[label] {$2$} (A)
				(S) edge node[label] {$2$} (B)
				(B) edge node[label] {$1$} (T)
			;
		\end{tikzpicture}
	\end{center}
	This graph is the residual of the original flow.
\end{minipage}
\end{center}

\hrule
\vspace{3ex}

You can think of the residual graph as a \say{list of possible changes} to the original flow. \\
There are two ways we can change a flow:
\begin{itemize}
	\item We can add flow along a path
	\item We can remove flow along another path
\end{itemize}

\vspace{1ex}

A residual graph captures both of these actions, showing us where we can add flow (forward edges) and where we can remove it (reverse edges). Note that \say{removing} flow along an edge is equivalent to adding flow in the opposite direction.


\vfill
\pagebreak

\problem{}<FindResidual>
Construct the residual of this flow.

\begin{center}
	\begin{tikzpicture}[node distance = 25mm]
		% 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] (T) [above right of = B] {$T$};
		\end{scope}

		% Edges
		\draw[->]
			(S) edge node[label] {$2$} (A)
			(A) edge node[label] {$1$} (T)
			(A) edge node[label] {$3$} (B)
			(S) edge node[label] {$1$} (B)
			(B) edge node[label] {$2$} (T)
		;

		% Flow
		\draw[path]
			(S)
			-- node[above left, flow] {$(2)$} (A)
			-- node[left, flow] {$(2)$} (B)
			-- node[below right, flow] {$(2)$} (T)
		;
	\end{tikzpicture}
\end{center}

\begin{solution}
	\begin{center}
		\begin{tikzpicture}[node distance = 25mm]
			% 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] (T) [above right of = B] {$T$};
			\end{scope}

			% Edges
			\draw[->]
				(A) edge node[label] {$2$} (S)
				(A) edge node[label] {$1$} (T)
				(A) edge[out=295,in=65] node[label] {$1$} (B)
				(B) edge[out=115,in=245] node[label] {$2$} (A)
				(S) edge node[label] {$1$} (B)
				(T) edge node[label] {$2$} (B)
			;
		\end{tikzpicture}
	\end{center}
\end{solution}

\vfill
\problem{}
Is the flow in \ref{FindResidual} maximal? \\
If it isn't, find a maximal flow. \\
\hint{Look at the residual graph. Can we add flow along another path?}

\vfill
\pagebreak

\problem{}
Show that...
\begin{enumerate}
	\item A maximal flow exists in every network with integral edge weights.
	\item Every edge in this flow carries an integral amount of flow
\end{enumerate}

\vfill
\pagebreak