Added "applications" section
This commit is contained in:
		@@ -6,59 +6,8 @@
 | 
				
			|||||||
	solutions
 | 
						solutions
 | 
				
			||||||
]{ormc_handout}
 | 
					]{ormc_handout}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\usepackage{subfiles}
 | 
					 | 
				
			||||||
\usetikzlibrary{arrows.meta}
 | 
					 | 
				
			||||||
\usetikzlibrary{shapes.geometric}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
% We put nodes in a separate layer, so we can
 | 
					\input{tikxset}
 | 
				
			||||||
% slightly overlap with paths for a perfect fit
 | 
					 | 
				
			||||||
\pgfdeclarelayer{nodes}
 | 
					 | 
				
			||||||
\pgfdeclarelayer{path}
 | 
					 | 
				
			||||||
\pgfsetlayers{main,nodes}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
% Layer settings
 | 
					 | 
				
			||||||
\tikzset{
 | 
					 | 
				
			||||||
	% Layer hack, lets us write
 | 
					 | 
				
			||||||
	% later = * in scopes.
 | 
					 | 
				
			||||||
	layer/.style = {
 | 
					 | 
				
			||||||
		execute at begin scope={\pgfonlayer{#1}},
 | 
					 | 
				
			||||||
		execute at end scope={\endpgfonlayer}
 | 
					 | 
				
			||||||
	},
 | 
					 | 
				
			||||||
	%
 | 
					 | 
				
			||||||
	% Arrowhead tweaks
 | 
					 | 
				
			||||||
	>={Latex[ width=2mm, length=2mm ]},
 | 
					 | 
				
			||||||
	label/.style = {
 | 
					 | 
				
			||||||
		circle,
 | 
					 | 
				
			||||||
		% For automatic red background in solutions
 | 
					 | 
				
			||||||
		fill = \ORMCbgcolor,
 | 
					 | 
				
			||||||
		draw = none
 | 
					 | 
				
			||||||
	},
 | 
					 | 
				
			||||||
	%
 | 
					 | 
				
			||||||
	% Nodes
 | 
					 | 
				
			||||||
	main/.style = {
 | 
					 | 
				
			||||||
		draw,
 | 
					 | 
				
			||||||
		circle,
 | 
					 | 
				
			||||||
		fill = white
 | 
					 | 
				
			||||||
	},
 | 
					 | 
				
			||||||
	%
 | 
					 | 
				
			||||||
	% Flow annotations
 | 
					 | 
				
			||||||
	flow/.style = {
 | 
					 | 
				
			||||||
		opacity = 1,
 | 
					 | 
				
			||||||
		thin,
 | 
					 | 
				
			||||||
		inner xsep = 2.5mm,
 | 
					 | 
				
			||||||
		inner ysep = 2.5mm
 | 
					 | 
				
			||||||
	},
 | 
					 | 
				
			||||||
	%
 | 
					 | 
				
			||||||
	% Paths
 | 
					 | 
				
			||||||
	path/.style = {
 | 
					 | 
				
			||||||
		line width = 4mm,
 | 
					 | 
				
			||||||
		draw = black,
 | 
					 | 
				
			||||||
		% Lengthen paths so they're
 | 
					 | 
				
			||||||
		% completely under nodes.
 | 
					 | 
				
			||||||
		line cap = rect,
 | 
					 | 
				
			||||||
		opacity = 0.3
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{document}
 | 
					\begin{document}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -69,109 +18,14 @@
 | 
				
			|||||||
		{Prepared by Mark on \today}
 | 
							{Prepared by Mark on \today}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	\subfile{parts/00 review}
 | 
						\input{parts/00 review}
 | 
				
			||||||
	\subfile{parts/01 flow}
 | 
						\input{parts/01 flow}
 | 
				
			||||||
	\subfile{parts/02 residual}
 | 
						\input{parts/02 residual}
 | 
				
			||||||
	\subfile{parts/03 fulkerson}
 | 
						\input{parts/03 fulkerson}
 | 
				
			||||||
 | 
						\input{parts/04 applications}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	\problem{Maximum Cardinality Matching}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	A \textit{matching} is a subset of edges in a bipartite graph. Nodes in a matching must not have more than one edge connected to them. \\
 | 
					 | 
				
			||||||
	A matching is \textit{maximal} if it has more edges than any other matching.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	\vspace{5mm}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	\begin{minipage}[t]{0.48\textwidth}
 | 
					 | 
				
			||||||
	\begin{center}
 | 
					 | 
				
			||||||
		Initial Graph \\
 | 
					 | 
				
			||||||
		\vspace{2mm}
 | 
					 | 
				
			||||||
		\begin{tikzpicture}
 | 
					 | 
				
			||||||
			% Nodes
 | 
					 | 
				
			||||||
			\begin{scope}[layer = nodes]
 | 
					 | 
				
			||||||
				\node[main] (A1) at (0mm, 24mm) {};
 | 
					 | 
				
			||||||
				\node[main] (A2) at (0mm, 18mm) {};
 | 
					 | 
				
			||||||
				\node[main] (A3) at (0mm, 12mm) {};
 | 
					 | 
				
			||||||
				\node[main] (A4) at (0mm, 6mm) {};
 | 
					 | 
				
			||||||
				\node[main] (A5) at (0mm, 0mm) {};
 | 
					 | 
				
			||||||
				\node[main] (B1) at (20mm, 24mm) {};
 | 
					 | 
				
			||||||
				\node[main] (B2) at (20mm, 18mm) {};
 | 
					 | 
				
			||||||
				\node[main] (B3) at (20mm, 12mm) {};
 | 
					 | 
				
			||||||
				\node[main] (B4) at (20mm, 6mm) {};
 | 
					 | 
				
			||||||
				\node[main] (B5) at (20mm, 0mm) {};
 | 
					 | 
				
			||||||
			\end{scope}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			% Edges
 | 
					 | 
				
			||||||
			\draw
 | 
					 | 
				
			||||||
				(A1) edge (B2)
 | 
					 | 
				
			||||||
				(A1) edge (B3)
 | 
					 | 
				
			||||||
				(A2) edge (B1)
 | 
					 | 
				
			||||||
				(A2) edge (B4)
 | 
					 | 
				
			||||||
				(A4) edge (B3)
 | 
					 | 
				
			||||||
				(A2) edge (B3)
 | 
					 | 
				
			||||||
				(A5) edge (B3)
 | 
					 | 
				
			||||||
				(A5) edge (B4)
 | 
					 | 
				
			||||||
			;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		\end{tikzpicture}
 | 
					 | 
				
			||||||
	\end{center}
 | 
					 | 
				
			||||||
	\end{minipage}
 | 
					 | 
				
			||||||
	\hfill
 | 
					 | 
				
			||||||
	\begin{minipage}[t]{0.48\textwidth}
 | 
					 | 
				
			||||||
	\begin{center}
 | 
					 | 
				
			||||||
		Maximal Matching \\
 | 
					 | 
				
			||||||
		\vspace{2mm}
 | 
					 | 
				
			||||||
		\begin{tikzpicture}
 | 
					 | 
				
			||||||
			% Nodes
 | 
					 | 
				
			||||||
			\begin{scope}[layer = nodes]
 | 
					 | 
				
			||||||
				\node[main] (A1) at (0mm, 24mm) {};
 | 
					 | 
				
			||||||
				\node[main] (A2) at (0mm, 18mm) {};
 | 
					 | 
				
			||||||
				\node[main] (A3) at (0mm, 12mm) {};
 | 
					 | 
				
			||||||
				\node[main] (A4) at (0mm, 6mm) {};
 | 
					 | 
				
			||||||
				\node[main] (A5) at (0mm, 0mm) {};
 | 
					 | 
				
			||||||
				\node[main] (B1) at (20mm, 24mm) {};
 | 
					 | 
				
			||||||
				\node[main] (B2) at (20mm, 18mm) {};
 | 
					 | 
				
			||||||
				\node[main] (B3) at (20mm, 12mm) {};
 | 
					 | 
				
			||||||
				\node[main] (B4) at (20mm, 6mm) {};
 | 
					 | 
				
			||||||
				\node[main] (B5) at (20mm, 0mm) {};
 | 
					 | 
				
			||||||
			\end{scope}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			% Edges
 | 
					 | 
				
			||||||
			\draw[opacity = 0.4]
 | 
					 | 
				
			||||||
				(A1) edge (B2)
 | 
					 | 
				
			||||||
				(A1) edge (B3)
 | 
					 | 
				
			||||||
				(A2) edge (B1)
 | 
					 | 
				
			||||||
				(A2) edge (B4)
 | 
					 | 
				
			||||||
				(A4) edge (B3)
 | 
					 | 
				
			||||||
				(A4) edge (B3)
 | 
					 | 
				
			||||||
				(A5) edge (B3)
 | 
					 | 
				
			||||||
				(A5) edge (B4)
 | 
					 | 
				
			||||||
			;
 | 
					 | 
				
			||||||
			\draw
 | 
					 | 
				
			||||||
				(A1) edge (B2)
 | 
					 | 
				
			||||||
				(A2) edge (B1)
 | 
					 | 
				
			||||||
				(A4) edge (B3)
 | 
					 | 
				
			||||||
				(A5) edge (B4)
 | 
					 | 
				
			||||||
			;
 | 
					 | 
				
			||||||
		\end{tikzpicture}
 | 
					 | 
				
			||||||
	\end{center}
 | 
					 | 
				
			||||||
	\end{minipage}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	\vspace{5mm}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Devise an algorithm to find a maximal matching in any bipartite graph. \\
 | 
					 | 
				
			||||||
	Find an upper bound for its runtime.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	\begin{solution}
 | 
					 | 
				
			||||||
		Turn this into a maximum flow problem and use FF. \\
 | 
					 | 
				
			||||||
		Connect a node $S$ to all nodes in the left group and a node $T$ to all nodes in the right group. All edges have capacity 1.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		\vspace{2ex}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		Just like FF, this algorithm will take at most $\min(\# \text{ left nodes}, \# \text{ right nodes})$ iterations.
 | 
					 | 
				
			||||||
	\end{solution}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\end{document}
 | 
					\end{document}
 | 
				
			||||||
@@ -1,8 +1,3 @@
 | 
				
			|||||||
\documentclass[../main.tex]{subfiles}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\begin{document}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\section{Review}
 | 
					\section{Review}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\definition{}
 | 
					\definition{}
 | 
				
			||||||
@@ -87,5 +82,3 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
\vfill
 | 
					\vfill
 | 
				
			||||||
\pagebreak
 | 
					\pagebreak
 | 
				
			||||||
 | 
					 | 
				
			||||||
\end{document}
 | 
					 | 
				
			||||||
@@ -1,8 +1,3 @@
 | 
				
			|||||||
\documentclass[../main.tex]{subfiles}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\begin{document}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\section{Network Flow}
 | 
					\section{Network Flow}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\generic{Networks}
 | 
					\generic{Networks}
 | 
				
			||||||
@@ -359,5 +354,3 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
\vfill
 | 
					\vfill
 | 
				
			||||||
\pagebreak
 | 
					\pagebreak
 | 
				
			||||||
 | 
					 | 
				
			||||||
\end{document}
 | 
					 | 
				
			||||||
@@ -1,8 +1,3 @@
 | 
				
			|||||||
\documentclass[../main.tex]{subfiles}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\begin{document}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\section{Residual Graphs}
 | 
					\section{Residual Graphs}
 | 
				
			||||||
As our network gets bigger, finding a maximum flow by hand becomes much more difficult. It will be convenient to have an algorithm that finds a maximal flow in any network.
 | 
					As our network gets bigger, finding a maximum flow by hand becomes much more difficult. It will be convenient to have an algorithm that finds a maximal flow in any network.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -214,6 +209,4 @@
 | 
				
			|||||||
\footnotetext{Integral = \say{integer} as an adjective.}
 | 
					\footnotetext{Integral = \say{integer} as an adjective.}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\vfill
 | 
					\vfill
 | 
				
			||||||
 | 
					\pagebreak
 | 
				
			||||||
 | 
					 | 
				
			||||||
\end{document}
 | 
					 | 
				
			||||||
@@ -1,7 +1,3 @@
 | 
				
			|||||||
\documentclass[../main.tex]{subfiles}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\begin{document}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
\section{The Ford-Fulkerson Algorithm}
 | 
					\section{The Ford-Fulkerson Algorithm}
 | 
				
			||||||
We now have all the tools we need to construct an algorithm that finds a maximal flow. \\
 | 
					We now have all the tools we need to construct an algorithm that finds a maximal flow. \\
 | 
				
			||||||
@@ -125,4 +121,3 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
\vfill
 | 
					\vfill
 | 
				
			||||||
\pagebreak
 | 
					\pagebreak
 | 
				
			||||||
\end{document}
 | 
					 | 
				
			||||||
							
								
								
									
										187
									
								
								Advanced/Graph Algorithms/parts/04 applications.tex
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										187
									
								
								Advanced/Graph Algorithms/parts/04 applications.tex
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,187 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					\section{Applications}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\problem{Maximum Cardinality Matching}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					A \textit{matching} is a subset of edges in a bipartite graph. Nodes in a matching must not have more than one edge connected to them. \\
 | 
				
			||||||
 | 
					A matching is \textit{maximal} if it has more edges than any other matching.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\vspace{5mm}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\begin{minipage}[t]{0.48\textwidth}
 | 
				
			||||||
 | 
					\begin{center}
 | 
				
			||||||
 | 
						Initial Graph \\
 | 
				
			||||||
 | 
						\vspace{2mm}
 | 
				
			||||||
 | 
						\begin{tikzpicture}
 | 
				
			||||||
 | 
							% Nodes
 | 
				
			||||||
 | 
							\begin{scope}[layer = nodes]
 | 
				
			||||||
 | 
								\node[main] (A1) at (0mm, 24mm) {};
 | 
				
			||||||
 | 
								\node[main] (A2) at (0mm, 18mm) {};
 | 
				
			||||||
 | 
								\node[main] (A3) at (0mm, 12mm) {};
 | 
				
			||||||
 | 
								\node[main] (A4) at (0mm, 6mm) {};
 | 
				
			||||||
 | 
								\node[main] (A5) at (0mm, 0mm) {};
 | 
				
			||||||
 | 
								\node[main] (B1) at (20mm, 24mm) {};
 | 
				
			||||||
 | 
								\node[main] (B2) at (20mm, 18mm) {};
 | 
				
			||||||
 | 
								\node[main] (B3) at (20mm, 12mm) {};
 | 
				
			||||||
 | 
								\node[main] (B4) at (20mm, 6mm) {};
 | 
				
			||||||
 | 
								\node[main] (B5) at (20mm, 0mm) {};
 | 
				
			||||||
 | 
							\end{scope}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							% Edges
 | 
				
			||||||
 | 
							\draw
 | 
				
			||||||
 | 
								(A1) edge (B2)
 | 
				
			||||||
 | 
								(A1) edge (B3)
 | 
				
			||||||
 | 
								(A2) edge (B1)
 | 
				
			||||||
 | 
								(A2) edge (B4)
 | 
				
			||||||
 | 
								(A4) edge (B3)
 | 
				
			||||||
 | 
								(A2) edge (B3)
 | 
				
			||||||
 | 
								(A5) edge (B3)
 | 
				
			||||||
 | 
								(A5) edge (B4)
 | 
				
			||||||
 | 
							;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						\end{tikzpicture}
 | 
				
			||||||
 | 
					\end{center}
 | 
				
			||||||
 | 
					\end{minipage}
 | 
				
			||||||
 | 
					\hfill
 | 
				
			||||||
 | 
					\begin{minipage}[t]{0.48\textwidth}
 | 
				
			||||||
 | 
					\begin{center}
 | 
				
			||||||
 | 
						Maximal Matching \\
 | 
				
			||||||
 | 
						\vspace{2mm}
 | 
				
			||||||
 | 
						\begin{tikzpicture}
 | 
				
			||||||
 | 
							% Nodes
 | 
				
			||||||
 | 
							\begin{scope}[layer = nodes]
 | 
				
			||||||
 | 
								\node[main] (A1) at (0mm, 24mm) {};
 | 
				
			||||||
 | 
								\node[main] (A2) at (0mm, 18mm) {};
 | 
				
			||||||
 | 
								\node[main] (A3) at (0mm, 12mm) {};
 | 
				
			||||||
 | 
								\node[main] (A4) at (0mm, 6mm) {};
 | 
				
			||||||
 | 
								\node[main] (A5) at (0mm, 0mm) {};
 | 
				
			||||||
 | 
								\node[main] (B1) at (20mm, 24mm) {};
 | 
				
			||||||
 | 
								\node[main] (B2) at (20mm, 18mm) {};
 | 
				
			||||||
 | 
								\node[main] (B3) at (20mm, 12mm) {};
 | 
				
			||||||
 | 
								\node[main] (B4) at (20mm, 6mm) {};
 | 
				
			||||||
 | 
								\node[main] (B5) at (20mm, 0mm) {};
 | 
				
			||||||
 | 
							\end{scope}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							% Edges
 | 
				
			||||||
 | 
							\draw[opacity = 0.4]
 | 
				
			||||||
 | 
								(A1) edge (B2)
 | 
				
			||||||
 | 
								(A1) edge (B3)
 | 
				
			||||||
 | 
								(A2) edge (B1)
 | 
				
			||||||
 | 
								(A2) edge (B4)
 | 
				
			||||||
 | 
								(A4) edge (B3)
 | 
				
			||||||
 | 
								(A4) edge (B3)
 | 
				
			||||||
 | 
								(A5) edge (B3)
 | 
				
			||||||
 | 
								(A5) edge (B4)
 | 
				
			||||||
 | 
							;
 | 
				
			||||||
 | 
							\draw
 | 
				
			||||||
 | 
								(A1) edge (B2)
 | 
				
			||||||
 | 
								(A2) edge (B1)
 | 
				
			||||||
 | 
								(A4) edge (B3)
 | 
				
			||||||
 | 
								(A5) edge (B4)
 | 
				
			||||||
 | 
							;
 | 
				
			||||||
 | 
						\end{tikzpicture}
 | 
				
			||||||
 | 
					\end{center}
 | 
				
			||||||
 | 
					\end{minipage}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\vspace{5mm}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Devise an algorithm to find a maximal matching in any bipartite graph. \\
 | 
				
			||||||
 | 
					Find an upper bound for its runtime.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\begin{solution}
 | 
				
			||||||
 | 
						Turn this into a maximum flow problem and use FF. \\
 | 
				
			||||||
 | 
						Connect a node $S$ to all nodes in the left group and a node $T$ to all nodes in the right group. All edges have capacity 1.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						\vspace{2ex}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Just like FF, this algorithm will take at most $\min(\# \text{ left nodes}, \# \text{ right nodes})$ iterations.
 | 
				
			||||||
 | 
					\end{solution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\vfill
 | 
				
			||||||
 | 
					\pagebreak
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\problem{Circulations with Demand}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Say we have a network of cities and power stations. Stations produce power; cities consume it.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Each station produces a limited amount of power, and each city has limited demand.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\vspace{2ex}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					We can represent this power grid as a graph, with cities and stations as nodes and transmission lines as edges.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\vspace{2ex}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					A simple example is below. There are two cities ($2$ and $4$) and two stations (both $-3$).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					We'll represent station capacity with a negative number, since they \textit{consume} a negative amount of energy.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\begin{center}
 | 
				
			||||||
 | 
						\begin{tikzpicture}[
 | 
				
			||||||
 | 
							node distance = 25mm,
 | 
				
			||||||
 | 
							main/.style = {
 | 
				
			||||||
 | 
								draw,
 | 
				
			||||||
 | 
								circle,
 | 
				
			||||||
 | 
								fill = white,
 | 
				
			||||||
 | 
								minimum size = 8mm
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
 | 
							% Nodes
 | 
				
			||||||
 | 
							\begin{scope}[layer = nodes]
 | 
				
			||||||
 | 
								\node[main] (S1) {$-3$};
 | 
				
			||||||
 | 
								\node[main] (S2) [below left of = S1] {$-3$};
 | 
				
			||||||
 | 
								\node[main] (C1) [below right of = S1] {$2$};
 | 
				
			||||||
 | 
								\node[main] (C2) [below right of = S2] {$4$};
 | 
				
			||||||
 | 
							\end{scope}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							% Edges
 | 
				
			||||||
 | 
							\draw[->]
 | 
				
			||||||
 | 
								(S1) edge node[label] {$3$} (S2)
 | 
				
			||||||
 | 
								(S1) edge node[label] {$3$} (C1)
 | 
				
			||||||
 | 
								(S2) edge node[label] {$2$} (C1)
 | 
				
			||||||
 | 
								(S2) edge node[label] {$2$} (C2)
 | 
				
			||||||
 | 
								(C1) edge node[label] {$2$} (C2)
 | 
				
			||||||
 | 
							;
 | 
				
			||||||
 | 
						\end{tikzpicture}
 | 
				
			||||||
 | 
					\end{center}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					We'd like to know if there exists a \textit{feasible circulation} in this network---that is, can we supply our cities with the energy they need without exceeding the capacity of power plants or transmission lines?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\vspace{2ex}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\textbf{Your job:} Devise an algorithm that solve this problem.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\vspace{2ex}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\note{\textbf{Bonus:} Say certain edges have a lower bound on their capacity, meaning that we must send \textit{at least} that much flow down the edge. Modify your algorithm to account for these additional constraints.}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\begin{solution}
 | 
				
			||||||
 | 
						Create a source node $S$, and connect it to each station with an edge. Set the capacity of that edge to the capacity of the station. \\
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Create a sink node $T$ and do the same for cities.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						\vspace{2ex}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						This is now a maximum-flow problem with one source and one sink. Apply FF.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						\linehack{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						To solve the bonus problem, we'll modify the network before running the algorithm above.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						\vspace{2ex}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Say an edge from $A$ to $B$ has minimum capacity $l$ and maximum capacity $u \geq l$. Apply the following transformations:
 | 
				
			||||||
 | 
						\begin{itemize}
 | 
				
			||||||
 | 
							\item Add $l$ to the capacity of $A$
 | 
				
			||||||
 | 
							\item Subtract $l$ from the capacity of $B$
 | 
				
			||||||
 | 
							\item Subtract $l$ from the total capacity of the edge.
 | 
				
			||||||
 | 
						\end{itemize}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Do this for every edge that has a lower bound then apply the algorithm above.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\end{solution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\vfill
 | 
				
			||||||
 | 
					\pagebreak
 | 
				
			||||||
							
								
								
									
										52
									
								
								Advanced/Graph Algorithms/tikxset.tex
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								Advanced/Graph Algorithms/tikxset.tex
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,52 @@
 | 
				
			|||||||
 | 
					\usetikzlibrary{arrows.meta}
 | 
				
			||||||
 | 
					\usetikzlibrary{shapes.geometric}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					% We put nodes in a separate layer, so we can
 | 
				
			||||||
 | 
					% slightly overlap with paths for a perfect fit
 | 
				
			||||||
 | 
					\pgfdeclarelayer{nodes}
 | 
				
			||||||
 | 
					\pgfdeclarelayer{path}
 | 
				
			||||||
 | 
					\pgfsetlayers{main,nodes}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					% Layer settings
 | 
				
			||||||
 | 
					\tikzset{
 | 
				
			||||||
 | 
						% Layer hack, lets us write
 | 
				
			||||||
 | 
						% later = * in scopes.
 | 
				
			||||||
 | 
						layer/.style = {
 | 
				
			||||||
 | 
							execute at begin scope={\pgfonlayer{#1}},
 | 
				
			||||||
 | 
							execute at end scope={\endpgfonlayer}
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						%
 | 
				
			||||||
 | 
						% Arrowhead tweaks
 | 
				
			||||||
 | 
						>={Latex[ width=2mm, length=2mm ]},
 | 
				
			||||||
 | 
						label/.style = {
 | 
				
			||||||
 | 
							circle,
 | 
				
			||||||
 | 
							% For automatic red background in solutions
 | 
				
			||||||
 | 
							fill = \ORMCbgcolor,
 | 
				
			||||||
 | 
							draw = none
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						%
 | 
				
			||||||
 | 
						% Nodes
 | 
				
			||||||
 | 
						main/.style = {
 | 
				
			||||||
 | 
							draw,
 | 
				
			||||||
 | 
							circle,
 | 
				
			||||||
 | 
							fill = white
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						%
 | 
				
			||||||
 | 
						% Flow annotations
 | 
				
			||||||
 | 
						flow/.style = {
 | 
				
			||||||
 | 
							opacity = 1,
 | 
				
			||||||
 | 
							thin,
 | 
				
			||||||
 | 
							inner xsep = 2.5mm,
 | 
				
			||||||
 | 
							inner ysep = 2.5mm
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						%
 | 
				
			||||||
 | 
						% Paths
 | 
				
			||||||
 | 
						path/.style = {
 | 
				
			||||||
 | 
							line width = 4mm,
 | 
				
			||||||
 | 
							draw = black,
 | 
				
			||||||
 | 
							% Lengthen paths so they're
 | 
				
			||||||
 | 
							% completely under nodes.
 | 
				
			||||||
 | 
							line cap = rect,
 | 
				
			||||||
 | 
							opacity = 0.3
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user