\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{subfig}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsmath,amsthm}
\usepackage{graphicx}
\usepackage[margin=1in]{geometry}

\newcounter{lecnum}

\newcommand{\lecture}[4]{
   \newpage
   \setcounter{lecnum}{#1}
   \noindent

   \begin{center}
   \framebox{
      \vbox{\vspace{2mm}
    \hbox to 16cm { {\bf CS602 Applied Algorithms
                        \hfill 2019-20 Sem II} }
       \vspace{4mm}
       \hbox to 16cm { {\Large \hfill Lecture #1: #2  \hfill} }
       \vspace{2mm}
       \hbox to 16cm { {\it Scribe: #4  \hfill  Lecturer: #3} }
      \vspace{2mm}}
   }
   \end{center}
   \vspace*{4mm}
}

\newtheorem{theorem}{Theorem}[lecnum]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{observation}[theorem]{Observation}

\DeclareMathOperator{\IN}{IN}
\DeclareMathOperator{\out}{OUT}

\begin{document}

%\lecture{**LECTURE-NUMBER**}{**DATE**}{**LECTURER**}{**SCRIBE**}
\lecture{9}{February 4}{Rohit Gurjar}{Parashiv Sihaniya}


%\section{XYZ}
Shortest path in a directed graph (with non-negative weights)

%INSERT GRAPH HERE
\begin{figure}[h]
  \centering
  \includegraphics[scale=0.4]{graph1}
  \caption{A directed graph}
  \label{fig:graph1}
\end{figure}
% Edges
\begin{align*}
& E = \text{ Set of Edges, } |E| = m\\
& \text{Path } P = \text{ Subset of }E\\
& x_1, x_2, \ldots x_m \in \{0,1\} \text{ represents arbitrary subset of edges}\\
& x_i = \begin{cases} 0 & i\mbox{-th edge NOT in the subset} \\
    1 & i\mbox{-th edge in the subset} \end{cases}\\
\end{align*}
We can write the following integer program for the shortest path proplem. Let $w_e$ be the weight of edge $e$ for each $e \in E$.
%We have the following LP:
\begin{eqnarray*}
  \text{minimize} \quad \sum_{e=1}^{m} w_{e}x_{e} & \text{s.t.}& \\
  \text{Conditions for $x$ to represent a path ($s \to t$): }&& \\
  x_e & \in & \{0,1\} \\
   \sum_{e \in \out(s)}x_{e} &=& 1, \\
    \sum_{e \in \IN(t)}x_{e} &=& 1, \\
 \sum_{e \in \IN(u)}x_{e} = \sum_{e \in \out(u)}x_{e} &\leq& 1, \text{ for } u \notin s,t \\
\end{eqnarray*}
\begin{observation}
Any 0-1 solution which minimizes this must be an ($s \to t$) path. The optimal 0-1 solution gives us a minimum weight path.
\end{observation}
%
%
Note that since it is a minimization program, the last inequality is redundant, and thus, can be ignored. 
%
We can write the following \underline{LP relaxation for the above integer program:}
\begin{eqnarray*}
  \text{minimize} \sum_{e \in E} w_{e}x_{e} &\text{s.t.}& \\
 \sum_{e \in \IN(u)}x_{e} & = &\sum_{e \in \out(u)}x_{e}, \text{ for } u \notin s,t \\
 0 & \leq& x_e \\
 \sum_{e \in \out(s)}x_{e} &=& 1, \\
 \sum_{e \in \IN(t)}x_{e} &=& 1 \\
\end{eqnarray*}
%
There can be non-integral solutions for this LP. For example, see Figure~\ref{fig:graph2}.
Interestingly, we can show that there is always an integral optimal solution, and thus,
the LP gives us the correct shortest path length.  

% GRAPH HERE
\begin{figure}[h]
  \centering
  \includegraphics[scale=0.6]{graph2}
  \caption{A feasible solution}
  \label{fig:graph2}
\end{figure}

\begin{theorem}
There is always an integral optimal solution.
\end{theorem}
\begin{claim}
\label{cla:integral}
If there is a non-integral feasible solution with weight $w$ then there is also an integral solution with weight at most $w$.
\end{claim}

\begin{figure}[h]
\centering
\begin{minipage}{.5\textwidth}
  \centering
  \includegraphics[width=0.8\linewidth]{graph2}
  %\captionof{figure}{caption}
  \label{fig:scene}
\end{minipage}%
\begin{minipage}{.5\textwidth}
  \centering
  \includegraphics[width=0.9\linewidth]{graph3}
  \label{fig:waterfall}
\end{minipage}
\caption{The left figure shows a fractional feasible solution.
% that is a convex combination of two paths. 
The integral solution corresponding to one of the two paths (the right figure) must have  a smaller or same weight value.}
\end{figure}
%
\textbf{Proof of Claim~\ref{cla:integral}:}
%INSERT GRAPH HERE
\begin{enumerate}
    \item If $x_e$ is non-integral for an edge $e$, then some neighbouring edge must be also non-integral. This is because the LP
    constraints say that the  difference of the outgoing and incoming edges is integral. 
    \item This way we can get a cycle of non-integral edges (ignoring directions).
    \item Now, one can add or subtract a number $\epsilon$ to the cycle edges so that the 
    difference of the outgoing and incoming sums remains unchanged (see Figure~\ref{fig:cycles}).
    \item Choose $\epsilon$ so that at least one edge variable becomes integral.
\end{enumerate}
\newpage
\begin{figure}[h]
  \centering
  \includegraphics[scale=0.6]{cyc1}
  %\caption{Feasible}
  \label{fig:cyc1}
\end{figure}
%Choose $\epsilon$ such that at least one variable becomes integral 
% Note that $sign(\Delta w) = -sign(\Delta w')$\\
There are two possible ways of changing the values. 
The total change in the value of the solution is given by $\Delta w$ and $\Delta w'$, respectively.
$$\Delta w = (-w_1 + w_2 - w_3 + w_4 + w_5 - w_6)\times 0.1 $$
$$\Delta w' = (+w_1 - w_2 + w_3 - w_4 - w_5 + w_6)\times \epsilon $$

%%%
\begin{figure}[h]
\centering
\begin{minipage}{.5\textwidth}
  \centering
  \includegraphics[width=0.8\linewidth]{cyc2}
  %\captionof{figure}{caption}
\end{minipage}%
\begin{minipage}{.5\textwidth}
  \centering
  \includegraphics[width=0.9\linewidth]{cyc3}
  \label{fig:cyc3}
\end{minipage}
\caption{Two ways to alter the edge values, so that the vertex constraints remain satisfied.}
  \label{fig:cycles}
\end{figure}
%%%%%%%
Note that $sign(\Delta w) = -sign(\Delta w')$.
 Since $\Delta w \text{ and } \Delta w'$ have opposite signs, we can choose the
direction which decreases the function value (or keeps it the same). This
way we get a new feasible solution with at least one more integral
coordinate. Keep repeating this procedure till all coordinates become
integral. In the end, we will have an integral feasible solution that has a
better (or same) function value as the starting solution.\\
\begin{theorem}
This LP is correct for shortest paths. In general, LP can have a fractional optimal which is strictly better than integral optimal.\\
\end{theorem}
\textbf{Dual LP}
\begin{itemize}
    \item Variables - Constraints in LP
    \item For every primal constraint $\to$ Dual Variable
        \item Don't need non-negative constraints on dual variables, since we have equalities in the primal.
    \item For every primal variable $\to$ Dual constraint
    \item $\therefore$ One constraint for every edge
\end{itemize}
\begin{eqnarray*}
\max  \; y_t -y_s & \text{s.t.}&\\
 y_v - y_u &\leq& w_e \text{ for each } e=(u,v) \in E.\\
\end{eqnarray*}
Think of an embedding of vertices on the real line and $y_u$ as the real coordinate of vertex $u$.
%
The objective is to maximize the distance between the source and the destination, 
while each vertex pair distance should be upper bounded by the corresponding edge weight. 
%
Dijkstra's algorithm essentially solves this LP. 
%
You can also think of this as follows: say for every edge $e=(u,v)$, the two endpoints
$u$ and $v$ are tied by a thread of length $w_e$ and you are trying to pull $s$ and $t$
as far apart as possible. 
%
This will basically tighten all the threads corresponding to edges that lie on a shortest path and
the distance between $s$ and $t$ will be the shortest $(s,t)$-distance in the graph.


\end{document}