%%% Matrix formatting macros for Problem Exercise 5
%%% Analysis of Algorithms, TDBC91
%%% Stephen J. Hegner, 290606

 \documentclass[12pt]{article}
 \usepackage{a4wide}
 \usepackage{pslatex}
 \usepackage{array}
 \usepackage{delarray}

 \parindent=0em
 \parskip=1em
 \newcommand{\problemspace}{\vspace{3ex}}

 %%% \csz is the width of the columns in the arrays.
 \def\csz{8pt}
 \def\ctz#1{\hfill #1 \hfil}
 %%% A row without \\ terminator.
 \def\mrowl#1#2#3#4#5{%
        $\ctz{#1}$ & $\ctz{#2}$ & $\ctz{#3}$ & $\ctz{#4}$ & $\ctz{#5}$ }
 %%% A row with \\ terminator.
 \def\mrow#1#2#3#4#5{ \mrowl{#1}{#2}{#3}{#4}{#5} \\ }
 %%% A 5x5 array.
 \def\begxarray{%
     \begin{array}[t][{*{5}{m{\csz}}}]}
 \def\endxarray{\end{array}}
 %%% A column array to represent the row values.
 \def\rowarray#1#2#3#4#5#6{%
   \begin{array}[t]{rm{\csz}} 
       $#1$ \\ $#2$ \\ $#3$ \\ $#4$  \\ $#5$ \\ \hline $#6$ \end{array}}
 %%% A row array to represent the column values.
 \def\colarray#1#2#3#4#5#6{%
   \\ \hspace*{8pt}\begin{array}[c]{*{6}{m{\csz}} m{\csz} m{\csz} }
       $#1$ & $#2$ & $#3$ & $#4$  & $#5$ &  $-$ & $#6$ 
   \end{array}}
 %%% Skip between arrays.
 \def\mhskip{\begin{array}[t]{*{5}{@{}c}} \\ \\ \mapsto \\ \\ \end{array}}

 \begin{document}

