📚 The CoCalc Library - books, templates and other resources
cocalc-examples / martinthoma-latex-examples / source-code / Pseudocode / Stoer-Wagner / Stoer-Wagner.tex
132930 viewsLicense: OTHER
\documentclass{article}1\usepackage[pdftex,active,tightpage]{preview}2\setlength\PreviewBorder{2mm}34\usepackage[utf8]{inputenc} % this is needed for umlauts5\usepackage[ngerman]{babel} % this is needed for umlauts6\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf7\usepackage{amssymb,amsmath,amsfonts} % nice math rendering8\usepackage{braket} % needed for \Set9\usepackage{algorithm,algpseudocode}1011\begin{document}12\begin{preview}13Sei $S \subseteq V$ und $c:E\rightarrow\mathbb{R}_0^+$ die14Kantengewichtsfunktion.15Für $v \in V \setminus S$ sei:1617\begin{align*}18c &:\mathcal{P}(V) \times V \rightarrow \mathbb{R}_0^+\\19c(S,v) &:= \sum_{\substack{\Set{u,v} \in E\\ u \in S}} c(\Set{u,v})20\end{align*}2122Sei nun $d: \mathcal{P}(V) \rightarrow V$ die Funktion, die den23Knoten liefert, der am stärksten mit $S \in \mathcal{P}(V)$24verbunden ist:25\[d(S) := v \in V \setminus S: c(S, v) = \max(\Set{c(S,v) | v \in V \setminus S})\]2627\begin{algorithm}[H]28\begin{algorithmic}29\Function{StoerWagner}{Network $N(D, s, t, c)$}30\State Graph $G_0 = D$31\State Knoten $a,b,v$32\State Phasenergebnisse $P$ \Comment{Speichert Schnitt und Gewicht}33\For{($i=1$; $\;i<|V|$; $\;i$++)}34\State Knotenmenge $S_i \gets \Set{}$35\State $S_i$.add($S_i \in G_i$) \Comment{Wähle einen beliebigen Startknoten}36\While{$S_i \neq V_{i-1}$}37\State $v \gets$ \Call{d}{$S_i$}38\State $S_i$.add($v$)39\EndWhile4041\State $a \gets v$42\State $b \gets$ \Call{d}{$\Set{a}$}43\State $V_i \gets$ \Call{Verschmelzen}{$V_{i-1}$, $a$, $b$}44\State $E_i \gets$ \Call{Verschmelzen}{$E_{i-1}$, $a$, $b$}45\State $G_i = (V_i, E_i)$46\State $P$.add($(a, V \setminus a)$, $c(a, V \setminus a)$)47\EndFor4849\State \Return $P$.getMinimalCut()50\EndFunction5152\Function{Verschmelzen}{Knotenmenge $V$, Knoten $a$, Knoten $b$}53\State $V$.remove($a$)54\State $V$.remove($b$)55\State \Comment{TODO: was, wenn a und b schon Mengen sind?}56\State $V$.add($\Set{a, b}$)57\EndFunction5859\Function{Verschmelzen}{Kantenmenge $E$, Knoten $a$, Knoten $b$}60\State \Comment{TODO: Kantengewichtsfunktion muss auch angepasst werden}61\ForAll{Kante $e:=(x,y) \in E$}62\If{$x == a \lor x == b$}63\State $E$.remove($e$)64\State $E$.add($(\Set{a, b},y)$)65\ElsIf{$y == a \lor y == b$}66\State $E$.remove($e$)67\State $E$.add($(x, \Set{a, b})$)68\EndIf69\EndFor70\EndFunction71\end{algorithmic}72\caption{Algorithmus von Stoer und Wanger}73\label{alg:seq1}74\end{algorithm}75\end{preview}76\end{document}777879