From: Bjørn Rustad Date: Tue, 15 Apr 2014 12:26:42 +0000 (+0200) Subject: EASTER HOLIDAY X-Git-Url: http://git.rustad.me/?a=commitdiff_plain;h=699fb39b19d39641a945142973bc9a35872d67f6;p=prosjektoppgave EASTER HOLIDAY --- diff --git a/cut.tex b/cut.tex index 4693c1e..7496831 100644 --- a/cut.tex +++ b/cut.tex @@ -39,6 +39,7 @@ separates the source from the sink. \end{equation} and a minimum $s$-$t$-cut is a cut whose capacity is minimum over all possible $s$-$t$-cuts in the network. + \label{def:s_t_cut} \end{definition} Note that there might exist many different minimum $s$-$t$-cuts in a network, resulting in different partitions of $V$. This is why we need diff --git a/flow.tex b/flow.tex index ce7c9b5..26c2674 100644 --- a/flow.tex +++ b/flow.tex @@ -17,8 +17,8 @@ sending through each edge of our network and must satisfy the following two constraints \begin{description} \item[Capacity constraint:] For all $u, v \in V, 0 \leq f(u, v) \leq c(u, - v)$, i.e., for every edge, the flow is less than or equal to the - capacity. + v)$, i.e., for every pair of vertices, the flow is less than or + equal to the capacity. \item[Flow conservation:] For all $u \in V - \{s, t\}$ \begin{equation} \sum_{v \in V} f(v, u) = \sum_{v \in V} f(u, v), @@ -30,55 +30,52 @@ Note that we have defined $f$ with all pairs of vertices as its domain, even though it is only non-zero on edges $(u, v) \in E$. This makes it easier to write sums like in the flow conservation constraint. -\fixme{No anti-parallel edges.} +We denote $\abs{f}$ as the net amount of flow from the source to the +sink in the network. Because of the flow conservation constraint, this +can be calculated as the net amount of flow going out of the source +\begin{equation} + \abs{f} = \sum_{v \in V} f(s, v) - \sum_{u \in V} f(u, s). + \label{eq:total_flow} +\end{equation} +Furthermore we denote the \emph{net flow} across an $s$-$t$-cut $C = (S, +T)$ as +\begin{equation} + f(S, T) = \sum_{u \in S} \sum_{v \in T} f(u, v) - \sum_{v \in T} + \sum_{u \in S} f(v, u). + \label{eq:net_flow_cut} +\end{equation} +Note how this definition is different from the capacity of a cut +$c(S,T)$ in Definition \ref{def:s_t_cut}. While the capacity of a cut +represents how much flow it is maximally possible to send from $S$ to +$T$, the net flow across a cut represents just that, the net amount of +flow across the cut, counting flow that goes back from $T$ to $S$. -\subsubsection{Residual network} -When further discussing the max-flow problem we will need the notion of -a residual network $G_f = (V_f, E_f, c_f)$, which is derived from the -original network $G$ and contains the edges along which it is possible -to send additional flow. This means that $E_f$ contains the edges $(u, -v)$ from $E$ where $f(u,v) < c(u,v)$. But that is not all, an important -realisation is that it is also possible to push flow \emph{back} along -an edge where the flow is already positive. In other words, sending flow -from $v$ to $u$ by cancelling some or all of the flow that is already -going from $u$ to $v$. +For any $s$-$t$-cut we have that +\begin{equation} + \abs{f} = f(S, T) + \label{eq:total_flow_eq_cut} +\end{equation} +This is trivial for the cut $S = \{s\}$, $T = V - S$. A proof that this +is true for the rest of the cuts can start at this trivial cut, and move +vertex by vertex from $T$ to $S$, maintaining the equality of +\eqref{eq:total_flow_eq_cut} at each step. -Thus the capacity function $c_f$ of our residual network becomes +Following from \eqref{eq:total_flow}, \eqref{eq:net_flow_cut} and +\eqref{eq:total_flow_eq_cut}, we can show that \begin{equation} - c_f(u, v) = - \begin{cases} - c(u, v) - f(u, v) & \text{if } (u, v) \in E, \\ - f(v, u) & \text{if } (v, u) \in E, \\ - 0 & \text{otherwise.} - \end{cases} + \abs{f} \leq c(S, T) + \label{eq:flow_leq_cut} \end{equation} -The vertices $V_f$ of $G_f$ are the same as the original network $G$, -while the edges $E_f$ are taken to be all pairs of vertices $(u, v)$ -with $c_f(u, v) > 0$. Since we can in $E_f$ at most have all the -original edges, and their reversals, we have $\abs{E_f} \leq \abs{E}$. - -\fixme{$\abs{f}$ needs to be defined somewhere?} - -What we seek in our graph, is a the minimal $s$-$t$-cut, a -«minimal» line through the graph that cuts a set of edges and separates -the source from the sink. -\begin{definition}[$s$-$t$-cut] - Given a network $G = (E, V, c)$, a cut $(S, T)$ of a network $G = - (V, E, c)$ is a partition of $V$ into $S$ and $T = V - S$ such that - $s \in S$ and $t \in T$. The capacity of the cut is - \begin{equation} - c(S, T) = \sum_{u \in S} \sum_{v \in S} c(u, v), - \end{equation} - and the minimum $s$-$t$-cut is the cut whose capacity is minimum - over all possible $s$-$t$-cuts in the network. -\end{definition} - -\fixme{COROLLARY 26.5 in Cormen.} -\fixme{Define $\abs{f}$.} - -When finding this minimum cut, we make use of an important duality -theorem in network flow theory, stating that the capacity of the minimum -$s$-$t$-cut in a network, is equal to the maximum flow from $s$ to $t$. +for any $s$-$t$-cut $C = (S, T)$. See \cite{cormen2009introduction} for +a full proof of this chain of arguments. + +\fixme{No anti-parallel edges.} +\fixme{More references to Cormen for proofs.} + +Recall that we want to find the minimum $s$-$t$ cut in our network. When +finding this minimum cut, we make use of an important duality theorem in +network flow theory, stating that the capacity of a minimum $s$-$t$-cut +in a network, is equal to the maximum flow from $s$ to $t$. \begin{theorem}[Max-flow min-cut theorem] If $f$ is a flow in a network $G = (V, E, c)$ with source $s$ and sink $t$, then the following is equivalent: @@ -86,24 +83,54 @@ $s$-$t$-cut in a network, is equal to the maximum flow from $s$ to $t$. \item $f$ is a maximum flow in $G$. \item The residual network $G_f$ contains no augmenting paths. \item $\abs{f} = c(S, T)$ for some cut $(S, T)$ of $G$. + \label{it:max_flow_min_cut} \end{enumerate} \end{theorem} -See \cite{cormen2009introduction} for a proof. Note that for any -$s$-$t$-cut $C = (S, T)$ in a graph $G$ with flow $\abs{f}$ from source -to sink, the \emph{flow} across the cut is always equal to $\abs{f}$, -while the \emph{capacity} of the cut will depend on the cut, and will -only be equal to $\abs{f}$ for one of the minimal $s$-$t$-cuts in $G$. +See \cite{cormen2009introduction} for a proof, and remark that because +of the inequality in \eqref{eq:flow_leq_cut}, the cut in statement +\ref{it:max_flow_min_cut} is a minimum cut. + +But how does this help us? We know that if we know the maximum flow +value, and we have an $s$-$t$-cut with capacity equal to the maximum +flow, we actually have a minimum cut. The question is then, how do we +find the maximum flow, and how do we find a minimum cut. \fixme{But how do we find THE minimum cut? Which one do we want? The maximum one? The minimum one? EEEEK} \subsection{Augmenting flow algorithms} The family of augmenting flow algorithms represent a popular approach to -the max flow problem. The idea is simply to look for paths from the +the maximum flow problem. The idea is simply to look for paths from the source to the sink in the graph, along which is is possible to send more flow, and then send the maximum amount of flow along this path. When no such path exists anymore, no more flow can be sent through the graph, and maximum flow has been reached. + +\subsubsection{Residual network} +When further discussing approaches to solving the max-flow problem we +will need the notion of a residual network $G_f = (V_f, E_f, c_f)$, +which is derived from the original network $G$ and contains the edges +along which it is possible to send additional flow. This means that +$E_f$ contains the edges $(u, v)$ from $E$ where $f(u,v) < c(u,v)$. But +that is not all, an important realisation is that it is also possible to +push flow \emph{back} along an edge where the flow is already positive. +In other words, sending flow from $v$ to $u$ by cancelling some or all +of the flow that is already going from $u$ to $v$. + +Thus the capacity function $c_f$ of our residual network becomes +\begin{equation} + c_f(u, v) = + \begin{cases} + c(u, v) - f(u, v) & \text{if } (u, v) \in E, \\ + f(v, u) & \text{if } (v, u) \in E, \\ + 0 & \text{otherwise.} + \end{cases} +\end{equation} +The vertices $V_f$ of $G_f$ are the same as the original network $G$, +while the edges $E_f$ are taken to be all pairs of vertices $(u, v)$ +with $c_f(u, v) > 0$. Since we can in $E_f$ at most have all the +original edges, and their reversals, we have $\abs{E_f} \leq 2 \abs{E}$. + \begin{figure} \centering \begin{tikzpicture}[scale=1.5] @@ -121,16 +148,21 @@ and maximum flow has been reached. \path[edge] (u) -- node[weight] {0/5} (t); \path[edge] (v) -- node[weight] {5/5} (t); \end{tikzpicture} - \caption{A network with the flow and capacity shown as flow/capacity. - The marked path is a valid augmenting path from $s$ to $t$, and by - increasing the flow along it, we will push flow back from $v$ to - $u$. \fixme{refer to this figure somewhere?}} + \caption{A network with the flow and capacity of each edge shown as + flow/capacity. The marked path is a valid augmenting path from + $s$ to $t$, and by increasing the flow along it, we will push + flow back from $v$ to $u$. \fixme{refer to this figure + somewhere!} + } \label{fig:aug_flow} \end{figure} \subsubsection{Ford-Fulkerson} The Ford-Fulkerson algorithm is the most basic augmenting flow -algorithm, which can be extended to more advanced algorithms. +algorithm, which can be extended to more advanced algorithms. It is +stated in pseudocode in Algorithm \ref{alg:ford_fulkerson}, and the idea +is to augment the flow along paths from $s$ to $t$ until it is no longer +possible. \begin{algorithm} \begin{algorithmic} \Function{Ford-Fulkerson}{$G$, $s$, $t$} @@ -145,76 +177,73 @@ algorithm, which can be extended to more advanced algorithms. \EndFunction \end{algorithmic} \caption{\sf The Ford-Fulkerson max-flow algorithm} +\label{alg:ford_fulkerson} \end{algorithm} + Of course, a choice has to be made on how to search for a path in the residual network. A common choice is to do a breadth-first search from the source node until the sink node is found, as this will yield the shortest possible augmenting path. This version of the algorithm is -called Edmonds-Karp and has a running time of $O(\abs{V}\abs{E}^2)$. The -reasoning being that on each iteration, at least one edge disappears -from the residual network, and each edge can only disappear and reappear -in the residual network $O(\abs{V})$ times. This means that the number -of loop iterations is in $O(\abs{V}\abs{E})$. Going through the edges in -the augmenting path takes $O(\abs{E})$ time, giving a total running time -of $O(\abs{V}\abs{E}^2)$. A formal proof can be found in -\cite{cormen2009introduction}. -\fixme{Unneccesary hand-waving?} - -\fixme{HAVE TO REFER TO THE ALGORITHMS, THEY ARE FLOATING} +called Edmonds-Karp and has a running time of $O(\abs{V}\abs{E}^2)$. +See \cite{cormen2009introduction} for a description of the breadth-first +search, and a formal proof of the running time of Edmonds-Karp. \subsubsection{Dinitz'} \fixme{I did implement this, but it is maybe not very central to the project/report, since I use an other algorithm in the final implementation. Maybe a comparison would be nice though.} -\fixme{DISREGARD THIS $\downarrow$} - \subsubsection{Dinic's algorithm} The «best» of the augmenting-path algorithms (citation needed). Makes a level graph with BFS, and finds a blocking flow through this graph which only goes from nodes with one label to nodes with greater labels. When this blocking flow is found we restart at the BFS. -\subsubsection{The push-relabel algorithm} -The nodes are allowed to have a positive excess but we still follow the -capacity constraints. The nodes also have a labeling, which has to be -valid. Push flow from active nodes, and relabel, preferrably in a -specific order, until it is not possible anymore. The minimal cut is -actually found before the flow becomes valid (has to be explained). +\subsection{The push-relabel algorithm} +The push-relabel algorithm is a different approach to the maximum flow +problem, presented by Goldberg and Tarjan in \cite{goldberg1988new}. +Unlike the augmenting flow algorithms, it does not at all times maintain +a valid flow $f$ in the network at all times, but still obtains a +maximum valid flow when the algorithm is finished. -Because of the way the graph evolves, we can reuse the graph between the -different labels. - -Initially proposed in \cite{goldberg1988new} where one can also find -proof that the algorithm maintains a valid labeling and that it -terminates at at maximal flow. Also has the lemma that if you have a -preflow, then there is no path from $s$ to $t$ in the residual graph. -But what is a preflow? Also, the distance label never decreases. Also -propose the global relabeling heuristic. - -Shiloach and Vishkin originally proposed the FIFO way of doing things -(according to Golberg and Tarjan)? +\subsubsection{Preflow} +Instead of maintaining a valid flow, we introduce the concept of a +\emph{preflow}, in which we relax the flow concervation constraint from +earlier a bit. For a preflow $f$, the flow must always be less than the +capacity, as before, but we allow positive excess in all vertices except +the source and the sink. The flow conservation constraint from before +then becomes +\begin{description} + \item[Relaxed flow conservation:] For all $u \in V - \{s, t\}$ + \begin{equation} + \sum_{v \in V} f(v, u) \geq \sum_{v \in V} f(u, v), + \end{equation} + i.e., for any node except the source and the sink, the + flow into the node must greater or equal to the flow out of the + node. +\end{description} -Cherkassky and Goldberg present some good implementation tips in -\cite{cherkassky1997implementing}, for example the global and gap -relabeling heuristics. Also has OK presentations of the different ways -of choosing the order of discharge operations. In the results I should -include some results with and without the heuristics. +For all vertices $u \in V$ we define the excess function +\begin{equation} + e(u) = \sum_{v \in V} f(v, u) - \sum_{v \in V} f(u, v), +\end{equation} +which represents the amount of flow which \emph{disappears} in node $u$. +Following from the constraint above $e(u) \geq 0$ for all vertices +except the source and the sink. -\cite{ahuja1997computational} has some good performance analysis. +The idea of the algorithm is to maintain a height distribution among the +nodes of the network and then ``lift'' the source node to let as many +units as possible flow through the edges of the network towards the +sink. When a maximum preflow is reached, there will normally be excess +flow in some of the vertices, which has to be pushed back towards the +source in order to obtained a valid flow. -\cite{boykov2006graph} is a good source on how graph cuts are used in -image analysis. It considers both one level graphs, and multilevel -graphs. Which is nice. It has just a small section on the different -algorithms that exist and that the special Boykov Kolmogorov algorithm -is the best. +The algorithm is based on two basic vertex operations, the \emph{push} +operation, which attempts to redistribute the excess of a vertex to its +neighbors, and the \emph{relabel} operation, which recalculates the +height of a vertex depending on the height of its neighbors. -\cite{derigs1989implementing} is also a good source for the different -heuristics. And also on the neighbor list that should not be reset after -each discharge (should try to implement this again, and reset at every -relabel!). Also has some semi-usable notes on how the minimal cut is -found after phase 1 of the algorithm is finished. Note that in this -article the gap relabeling heuristic is also called RELABEL-GLOBAL. +\subsubsection{The push operation} \begin{algorithm} \begin{algorithmic} @@ -233,6 +262,8 @@ article the gap relabeling heuristic is also called RELABEL-GLOBAL. \caption{\sf The push procedure of the Push-Relabel algorithm} \end{algorithm} +\subsubsection{The relabel operation} + \begin{algorithm} \begin{algorithmic} \Function{Relabel}{$u$} @@ -247,6 +278,10 @@ article the gap relabeling heuristic is also called RELABEL-GLOBAL. \caption{\sf The relabel procedure of the Push-Relabel algorithm} \end{algorithm} +\subsubsection{Putting it all together} + +\subsubsection{Heuristics} + \begin{algorithm} \begin{algorithmic} \Function{Gap}{$u$} @@ -259,6 +294,46 @@ article the gap relabeling heuristic is also called RELABEL-GLOBAL. \caption{\sf The gap procedure of the Push-Relabel algorithm} \end{algorithm} +The nodes are allowed to have a positive excess but we still follow the +capacity constraints. The nodes also have a labeling, which has to be +valid. Push flow from active nodes, and relabel, preferrably in a +specific order, until it is not possible anymore. The minimal cut is +actually found before the flow becomes valid (has to be explained). + +Because of the way the graph evolves, we can reuse the graph between the +different labels. + +Initially proposed in \cite{goldberg1988new} where one can also find +proof that the algorithm maintains a valid labeling and that it +terminates at at maximal flow. Also has the lemma that if you have a +preflow, then there is no path from $s$ to $t$ in the residual graph. +But what is a preflow? Also, the distance label never decreases. Also +propose the global relabeling heuristic. + +Shiloach and Vishkin originally proposed the FIFO way of doing things +(according to Golberg and Tarjan)? + +Cherkassky and Goldberg present some good implementation tips in +\cite{cherkassky1997implementing}, for example the global and gap +relabeling heuristics. Also has OK presentations of the different ways +of choosing the order of discharge operations. In the results I should +include some results with and without the heuristics. + +\cite{ahuja1997computational} has some good performance analysis. + +\cite{boykov2006graph} is a good source on how graph cuts are used in +image analysis. It considers both one level graphs, and multilevel +graphs. Which is nice. It has just a small section on the different +algorithms that exist and that the special Boykov Kolmogorov algorithm +is the best. + +\cite{derigs1989implementing} is also a good source for the different +heuristics. And also on the neighbor list that should not be reset after +each discharge (should try to implement this again, and reset at every +relabel!). Also has some semi-usable notes on how the minimal cut is +found after phase 1 of the algorithm is finished. Note that in this +article the gap relabeling heuristic is also called RELABEL-GLOBAL. + \subsubsection{Other algorithms} Special made augmenting flow algorithm for this type of graphs. Used in software1, software2, etc. Is fast. diff --git a/main.tex b/main.tex index c20cdc7..a048650 100644 --- a/main.tex +++ b/main.tex @@ -16,7 +16,7 @@ \usepackage{amsthm} % for Ã¥ lage teoremer og lignende. \usepackage{graphicx} % inkludering av grafikk -\usepackage{hyperref} % Lager hyperlinker i evt. pdf-dokument +\usepackage[hidelinks]{hyperref} % Lager hyperlinker i evt. pdf-dokument % men har noen bugs, sÃ¥ den er kommentert % bort her. diff --git a/total.tex b/total.tex index 74a2dd9..a30e159 100644 --- a/total.tex +++ b/total.tex @@ -193,6 +193,9 @@ The set perimeter behaves mostly as one might expect, just note that if the boundary of $E$ overlaps with the boundary of $\Omega$, then $P(E,\Omega)$ will not include the overlapping part of the boundary. +\fixme{WOW, this is bad! The level sets are not sets! But the perimeter +function want sets!} + For an image $u$ we introduce the level sets of $u$ as \begin{equation} u^\lambda = \idfun_{u \leq \lambda},