% $Header: /home/rdv/quantum/genetic-paper/RCS/eaqc-paper.tex,v 1.12 2005/05/29 21:34:00 rdv Exp rdv $
% now how do I set the paper size?
% \documentclass[twocolumn]{article}

\documentclass[onecolumn,doublespace]{article}
\usepackage{times}
\usepackage{graphics}
\usepackage{lscape}
\usepackage{subfigure}
\usepackage{graphicx}
\usepackage{color}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{kbordermatrix,blkarray}
\pagestyle{plain}

\bibliographystyle{unsrt}   %>>>> makes bibtex use spiebib.bst

% \input{psfig}
\input{epsf}
% \epsfverbosetrue

%\def\comment#1{$\Rightarrow${\small\em #1}}
\def\comment#1{}
\newenvironment{chapterquote}
  {\begin{quotation}
      \sf}
  {\end{quotation}}
\def\cq#1#2{\begin{chapterquote}#1\flushright\textbf{#2}\end{chapterquote}}


\newcommand{\icol}[1]{% inline column vector
  \left(\begin{smallmatrix}#1\end{smallmatrix}\right)%
}

\newcommand{\irow}[1]{% inline row vector
  \begin{smallmatrix}(#1)\end{smallmatrix}%
}

\newcommand{\tvec}[1]{%
  \vec{#1}^{\thinspace\intercal}%
}

\newcommand{\myblank}{%
 \thinspace\textvisiblespace\thinspace
}

\begin{document}
\title{Optimization Theory (DS2) Lecture \#8\\
$A^*$ Algorithm, Duality, and Minimum Spanning Tree Via Linear Algebra
}
\maketitle
\begin{abstract}
  Today we are going through the $A^*$ algorithm, which doesn't appear
  in the textbook, duality (which does), and looking at MSTs (which
  don't) using duality and LA.
\end{abstract}

\emph{Some text and examples adapted from the paperback edition of
  \emph{A Gentle Introduction to Optimization}, B. Guerin \emph{et
    al.}}

\section{Reorganizing the Semester}

Now that we are about halfway through the semester, we can see a
little more clearly the complete picture of where we are headed:

\begin{itemize}
\item Lec. 1: Introduction
\item Basics of Linear Programming
  \begin{itemize}
  \item Lec. 2: Examples of Linear, Integer and Graph Problems
    (formulating formal descriptions of problems)
  \item Lec. 3: Three Kinds of Certificates, Standard Equality Form,
    and a Simplex Iteration
  \item Lec. 4: The Heart of the Simplex Algorithm (bases and
    canonical forms) \emph{In my opinion, this is the hardest week of
      the semester!}
  \item Lec. 5: Sticking a Stake in the Heart of the Simplex Algorithm
  \end{itemize}
\item Graph Algorithms
  \begin{itemize}
  \item Lec. 6: Basic Ideas of Graphs, Dijkstra's Shortest Path First
    Algorithm
  \item Lec. 7: Several Minimum Spanning Tree Algorithms
  \item Lec. 8: $A^*$ Algorithm, Duality, and Minimum Spanning Tree
    Via Linear Algebra
  \item Lec. 9: Minimum Weight Bipartite Matching (and more Duality)
  \item (Sadly, we are going to skip some important problems such as
    set cover, and min cut max flow.  Semester projects, perhaps?)
  \end{itemize}
\item Integer Problems
  \begin{itemize}
  \item Lec. 10: The Knapsack Problem
    \item (Sadly, we are going to skip \emph{many} important problems
      and solutions here!)
  \end{itemize}
\item Computational Complexity
  \begin{itemize}
  \item Lec. 11: Basic Ideas of Computational Complexity
  \end{itemize}
\item Non-Linear Programming (NLP) and Advanced Techniques \\
  \emph{Warning: These lectures require a little basic calculus!  But
    don't worry too much if you're not up on your derivatives; there
    will be no required homework on these lectures.}
  \begin{itemize}
  \item Lec. 12: Basics: Finding a Min/Max of a Function (Derivatives,
    Gradient Descent, Newton's Method)
  \item Lec. 13: Deterministic Exact, Deterministic Heuristic, and
    Random Algorithms (AI-like methods, more on computational complexity)
  \item Lec. 14: Pareto Optimality and Wrapping Up the Semester
  \end{itemize}
\end{itemize}

\section{Semester Projects}

In the English Wikipedia page on the simplex algorithm, I like the
explanation of the history, and I like the images, but the explanation
of tableaus and pivots is not quite the way we're solving things, so I
wouldn't invest too much time in trying to understand that.

The Japanese page on the simplex algorithm is actually poor.  \emph{I
  would {\bf gladly} accept a student rewriting that Wikipedia page as
  an end-of-term project!}  In fact, I encourage it!  Any volunteers?

You should expect that your project will take 10-20 hours; if it takes
less than that, it's too lightweight.

Types of projects:

\begin{enumerate}
\item Create or improve an optimization-related Wikipedia page, such
  as:
  \begin{enumerate}
  \item the Japanese page on simplex
  \item the Indonesian page on just about anything
  \end{enumerate}
  Languages other than English, Japanese or Indonesian require prior
  approval, and will require an outside evaluator.
\item 3D print a teaching tool I can keep, e.g. a polytope for a
  \emph{specific} linear problem, or a 2D optimization surface with a
  max, a min, and a saddle point.
\item A compiler that takes in graphviz and outputs OpenSCAD.
  Ideally, this would be a plugin for the existing graphviz tools.
\item Find and solve a medium sized optimization problem using one of
  the techniques from class.  This should be a large enough problem
  that creating the formal definition is non-trivial, and presumably
  the solution will require the use of some computer method.  For
  this, you may use existing tools, as the emphasis is on the problem.
\item Implement one of the algorithms from class.  Your choice of
  language.  This is \emph{not} just learning to use some existing
  library!
\item Write a 5 page report on advanced optimization (e.g., one of the
  topics from the last two weeks of the semester).
\item Work on one of the sections from the textbook that we didn't
  cover.
\end{enumerate}

\section{Interlude: Most Important Algorithms of the 20th Century}

The Society for Industrial and Applied Mathematics (SIAM) named the
top ten algorithms of the 20th century.  Simplex and Metropolis
(arguably the first important Monte Carlo algorithm) are two of them.

There is also the book, \emph{9 Algorithms That Changed the Future},
by John MacCormick, but it's more of a list of problems than
algorithms.

Marcos Otero also created a list in reply to a list that I don't
actually like.  Even Oteros' is more of a list of problems than
algorithms.


\section{$A^*$ Algorithm}

I don't know if $A^*$ is the way that Google Maps or Ekitan solves
your routing problem to get here in the morning, but it \emph{could}.
Some people think of $A^*$ as an extension to or generalization of
Dijkstra's shortest path algorithm, but it expands the range of
applications so much that I think of it as a separate algorithm.

In Dijkstra's algorithm, the frontier (or ``open set'') consists of a
set of nodes with links headed out from there, the links currently
under consideration for addition to our path(s).  We select the next
link based on
\begin{align}
\operatorname{min}(d(n) + c_e), n \in F, e \in \textrm{edges of } n
\end{align}
for $d()$ being the distance from the origin to the node $n$, $c_e$
being the cost of edge $e$ from node $n$.  That is, we add a new node
to the frontier by selecting the next node with the lowest total cost
back to our origin.

Putting it another way, we can talk about $f(n)$, for all $n \in
\operatorname{Succ}(F)$, the set of possible successor nodes, the
candidates to be added to our tree.  (This will be a little easier for
talking about $A^*$.)

Then we can modify $f(n)$ to be
\begin{align}
f(n) = g(n) + h(n)
\end{align}
where $g(n)$ is the distance to the node, and $h(n)$ is a
\emph{heuristic} for estimating the distance from $n$ to the
destination.

$A^*$ is fantastically useful when Dijkstra fails us in practice,
because it guides the set of things we look at next for efficiency,
without ultimately preventing us from finding the solution even in
``bad'' cases.  It is also good when our ``graph'' is effectively
determined dynamically, as long as we can limit the set of things we
add at each step.

\section{Duality, marking a brief return to linear algebra}

\subsection{Examples}

There are several cases of duality.  Let's look at a couple.  The
minimization form of the linear program:
\begin{align}
  \operatorname{min} z(\vec{x}) = \tvec{c}\vec{x}
\end{align}
subject to
\begin{align}
A\vec{x} & \ge \vec{b} \label{eq:ge-primal} \\
\vec{x} & \ge \vec{0}
\end{align}
has a \emph{dual} program
\begin{align}
  \operatorname{max} z'(\vec{y}) = \tvec{b}\vec{y}
\end{align}
subject to
\begin{align}
A^\intercal\vec{y} & \le \vec{c} \\
\vec{y} & \ge \vec{0}.
\end{align}

The superficially similar problem where the $\ge$ in
Eq.~\ref{eq:ge-primal} is replaced with $=$ has a different dual:
\begin{align}
  \operatorname{min} z(\vec{x}) = \tvec{c}\vec{x}
\end{align}
subject to
\begin{align}
A\vec{x} & = \vec{b}  \label{eq:eq-primal}\\
\vec{x} & \ge \vec{0}
\end{align}
has the \emph{dual} program
\begin{align}
  \operatorname{max} z'(\vec{y}) = \tvec{b}\vec{y}
\end{align}
subject to
\begin{align}
A^\intercal\vec{y} & \le \vec{c} \\
\vec{y} & \textrm{  free.}
\end{align}

Note the difference in the last lines of the two dual problems.

In the textbook, the primal problem is the maximization problem,
called $P$ or $P_{\textrm{max}}$ and the minimization problem is the
dual problem, called $D$ or $P_{\textrm{min}}$, so technically our
first problem above is actually the dual and its dual is the primal.

\subsection{Constructing the dual}

Personally, I found Table 4.1 in the textbook to be cryptic.  Let me
try to reconstruct it for you.  In each block below, replace the
``\myblank'' place with the symbol below it, then read across for what
it generates in the dual problem.  For example, if $A\vec{x} =
\vec{b}$, read down to ``$=$ constraint'' and across to ``free
variable'' to learn that the $y_i$ corresponding to a particular line
in the set of constraints having an equals sign results in a new
variable in $\vec{y}$ that is a free variable.

% or use \textvisiblespace?
\begin{tabular}{c|c}
$P (P_{\textrm{max}})$ & $D (P_{\textrm{min}})$ \\ \hline
$A\vec{x} \myblank \vec{b}$ & $\vec{y} \myblank \vec{0}$ \\
$\le$ constraint & $\ge 0$ variable \\ 
$=$ constraint & free variable \\
$\ge$ constraint & $\le 0$ variable \\
\hline
$\vec{x} \myblank \vec{0}$  & $A^\intercal\vec{y} \myblank \vec{c}$ \\
$\ge 0$ variable & $\ge$ constraint \\
free variable & $=$ constraint \\
$\le 0$ variable & $\le$ constraint \\
 \hline
\end{tabular}

\subsection{A couple of comments}

The dual of the dual of a problem is the original problem.  (If it's
not, you've done something wrong, such as the problem wasn't properly
specified in the first place.)

The \emph{weak duality theorem} says that the objective function value
for the maximization problem $P$ is always less than or equal to the
objective function for the minimization function.  If they are equal,
then you have found optimal solutions for both.  It also implies that
if the primal is unbounded, then the dual is infeasible, and
vice-versa.

The \emph{strong duality theorem} says that if the primal has a
bounded optimal value for the objective function $z(\vec{x})$, then
the the dual also has an optimal value for its objective function
$z'(\vec{y})$, and in fact, \emph{those optimal values are always the
  same!}

\section{Minimum spanning tree via LP (and Duality)}

We're going to try this on the graph we used last week, which consists
of 9 nodes and 14 links, so it's bit of a large problem to do by hand,
but I want you to see the techniques.  Although we're not going to
cover everything you can do to graph problems using matrices, I also
want you to get the idea that matrices can be used in graph problems.

A complete, proper formulation via linear programming would involve an
exponential number of constraints.  Basically, you write out every
proper, non-empty subset of vertices and create a constraint that says
that there must be at least one edge connecting a node \emph{inside}
the subset with a node \emph{outside} the subset.  For a graph with $v
= |V|$ vertices, this would be $2^v - 2$ constraints.  For our graph
in Fig.~\ref{fig:graph-algos}, that would be 510 constraints, and I'm
not planning on writing those out by hand!  Even for a computer, such
exponential growth \emph{very} quickly leaves the ream of the
possible.

\begin{figure}
\includegraphics[width=13cm]{graph-algos}
\caption{Our figure from Intro to Algorithms.}
\label{fig:graph-algos}
\end{figure}

Instead, I want to demonstrate the principles by creating a hybrid
approach here.  (I haven't seen this approach written down anywhere
before.  This is my own formulation, but I have no doubt both that it
is correct and has been discovered before.)  Basically, we're going to
do Boruvka's algorithm where each iteration is done using an LP.

\subsection{The program}

The minimization form of the problem (note that our $x$ and $y$ here
are swapped relative to the above):

\begin{align}
  \operatorname{min} z(\vec{x}) = \tvec{c}\vec{x}
\end{align}
subject to
\begin{align}
A\vec{x} & \ge \vec{b} \\
\vec{x} & \ge 0, \vec{x} \textrm{  integer}
\end{align}
where
\begin{align}
\vec{c}^\intercal & = (4,8,11,8,7,1,2,6,7,4,2,14,9,10) \\
\vec{x}^\intercal & = (x_{ab},x_{ah},x_{bh},x_{bc},x_{hi},x_{hg},x_{ic},x_{ig},x_{cd},x_{cf},x_{gf},x_{df},x_{de},x_{fe}) \\
A^\intercal & = \bordermatrix{
   & a & b & c & d & e & f & g & h & i \cr
ab & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \cr
ah & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \cr
bh & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \cr
bc & 0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \cr
hi & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 \cr
hg & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 \cr
ic & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 \cr
ig & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 1 \cr
cd & 0 & 0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 \cr
cf & 0 & 0 & 1 & 0 & 0 & 1 & 0 & 0 & 0 \cr
gf & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 & 0 \cr
df & 0 & 0 & 0 & 1 & 0 & 1 & 0 & 0 & 0 \cr
de & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 0 & 0 \cr
fe & 0 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 0 \cr
} \\
\vec{b} & = \vec{1}
\end{align}

Note that $A$ is written in transpose, that was easier here.  $A$
actually has one column for each edge and one row for each vector,
though we're going to swap them and use it the way it's written in
just a minute.

Let's look at this in detail.  Every member of the vector $\vec{x}$
should be either 0 or 1, either we use the link or we don't.  Then the
objective function will end up being the sum of the costs of the links
that are in use, which are represented in $\vec{c}$.  We constrain
each node to having at least one link, which means that $\vec{x}$ has
to have a 1 in some entry corresponding to a 1 in each column of
$A^\intercal$.

Also, note that since you can't use half a link, we are insisting that
$\vec{x}$ (or $\vec{y}$) all be integers, but we haven't yet really
discussed integer problems.  Instead, what we will solve here is
called the \emph{linear relaxation} of the integer problem.

On the first iteration, we \emph{should} get the result
\begin{align}
\tvec{x} = (1,0,0,0,0,1,1,0,1,0,1,0,1,0).
\end{align}

That is, our set of links we add in the first iteration of Boruvka's
algorithm should be $\{ab, hg, ic, cd, gf, de \}$.

After this iteration, we now have several trees, called a forest:
\begin{align}
\{\{a, b\}, \{c, d, e, i\}, \{f, g, h\}\}.
\end{align}
Now we can rewrite the program looking for the cheapest connections
between each tree:
\begin{align}
  \operatorname{min} z(\vec{x}) = \tvec{c}\vec{x}
\end{align}
subject to
\begin{align}
A\vec{x} & \ge \vec{b} \\
\vec{x} & \ge 0, \vec{x} \textrm{  integer}
\end{align}
where
\begin{align}
\vec{c}^\intercal & = (8,11,8,7,6,4,14,10) \\
\vec{x}^\intercal & = (x_{ah},x_{bh},x_{bc},x_{hi},x_{ig},x_{cf},x_{df},x_{fe}) \\
A^\intercal & = \bordermatrix{
   & ab & cdei & fgh \cr
ah & 1 & 0 & 1 \cr
bh & 1 & 0 & 1 \cr
bc & 1 & 1 & 0 \cr
hi & 0 & 1 & 1 \cr
ig & 0 & 1 & 1 \cr
cf & 0 & 1 & 1 \cr
df & 0 & 1 & 1 \cr
fe & 0 & 1 & 1 \cr
}
\end{align}

\subsection{And its dual}

Our program has the dual
\begin{align}
  \operatorname{max} z'(\vec{y}) = \tvec{b}\vec{y}
\end{align}
subject to
\begin{align}
A^\intercal\vec{y} & \le \vec{c} \\
\vec{y} & \ge \vec{0}, \vec{y} \textrm{  integer.}
\end{align}




\section{Interlude: the Adjacency and Distance Matrices}

Note that the matrix $A$ above is related to but not the same as the
\emph{adjacency matrix} for a graph, which in a $v\times v$ square
matrix just denoting which nodes are connected to each other, also
generally denoted $A$ (for adjacency):

\begin{align}
A & = \bordermatrix{
  & a & b & c & d & e & f & g & h & i \cr
a & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \cr
b & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 0 \cr
c & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 0 & 1 \cr
d & 0 & 0 & 1 & 0 & 1 & 1 & 0 & 0 & 0 \cr
e & 0 & 0 & 0 & 1 & 0 & 1 & 0 & 0 & 0 \cr
f & 0 & 0 & 1 & 1 & 1 & 0 & 1 & 0 & 0 \cr
g & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 1 & 1 \cr
h & 1 & 1 & 0 & 0 & 0 & 0 & 1 & 0 & 1 \cr
i & 0 & 0 & 1 & 0 & 0 & 0 & 1 & 1 & 0 \cr
}
\end{align}

The distance matrix (sometimes denoted $M$) replaces those simple 1/0
values with the distance (cost):

\begin{align}
M & = \bordermatrix{
  & a & b & c & d & e & f & g & h & i \cr
a & 0 & 4 & 0 & 0 & 0 & 0 & 0 & 8 & 0 \cr
b & 4 & 0 & 8 & 0 & 0 & 0 & 0 & 11 & 0 \cr
c & 0 & 8 & 0 & 7 & 0 & 4 & 0 & 0 & 2 \cr
d & 0 & 0 & 7 & 0 & 9 & 14 & 0 & 0 & 0 \cr
e & 0 & 0 & 0 & 9 & 0 & 10 & 0 & 0 & 0 \cr
f & 0 & 0 & 4 & 14 & 10 & 0 & 2 & 0 & 0 \cr
g & 0 & 0 & 0 & 0 & 0 & 2 & 0 & 1 & 6 \cr
h & 8 & 11 & 0 & 0 & 0 & 0 & 1 & 0 & 7 \cr
i & 0 & 0 & 2 & 0 & 0 & 0 & 6 & 7 & 0 \cr
}
\end{align}

Note that $A = A^\intercal$ and $M = M^\intercal$, which is true for
undirected graphs but not directed ones.  In this class, we are
limiting ourselves entirely to undirected graphs.

These two matrices have many uses; you can determine, for example, how
closely two graphs resemble each other.

Matrix representations of graphs are used for e.g. the original Page
Rank algorithm that is the heart of Google's search.

\section{Homework}

See the separate file uploaded to SFS.

\end{document}
