% MODIFY THE FOLLOWING TO INCLUDE THE LECTURE #, TOPIC, DATE, and YOUR NAME
\lecturetitle{19}{VLSI 3 \& Pattern Matching 1}{5 Nov 97}{Noah Treuhaft}

% INCLUDE AN OUTLINE OF THE CLASS TOPICS
\begin{itemize} 
  \item Integer Programming For Global Routing
  \begin{itemize} 
    \item Concurrent Layout
    \item Hierarchical Layout
  \end{itemize}
  \item Detailed Routing (Channel Routing)
  \begin{itemize}
    \item Introduction
    \item Left Edge Algorithm (LEA)
    \item Greedy
  \end{itemize}
  \item Sequence Matching And Its Use In Computational Biology
  \begin{itemize}
    \item DNA
    \item Proteins
    \item Human Genome Project
    \item Sequence Alignment
  \end{itemize}
\end{itemize}

\section{Integer Programming For Global Routing}
\index{Routing with Integer Programming}

\subsection{Concurrent Layout}
Concurrent layout optimizes all nets together rather than adding one
net to the solution at a time.  The goal is to minimize total wire
length, and it can be met with an integer program.

Recall that a net is a set of terminals that must be all connected to
each other, and that a netlist is a set of nets that need to be
routed.  Suppose that the netlist consists of $n$ nets.  
Let $T_i =  \{T_{i1},T_{i2} \ldots T_{il_i}\}$ be all the Steiner
trees that connect net $i$ ($l_i$ is the number of such trees).
The following
integer program finds and optimal route for our nets.
\begin{displaymath}
\begin{array}{lll}
\mbox{minimize} & \sum_{i=1}^{n} \sum_{j=1}^{l_i} L(T_{ij}) \cdot x_{ij} & \\
\mbox{subject to} & \sum_{j=1}^{l_i} {x_{ij}} = 1 & i = 1,2\ldots,n \\
           & \sum_{i,j : e \in T_{ij}} x_{ij} \leq C(e) & e \in E \\
