From d737c1ba9f942dbfe1a1c07b664a555500e32eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ondra=20Mi=C4=8Dka=20=40=20miles-teg?= <mitch.ondra@gmail.com> Date: Wed, 25 Aug 2021 15:30:14 +0200 Subject: [PATCH] Graphs: Dinic picture and code --- om-graphs/Makefile | 2 +- om-graphs/graphs.tex | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/om-graphs/Makefile b/om-graphs/Makefile index 68d5356..65115ee 100644 --- a/om-graphs/Makefile +++ b/om-graphs/Makefile @@ -2,7 +2,7 @@ TOP=.. 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 diff --git a/om-graphs/graphs.tex b/om-graphs/graphs.tex index 305babd..140a21c 100644 --- a/om-graphs/graphs.tex +++ b/om-graphs/graphs.tex @@ -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 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 -$+7$.\TODO shorter caption} +$+7$.} \qed @@ -110,7 +110,7 @@ linear time. \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)$ (ones are omitted). Bottom part shows the tree after compression of non-trivial heavy -paths.\TODO shorter caption} +paths.} \subsection{Lowest common ancestor} 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 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 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. +\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 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$. @@ -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 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$ 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 @@ -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 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. That is, we stop when $s$ would be removed from~$F$ during expand step. Using simple -- GitLab