Commit d737c1ba by Ondřej Mička

### Graphs: Dinic picture and code

parent 56200b30
 ... @@ -2,7 +2,7 @@ TOP=.. ... @@ -2,7 +2,7 @@ TOP=.. include ../Makerules include ../Makerules IMAGES=range-tree lazy-update heavy-light expose-idea middle-sons expose-real expose-phases IMAGES=range-tree lazy-update heavy-light expose-idea middle-sons expose-real expose-phases level-network $(MAIN).pdf: images$(MAIN).pdf: images ... ...
 ... @@ -78,7 +78,7 @@ from $x$ to $z$. The node~$x$ is marked, with $\delta = +4$, so we need to incre ... @@ -78,7 +78,7 @@ from $x$ to $z$. The node~$x$ is marked, with $\delta = +4$, so we need to incre stored in~$x$ by~4 and transfer mark to both children of~$x$. Then we can visit~$x$ and stored in~$x$ by~4 and transfer mark to both children of~$x$. Then we can visit~$x$ and move along to~$y$. Node~$y$ is also marked now, so we update~$y$ and transfer mark to both move along to~$y$. Node~$y$ is also marked now, so we update~$y$ and transfer mark to both children. Left child of~$y$ was already marked by $+3$, so we have change the mark to children. Left child of~$y$ was already marked by $+3$, so we have change the mark to $+7$.\TODO shorter caption} $+7$.} \qed \qed ... @@ -110,7 +110,7 @@ linear time. ... @@ -110,7 +110,7 @@ linear time. \figure[]{heavy-light.pdf}{}{Example of heavy-light decomposition. Top part shows a tree \figure[]{heavy-light.pdf}{}{Example of heavy-light decomposition. Top part shows a tree with heavy paths marked by thick lines. Numbers in parenthesis show the value of $s(v)$ with heavy paths marked by thick lines. Numbers in parenthesis show the value of $s(v)$ (ones are omitted). Bottom part shows the tree after compression of non-trivial heavy (ones are omitted). Bottom part shows the tree after compression of non-trivial heavy paths.\TODO shorter caption} paths.} \subsection{Lowest common ancestor} \subsection{Lowest common ancestor} A simple application of heavy-light decomposition is a data structure to answer lowest A simple application of heavy-light decomposition is a data structure to answer lowest ... @@ -464,9 +464,12 @@ from~$s$ to~$t$ in the residual network\footnote{Residual network is a network c ... @@ -464,9 +464,12 @@ from~$s$ to~$t$ in the residual network\footnote{Residual network is a network c the edges with non-zero residual capacity, that is, difference between capacity and a the edges with non-zero residual capacity, that is, difference between capacity and a flow. Capacity of each edge in residual network is exactly the residual capacity.}. The flow. Capacity of each edge in residual network is exactly the residual capacity.}. The important property of level graph is that it is acyclic and it can be decomposed into important property of level graph is that it is acyclic and it can be decomposed into levels such that there are no edges between vertices in each level, see Figure~\TODO level levels such that there are no edges between vertices in each level, see Figure~\figref{level-network} level graph. graph. \figure[level-network]{level-network.pdf}{}{Example of a level network.} Dinic's algorithm starts with a zero flow and in each iteration it finds a blocking flow Dinic's algorithm starts with a zero flow and in each iteration it finds a blocking flow in the level graph and augments the flow with the blocking flow. It can be shown that we in the level graph and augments the flow with the blocking flow. It can be shown that we need~$n$ iterations to find the maximum flow in~$G$. need~$n$ iterations to find the maximum flow in~$G$. ... @@ -495,6 +498,15 @@ $s \to t$ and perform a path update that decreases costs on $s\to t$ by $\Cost(e ... @@ -495,6 +498,15 @@$s \to t$and perform a path update that decreases costs on$s\to t$by$\Cost(e This corresponds to increasing the flow on $s\to t$ by $\Cost(e)$. If $\Cost(e) = 0$ we This corresponds to increasing the flow on $s\to t$ by $\Cost(e)$. If $\Cost(e) = 0$ we simply cut~$e$ and remove it from $F$. simply cut~$e$ and remove it from $F$. \proc{Augment step} \:If $\Root(s) = t$, then: \::$e \= \op{PathMin}(s)$ \::If $\Cost(e) = 0$: \:::$\op{Cut}(e)$ \::else: \:::$\op{PathUpdate}(s, -\Cost(e))$ \endalgo The other step is expand step which is performed when $\Root(s) = r \neq t$. If $r$ The other step is expand step which is performed when $\Root(s) = r \neq t$. If $r$ has an unmarked outgoing edge~$e$ we simply add~$e$ to~$F$ using $\op{Link}(e)$ and we has an unmarked outgoing edge~$e$ we simply add~$e$ to~$F$ using $\op{Link}(e)$ and we mark~$e$. However, if there is no such edge, all $s\to t$ paths via~$r$ are already mark~$e$. However, if there is no such edge, all $s\to t$ paths via~$r$ are already ... @@ -502,7 +514,17 @@ blocked and we may remove~$r$ from~$F$ for good. That is, we remove all edges th ... @@ -502,7 +514,17 @@ blocked and we may remove~$r$ from~$F$ for good. That is, we remove all edges th to~$r$. Marked edges still present in~$F$ are cut and deleted from~$F$, unmarked edges are to~$r$. Marked edges still present in~$F$ are cut and deleted from~$F$, unmarked edges are marked but not added to~$F$. marked but not added to~$F$. \TODO algorithm pseudocode \proc{Expand step} \:$r \= \Root(s)$ \:If $r \neq t$: \::If exists unmarked edge~$e$ going from $r$: \:::$\op{Mark}(e)$ \:::$\op{Link}(e)$ \::else: \::: For each edge $e = (u,r)$: \::::$\op{Mark}(e)$ \::::$\op{Cut}(e)$ \cmt{Cut does nothing if $e$ is not in the tree} \endalgo We repeat these steps until $\Root(s) = s$ and all edges going out from~$s$ are marked. We repeat these steps until $\Root(s) = s$ and all edges going out from~$s$ are marked. That is, we stop when $s$ would be removed from~$F$ during expand step. Using simple That is, we stop when $s$ would be removed from~$F$ during expand step. Using simple ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!