%%% A simple example:

 \noindent Vertex 1; path 1; $\hat{c}= 21 + 4 = 25$: \\
 $\begxarray
  \mrow{\infty}{20}{30}{10}{11}
  \mrow{15}{\infty}{16}{14}{2}
  \mrow{3}{5}{\infty}{2}{4}
  \mrow{19}{6}{18}{\infty}{3}
  \mrowl{16}{4}{7}{16}{\infty}
 \endxarray
 \mhskip
 \begxarray
  \mrow{\infty}{10}{20}{0}{1}
  \mrow{13}{\infty}{14}{2}{0}
  \mrow{1}{3}{\infty}{0}{2}
  \mrow{16}{3}{15}{\infty}{0}
  \mrowl{12}{0}{3}{12}{\infty}
 \endxarray
 \rowarray{10}{2}{2}{3}{4}{21}
 \mhskip
 \begin{array}[t]{l}
 \begxarray
  \mrow{\infty}{10}{17}{0}{1}
  \mrow{12}{\infty}{11}{2}{0}
  \mrow{0}{3}{\infty}{0}{2}
  \mrow{15}{3}{12}{\infty}{0}
  \mrowl{11}{0}{0}{12}{\infty}
   \endxarray 
  \colarray{1}{0}{3}{0}{0}{4}
  \end{array}$

 \noindent Vertex 2; path 12; $\hat{c} = 25  + 10 + 0 + 0 = 35$: \\
 $\begxarray
  \mrow{\infty}{10}{17}{0}{1}
  \mrow{12}{\infty}{11}{2}{0}
  \mrow{0}{3}{\infty}{0}{2}
  \mrow{15}{3}{12}{\infty}{0}
  \mrowl{11}{0}{0}{12}{\infty}
  \endxarray 
 \mhskip
 \begxarray
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrow{\infty}{\infty}{11}{2}{0}
  \mrow{0}{\infty}{\infty}{0}{2}
  \mrow{15}{\infty}{12}{\infty}{0}
  \mrowl{11}{\infty}{0}{12}{\infty}
 \endxarray
 \mhskip
 \begxarray
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrow{\infty}{\infty}{11}{2}{0}
  \mrow{0}{\infty}{\infty}{0}{2}
  \mrow{15}{\infty}{12}{\infty}{0}
  \mrowl{11}{\infty}{0}{12}{\infty}
 \endxarray
 \rowarray{0}{1}{0}{0}{0}{0}
 \mhskip
 \begin{array}[t]{l}
 \begxarray
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrow{\infty}{\infty}{11}{2}{0}
  \mrow{0}{\infty}{\infty}{0}{2}
  \mrow{15}{\infty}{12}{\infty}{0}
  \mrowl{11}{\infty}{0}{12}{\infty}
   \endxarray 
  \colarray{0}{0}{0}{0}{0}{0}
  \end{array}$


 \noindent Vertex 3; path 13; $\hat{c}= 25 + 17 + 0 + 11 = 53$: \\
 $\begxarray
  \mrow{\infty}{10}{17}{0}{1}
  \mrow{12}{\infty}{11}{2}{0}
  \mrow{0}{3}{\infty}{0}{2}
  \mrow{15}{3}{12}{\infty}{0}
  \mrowl{11}{0}{0}{12}{\infty}
  \endxarray 
 \mhskip
 \begxarray
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrow{12}{\infty}{\infty}{2}{0}
  \mrow{\infty}{3}{\infty}{0}{2}
  \mrow{15}{3}{\infty}{\infty}{0}
  \mrowl{11}{0}{\infty}{12}{\infty}
 \endxarray
 \mhskip
 \begxarray
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrow{12}{\infty}{\infty}{2}{0}
  \mrow{\infty}{3}{\infty}{0}{2}
  \mrow{15}{3}{\infty}{\infty}{0}
  \mrowl{11}{0}{\infty}{12}{\infty}
 \endxarray
 \rowarray{0}{0}{0}{0}{0}{0}
 \mhskip
 \begin{array}[t]{l}
 \begxarray
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrow{1}{\infty}{\infty}{2}{0}
  \mrow{\infty}{3}{\infty}{0}{2}
  \mrow{4}{3}{\infty}{\infty}{0}
  \mrowl{0}{0}{\infty}{12}{\infty}
   \endxarray 
  \colarray{11}{0}{0}{0}{0}{11}
  \end{array}$

 \noindent Vertex 4; path 14; $\hat{c}= 25 + 0 + 0 + 0 = 25$: \\
 $\begxarray
  \mrow{\infty}{10}{17}{0}{1}
  \mrow{12}{\infty}{11}{2}{0}
  \mrow{0}{3}{\infty}{0}{2}
  \mrow{15}{3}{12}{\infty}{0}
  \mrowl{11}{0}{0}{12}{\infty}
  \endxarray 
 \mhskip
 \begxarray
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrow{12}{\infty}{11}{\infty}{0}
  \mrow{0}{3}{\infty}{\infty}{2}
  \mrow{\infty}{3}{12}{\infty}{0}
  \mrowl{11}{0}{0}{\infty}{\infty}
 \endxarray
 \mhskip
 \begxarray
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrow{12}{\infty}{\infty}{2}{0}
  \mrow{\infty}{3}{\infty}{0}{2}
  \mrow{15}{3}{\infty}{\infty}{0}
  \mrowl{11}{0}{\infty}{12}{\infty}
 \endxarray
 \rowarray{0}{0}{0}{0}{0}{0}
 \mhskip
 \begin{array}[t]{l}
 \begxarray
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrow{1}{\infty}{\infty}{2}{0}
  \mrow{\infty}{3}{\infty}{0}{2}
  \mrow{4}{3}{\infty}{\infty}{0}
  \mrowl{0}{0}{\infty}{12}{\infty}
   \endxarray 
  \colarray{0}{0}{0}{0}{0}{0}
  \end{array}$

 \noindent Vertex 5; path 15; $\hat{c}= 25 + 1 + 0 + 5 = 31$: \\
 $\begxarray
  \mrow{\infty}{10}{17}{0}{1}
  \mrow{12}{\infty}{11}{2}{0}
  \mrow{0}{3}{\infty}{0}{2}
  \mrow{15}{3}{12}{\infty}{0}
  \mrowl{11}{0}{0}{12}{\infty}
  \endxarray 
 \mhskip
 \begxarray
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrow{12}{\infty}{11}{2}{\infty}
  \mrow{0}{3}{\infty}{0}{\infty}
  \mrow{15}{3}{12}{\infty}{\infty}
  \mrowl{\infty}{0}{0}{12}{\infty}
 \endxarray
 \mhskip
 \begxarray
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrow{10}{\infty}{9}{0}{\infty}
  \mrow{0}{3}{\infty}{0}{\infty}
  \mrow{12}{0}{9}{\infty}{\infty}
  \mrowl{\infty}{0}{0}{12}{\infty}
 \endxarray
 \rowarray{0}{2}{0}{3}{0}{5}
 \mhskip
 \begin{array}[t]{l}
 \begxarray
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrow{10}{\infty}{9}{0}{\infty}
  \mrow{0}{3}{\infty}{0}{\infty}
  \mrow{12}{0}{9}{\infty}{\infty}
  \mrowl{\infty}{0}{0}{12}{\infty}
 \endxarray 
  \colarray{0}{0}{0}{0}{0}{0}
  \end{array}$

  \newpage
  \noindent Vertex 6; path 142; $\hat{c}= 25 + 3 + 0 + 0 = 28$: \\
 $\begxarray
  \mrow{\infty}{10}{17}{0}{1}
  \mrow{12}{\infty}{11}{2}{0}
  \mrow{0}{3}{\infty}{0}{2}
  \mrow{15}{3}{12}{\infty}{0}
  \mrowl{11}{0}{0}{12}{\infty}
  \endxarray 
 \mhskip
 \begxarray
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrow{\infty}{\infty}{11}{\infty}{0}
  \mrow{0}{\infty}{\infty}{\infty}{2}
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrowl{11}{\infty}{0}{\infty}{\infty}
 \endxarray
 \mhskip
 \begxarray
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrow{\infty}{\infty}{11}{\infty}{0}
  \mrow{0}{\infty}{\infty}{\infty}{2}
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrowl{11}{\infty}{0}{\infty}{\infty}
 \endxarray
 \rowarray{0}{0}{0}{0}{0}{0}
 \mhskip
 \begin{array}[t]{l}
 \begxarray
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrow{\infty}{\infty}{11}{\infty}{0}
  \mrow{0}{\infty}{\infty}{\infty}{2}
  \mrow{\infty}{\infty}{\infty}{\infty}{\infty}
  \mrowl{11}{\infty}{0}{\infty}{\infty}
 \endxarray 
  \colarray{0}{0}{0}{0}{0}{0}
  \end{array}$

\end{document}
