SCC-finden.tex 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. \subsection{SCCs finden}
  2. \begin{frame}{Wie findet man SCCs?}{}
  3. \begin{wrapfigure}{r}{150px}
  4. \begin{center}
  5. \includegraphics{Material/Bob_Tarjan.jpg}
  6. \end{center}
  7. \caption{Robert Tarjan}
  8. \end{wrapfigure}
  9. Algorithmus von Robert Tarjan
  10. % Source: http://commons.wikimedia.org/wiki/File:Bob_Tarjan.jpg
  11. nutzt Tiefensuche im Graphen
  12. \end{frame}
  13. \tikzstyle StackBox=[style=help lines,color=blue!50,fill=white]
  14. \tikzstyle{abstract}=[rectangle, draw=black,
  15. fill=orange!40,
  16. text centered, anchor=center, text=white, text width=0.4cm, text height=0.4cm]
  17. \tikzstyle{textstyle}=[rectangle, draw=white,
  18. fill=white, anchor=base west, text=black, text width=3cm, text height=0.4cm]
  19. \tikzstyle{textstyleMini}=[rectangle, draw=white,
  20. fill=white, anchor=center, text=black, text width=0.5cm, text height=0.4cm]
  21. \begin{frame}
  22. \begin{algorithm}[H]
  23. \begin{algorithmic}
  24. \Function{startTarjan}{Graph g}
  25. \State $indexCounter \gets 0$
  26. \State $stack$
  27. \ForAll{$node$ in $g$}
  28. \If{$!node.visited$}
  29. \Call{tarjan}{$node$}
  30. \EndIf
  31. \EndFor
  32. \EndFunction
  33. \end{algorithmic}
  34. \caption{Tarjans Algorithmus zur bestimmung starker Zusammenhangskomponenten}
  35. \label{alg:seq1}
  36. \end{algorithm}
  37. \end{frame}
  38. \begin{frame}
  39. \begin{algorithm}[H]
  40. \begin{algorithmic}
  41. \Function{tarjan}{Node* node}
  42. \State $node.visited \gets $ \textbf{true}
  43. \State $node.index \gets indexCounter++$
  44. \State $stack.push(node)$
  45. \ForAll{$successor$ in $node.successors$}
  46. \If{$!node.visited$}
  47. \Call{tarjan}{successor}
  48. \EndIf
  49. \State $node.lowlink \gets$ \Call{min}{$node.lowlink, successor.lowlink$}
  50. \EndFor
  51. \boxto<1->{a}\If{$node.lowlink == node.index$}
  52. \Repeat
  53. \State $successor \gets stack.pop()$
  54. \Until{$successor == node$}
  55. \EndIf\tikzmark{a}
  56. \EndFunction
  57. \end{algorithmic}
  58. \label{alg:seq2}
  59. \end{algorithm}
  60. % To insert the annotation
  61. \begin{tikzpicture}[remember picture,overlay]
  62. \coordinate (a) at ($(a)+(8.5,3)$); % <= adjust this parameter to move the position of the annotation
  63. \node[rectangle,draw, gray,text width=3cm,align=left,right] at (a) {SCC wurde gefunden, ggf. ausgeben};
  64. \end{tikzpicture}
  65. \end{frame}
  66. \begin{frame}{Wie findet man SCCs?}{}
  67. \begin{figure}
  68. \begin{tikzpicture}[->,scale=1.8, auto,swap]
  69. \node[textstyle] (Text) at (0,3) {Rekursionstiefe:};
  70. \node[textstyle] (RecDepth) at (3,3) {};
  71. % Draw the vertices
  72. \foreach \pos/\name in {{(0,0)/a}, {(0,2)/b}, {(1,2)/c},
  73. {(1,0)/d}, {(2,1)/e}, {(3,1)/f},
  74. {(4,2)/g}, {(5,2)/h}, {(4,0)/i},
  75. {(5,0)/j}}
  76. \node[vertex] (\name) at \pos {$\name$};
  77. % Connect vertices with edges
  78. \foreach \source/ \dest /\pos in {a/b/,b/c/,c/d/,d/a/,
  79. c/e/bend left, d/e/,e/c/,
  80. e/f/,
  81. f/g/, f/i/,g/f/bend right,i/f/bend left,
  82. g/h/, h/j/, j/i/, i/g/}
  83. \path (\source) edge [\pos] node {} (\dest);
  84. % Start animating the vertex and edge selection.
  85. \foreach \vertex / \fr / \lowlink / \index in {a/1/0/0,b/2/1/1,c/3/2/2,d/4/0/3,e/5/2/4,f/6/5/5,g/7/6/6,h/8/7/7,j/9/8/8,i/10/5/9} {
  86. \path<\fr-> node[selected vertex] at (\vertex) {$\vertex_{\lowlink, \index}$};
  87. \path<\fr-> node[textstyleMini] at (RecDepth) {$\index$};
  88. }
  89. % Start animating the edge selection.
  90. % For convenience we use a background layer to highlight edges
  91. % This way we don't have to worry about the highlighting covering
  92. % weight labels.
  93. \begin{pgfonlayer}{background}
  94. \path<4->[ignored edge] (d.center) edge [] node {} (a.center);
  95. \path<5->[ignored edge] (e.center) edge [] node {} (c.center);
  96. \path<10->[ignored edge] (i.center) edge [bend left] node {} (f.center);
  97. \foreach \source / \dest / \fr / \pos in {a/b/2/,b/c/3/,c/d/4/, d/e/5/,e/f/6/,f/g/7/,g/h/8/,
  98. h/j/9/,j/i/10/}
  99. \path<\fr->[selected edge] (\source.center) edge [\pos] node {} (\dest.center);
  100. \end{pgfonlayer}
  101. % go back in recursion
  102. % Start animating.
  103. \foreach \vertex / \fr / \lowlink / \index in {j/11/5/8,h/12/5/7,g/13/5/6,f/14/5/5} {
  104. \path<\fr-> node[selected vertex] at (\vertex) {$\vertex_{\lowlink, \index}$};
  105. \path<\fr-> node[textstyleMini] at (RecDepth) {$\index$};
  106. }
  107. % mark first scc
  108. \begin{pgfonlayer}{background}
  109. \path<15->[color=blue,fill=green!20] (4.2,1) circle (1.6cm);
  110. \end{pgfonlayer}
  111. % go back in recursion
  112. % Start animating.
  113. \foreach \vertex / \fr / \lowlink / \index in {e/16/2/4,c/17/0/3,b/18/0/1,a/19/0/0} {
  114. \path<\fr-> node[selected vertex] at (\vertex) {$\vertex_{\lowlink, \index}$};
  115. \path<\fr-> node[textstyleMini] at (RecDepth) {$\index$};
  116. }
  117. % mark first scc
  118. \begin{pgfonlayer}{background}
  119. \path<20->[color=blue,fill=green!20] (0.6,1) circle (1.6cm);
  120. \end{pgfonlayer}
  121. \end{tikzpicture}
  122. \end{figure}
  123. \end{frame}