\mbox{where} & x_{ij} = \left \{ \begin{array}{ll} 
                           1 & \mbox{if $T_{ij}$ is used} \\
                           0 & \mbox{otherwise}
                          \end{array} \right.  & \\
      & L(T_{ij}) = \mbox{total length of tree $T_{ij}$} & \\
      & C(e) = \mbox{capacity restriction of edge $e$} & \\
      & E = \mbox{set of all edges} &
\end{array}
\end{displaymath}
It minimizes the total length of all included Steiner trees across all
nets.  The first constraint ensures that only one tree per net is
included while the second ensures that the solution does not exceed
the capacity of any edge.
Although this is a nice concise description of the problem, it
is infeasible to solve for any reasonably sized circuit.
To make the problem more feasible, a hierarchical application
of the approach is used.

\subsection{Hierarchical Layout}

In hierarchical layout, a floorplan is preprocessed by partitioning it
into a hierarchy of sub-blocks.  At each node of the resulting tree,
the sub-blocks can then be routed with a modified version of the
concurrent routing program.  The modification involves replacing the
first constraint with
\begin{displaymath}
\begin{array}{lll}
 & \sum_{j=1}^{l_i} x_{ij} = n_{i} & i = 1,2\ldots,n
\end{array}
\end{displaymath}
where $n_i$ is the number of nets that connect the same set of blocks.
(In partitioning the floorplan, we create equivalence classes of nets.
Since the algorithm actually routes these equivalence classes, the
$n_i$ account for the fact that they may contain more than one net.)
The modified program is solved at each node in the tree in top-down
order.  

%Here is an example of a floorplan and its preprocessed cut-tree.

% \centerline{\psfig{file=../lecture19/hierarchical.eps,width=0.75\textwidth}}

The number of variables in both the concurrent and hierarchical
programs can be reduced using various techniques; see chapter 6 of N.\
Sherwani, {\it Algorithms for VLSI Physical Design Automation},
Kluwer, 1995.

\section{Detailed Routing (Channel Routing)}

\subsection{Introduction}

A channel is the space between two standard-cell blocks, and is used
for routing wires between the terminals of those and other blocks.
This type of routing is known as channel routing.  For channel
routing, we know where wires enter the channel (at the terminals of
the blocks that bound the channel).  The goal is to optimize the
routing of wires within the channel to allow the best compaction of
blocks afterward.  Figure~\ref{fig:channelroute} 
describes some terminology for channel
routing.

\begin{figure}
\centerline{\psfig{file=../lecture19/defs.ps}}
\caption{Channel routing definitions.}
\label{fig:channelroute}
\end{figure}
Switchboxes are formed by the intersection of two channels.  Routing
algorithms for switchboxes are slightly different from those for
channels, but they have the same flavor.

Channel routing can be grid-based or gridless.  Grid-based routing
requires that wires fit on a regular grid.  Gridless routing is more
flexible in its wire placement.  This flexibility makes it useful for
routing wires of different thicknesses, which arise when the wires
must carry different currents.

Semiconductor technology usually provides multiple wiring layers, and
channel routing algorithms must be able to make use of these layers.
Two types of model exist for the use of multiple layers: reserved and
unreserved.  Reserved layer-models restrict all wires within a given
layer to running in a single orientation (either horizontally or
vertically), and are commonly used for routing programmable logic
arrays (PLA's).  An unreserved layer-model, in which wires can be
routed both horizontally and vertically within the same layer, is more
flexible.

There are four popular two-layer routing algorithms.
\begin{itemize}
  \item Left-edge algorithm (LEA) (Hashimoto and Stevens 1971)
  \item Constraint graph (1982)
  \item Greedy (Rivest Fiduccia1982)
  \item Hierarchical (1983)
\end{itemize}
LEA and Greedy are discussed below.

\subsection{Left Edge Algorithm (LEA)}
\index{Detailed Routing: Left Edge Algorithm}

The three steps of LEA are as follows.
\begin{enumerate}
  \item Determine the interval of each net.  The interval of a net is
  simply the region bounded by its leftmost and rightmost
  terminals. (${\rm O}(n)$)
  
  \item Sort these intervals by their leftmost points. (${\rm O}(n\log
  n)$)

  \item For each interval, find the first free track and place the
  interval on that track.  Information about currently-occupied tracks
  can be maintained in a balanced tree so that inserting, deleting,
  and finding the minimum take logarithmic time.
\end{enumerate}

This algorithm effectively does plane-sweeping, which appears in
computational geometry.  In plane-sweeping, elements are sorted in one
of two dimensions, and then swept through in the other.  
Figure~\ref{fig:lea} shows an example.  

\begin{figure}
\centerline{\psfig{file=../lecture19/left-edge.eps,width=0.75\textwidth}}
\caption[]{Example of the LEA channel routing algorithm.
The left half show the intervals that are
routed in the right half.}
\label{fig:lea}
\end{figure}

Simple LEA has two limitations.
\begin{itemize}
  \item Each net must be routed on a single track.  This limits the
  quality of the resultant routes.

  \item It cannot account for vertical constraints.  This makes some
  nets impossible to route.
\end{itemize}
Various extensions (such as allowing doglegs) solve these problems.

\subsection{Greedy}
\index{Detailed Routing: Greedy Algorithm}

Here is the greedy channel router algorithm.  For each column $i$ in
order:
\begin{enumerate}
  \item Connect the terminals at column $i$ either to the tracks
  containing their nets or to the first empty tracks.  Note that
  connecting both terminals to tracks containing their nets might not
  be possible, in which case one of the tracks must be split.
  Splitting a track involves simply using two tracks (and thus two
  parallel wires) for some part of a single net.

  \item Join any tracks that were split during the previous iteration
  (i.e., that were split when processing the previous column).

  \item If any split tracks could not be joined in the previous step,
  reduce the distance between those tracks.

  \item Move each net toward the boundary on which its next terminal
  lies.
\end{enumerate}
Figure~\ref{fig:greedy} shows an example of a greedily-routed channel.

\begin{figure}
\centerline{\psfig{file=../lecture19/greedy.eps,width=0.75\textwidth}}
\caption[]{Example of the greedy channel router.}
\label{fig:greedy}
\end{figure}

\section{Sequence Matching And Its Use In Computational Biology}

\subsection{DNA}

DNA is a sequence of base-pairs (bps) of the four nucleotide
bases---Adenosine, Cytosine, Thymine, and Guanine (or a, c, t, and g).
A human genome consists of DNA: approximately $3 \cdot 10^9$ bps
divided into 46 chromosomes, each with between $5 \cdot 10^7$ and $25
\cdot 10^7$ bps.  Each chromosome---because it is DNA---is a sequence
of bps, and is used to generate proteins: \[ \mbox{DNA} \stackrel{\rm
transcription}{\longrightarrow} \mbox{mRNA} \stackrel{\rm
translation}{\longrightarrow} \mbox{Protein}
\]

\subsection{Proteins}

Proteins comprise 20 different amino acids (gly, trp, cys, \ldots).
Each bp triple in DNA codes one of these amino acids.  Since there are
64 possible triples, this is a many-to-one mapping.  (Four of triples
serve to mark the beginnings and ends of proteins rather than coding
amino acids).  The structure of a protein, as determined by its amino
acids, controls how it folds, which in turn determines its function.
Protein folding---and therefore function---can be computed as an
N-body problem.

Goals in molecular biology are
\begin{enumerate}
  \item to extract genome sequences for various organisms,

  \item to determine the structure and purpose of the proteins coded by
  these sequences, and

  \item to use that knowledge to study and cure genetic diseases, design
  new drugs, and study evolution.
\end{enumerate}

\subsection{Human Genome Project}

The goal of the human genome project is to generate a map of each
human chromosome.  The basic approach is as follows.

\begin{enumerate}
  \item Divide chromosomes using restriction enzymes, which function
  as microscopic scalpels.  These enzymes break chromosomal DNA
  between different bps.

  \item Clone the DNA fragments using host cells (usually bacteria).

  \item Find an exact map of a portion of the fragments (e.g., the
  first and last 600 bps).  This can be done with a divide-and-conquer
  technique.

  \item Use sequence alignment to determine how the mapped fragments
  fit together.

  \item Find an exact map of the desired subset of the fragments.
\end{enumerate}

\subsection{Sequence Alignment}

Sequence alignment answers this question: ``How similar are two bp
sequences?''  It tries to find the closest match, allowing for
mutations (${\rm X} \rightarrow {\rm Y}$), insertions (${\rm \_}
\rightarrow {\rm Y}$), and deletions (${\rm X} \rightarrow {\rm \_}$),
but minimizing the number of these differences.  For example, 
\begin{verbatim}
acta_gtc__tac
 | | |||  ||
_cgacgtcgata_
\end{verbatim}
contains one mutation, three insertions, and two deletions.
Notice that mutations can be modeled as an insertion-deletion pair
(${\rm \_X} \rightarrow {\rm Y\_}$).  Insertions and deletions are
know collectively as indels.  

There are three types of sequence alignment.
\begin{description}
  \item[Global] Aligns two sequences A and B, like the {\tt diff} utility.

  \item[Local] Aligns A with any part of B (i.e., finds the best match
  or matches for A within B), like the {\tt agrep} utility.

  \item[Multiple] Finds matches among $n$
  sequences ({\em i.e.}, align them all up together).
\end{description}
For both global and local alignment, we may want to find the $n$ best
matches rather than the single best match.

Multiple alignment problems typically are NP-hard, so approximations
are used.
