bellman-ford-algorithm.tex 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. \documentclass{beamer}
  2. \usepackage{tikz}
  3. \usepackage{verbatim}
  4. \usetikzlibrary{arrows,shapes}
  5. \begin{document}
  6. \pgfdeclarelayer{background}
  7. \pgfsetlayers{background,main}
  8. \tikzset{
  9. vertex/.style={
  10. circle,
  11. fill=black!25,
  12. minimum size=20pt,
  13. inner sep=0pt,
  14. text height=1ex,
  15. text depth=1ex,
  16. label={[weight label]center:\weight},
  17. label={[pred label]center:\pred}
  18. },
  19. pred label/.style={
  20. font=\tiny,
  21. xshift=0.3em,
  22. yshift=-0.8ex,
  23. text height=1ex,
  24. text depth=0pt
  25. },
  26. weight label/.style={
  27. font=\tiny,
  28. xshift=-0.3em,
  29. yshift=-0.8ex,
  30. text height=1ex,
  31. text depth=0pt
  32. }
  33. }
  34. \tikzstyle{vertexOnly}=[circle,fill=black!25,minimum size=20pt,inner sep=0pt]
  35. \tikzstyle{selected vertex} = [vertex, fill=red!24]
  36. \tikzstyle{edge} = [->,draw,thick]
  37. \tikzstyle{weight} = [font=\small]
  38. \tikzstyle{selected edge} = [draw,line width=5pt,-,red!50]
  39. \tikzstyle{ignored edge} = [draw,line width=5pt,-,black!20]
  40. \begin{frame}
  41. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  42. % Given Graph %
  43. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  44. \begin{figure}
  45. \begin{tikzpicture}[scale=2.5, auto,swap]
  46. % First we draw the vertices
  47. \foreach \pos/\name in {{(0,2)/a}, {(1,2)/b}, {(2,2)/c},
  48. {(0,1)/d}, {(1,1)/e}, {(2,1)/f},
  49. {(0,0)/g}, {(1,0)/h}, {(2,0)/i}}
  50. \node[vertexOnly] (\name) at \pos {$\name$};
  51. % Connect vertices with edges and draw weights
  52. \foreach \source/ \dest /\weight/\style in {a/b/0/, b/c/1/, a/d/2/, e/d/5/,
  53. b/e/3/bend right, e/b/-1/bend right, b/f/4/above, f/i/3/,
  54. i/e/1/, g/h/1/}
  55. \path (\source) edge[->,\style, thick] node {$\weight$} (\dest);
  56. \end{tikzpicture}
  57. \end{figure}
  58. \end{frame}
  59. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  60. % Initialisation %
  61. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  62. \begin{frame}
  63. \begin{figure}
  64. \begin{tikzpicture}[scale=2.5, auto,swap]
  65. % First we draw the vertices
  66. \foreach \pos/\name/\weight/\pred in {
  67. {(0,2)/a/$0$/-},{(1,2)/b/$\infty$/-}, {(2,2)/c/$\infty$/-},
  68. {(0,1)/d/$\infty$/-}, {(1,1)/e/$\infty$/-}, {(2,1)/f/$\infty$/-},
  69. {(0,0)/g/$\infty$/-}, {(1,0)/h/$\infty$/-}, {(2,0)/i/$\infty$/-}}
  70. \node[vertex] (\name) at \pos {$\name$};
  71. % Connect vertices with edges and draw weights
  72. \foreach \source/ \dest /\weight/\style in {
  73. a/b/0/, b/c/1/, a/d/2/, e/d/5/, b/e/3/bend right,
  74. e/b/-1/bend right, b/f/4/above, f/i/3/, i/e/1/,
  75. g/h/1/}
  76. \path (\source) edge[->,\style, thick] node {$\weight$} (\dest);
  77. \end{tikzpicture}
  78. \end{figure}
  79. \end{frame}
  80. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  81. % first iteraton %
  82. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  83. \begin{frame}
  84. \begin{figure}
  85. \begin{tikzpicture}[scale=2.5, auto,swap]
  86. % First we draw the vertices
  87. \foreach \pos/\name/\weight/\pred in {
  88. {(1,2)/b/$\infty$/-}, {(2,2)/c/$\infty$/-},
  89. {(0,1)/d/$\infty$/-}, {(1,1)/e/$\infty$/-}, {(2,1)/f/$\infty$/-},
  90. {(0,0)/g/$\infty$/-}, {(1,0)/h/$\infty$/-}, {(2,0)/i/$\infty$/-}}
  91. \node[vertex] (\name) at \pos {$\name$};
  92. % Connect vertices with edges and draw weights
  93. \foreach \source/ \dest /\weight/\style in {
  94. a/b/0/, b/c/1/, a/d/2/, e/d/5/, b/e/3/bend right,
  95. e/b/-1/bend right, b/f/4/above, f/i/3/, i/e/1/,
  96. g/h/1/}
  97. \path (\source) edge[->,\style, thick] node {$\weight$} (\dest);
  98. \end{tikzpicture}
  99. \end{figure}
  100. \end{frame}
  101. \end{document}