\documentclass{article}
\usepackage{float}
\usepackage{graphicx}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\usepackage{relsize}
\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{que}{Que}




\begin{document}

%\lecture{**LECTURE-NUMBER**}{**DATE**}{**LECTURER**}{**SCRIBE**}
\lecture{12}{February 13}{Rohit Gurjar}{Prachi Singh}


\section{Bipartite Matching}
Bipartite matching is one of first problems 
that inspired application of linear programming and in particular, primal-dual
scheme to combinatorial optimization. 
%
In this lecture, we will apply primal-dual scheme to weighted bipartite matching.  
%
\begin{definition}[Bipartite Graph]
A Graph G is bipartite if the vertex set V can be partitioned into two sets A and B such that no edge in E has both endpoints in the same set of the bipartition.
\end{definition}

\begin{definition}[Matching]
A Matching M $\subseteq$ E is a set of edges such that every vertex V is incident to at most one edge of M. In Fig.\ref{fig:matching}, shaded edges form a matching. 

\begin{figure}[h]
    \centering
    \includegraphics[width=6cm, height=5cm]{images/matching.PNG}
    \caption{Example of Matching}
    \label{fig:matching}
\end{figure}

\end{definition}

\begin{definition}[Bipartite Matching]
A matching in Bipartite Graph is called Bipartite Matching.
\end{definition}
\textbf{Goal:} Find the maximum size matching i.e. Maximum cardinality matching problem.
\subsection{Augmenting Path Algorithm}
\begin{enumerate}
    \item Start with empty matching i.e., M $=\phi$.
    \item At any stage, find an augmenting path with respect to M. 
    \item Augment current matching.
\end{enumerate}
 
\begin{definition} [Augmenting Path]
An Augmenting path is a path that alternates between matching and non-matching edges, starting and ending with free vertices. In Fig.\ref{fig:augmentpath}, dotted edges do not belong to the matching, and solid edges belong to the matching.  
\begin{figure}[h]
    \centering
    \includegraphics[width=9cm, height=2cm]{images/scribe1.PNG}
    \caption{Example of Augmenting Path}
    \label{fig:augmentpath}
\end{figure}

\end{definition}
\begin{claim}
If a matching $M$ is not maximum, then there exists an augmenting path with respect to $M$.
\end{claim}
The proof of the claim was left as an exercise. 
%
One way to prove the claim is to consider the union of matching $M$ with some maximum size matching $M'$
and argue that it consists of a set of disjoint alternating paths and cycles. 
Once we have established that an augmenting path always exists, the next question is:

\textbf{Que.} How to find an augmenting path?
It is similar to finding an ordinary path from a source to a destination. 
To ensure that a path alternates between matching and non-matching edges one 
can direct all the matching edges from left to right and direct all the other edges from right to left. 
%Any BFS/DFS algorithm on this directed graph will give an alternating path. 
To get an augmenting path, we should find a directed path in this graph from any free vertex on the left
to a neighbor of any free vertex on the right. 
Any BFS/DFS algorithm is good enough for this. 
%Similar to BFS/DFS, by marking direction on the edges alternately. Edges pointing to the same direction forms an augmenting path.

\section{Miminum weight perfect matching}
The bipartite matching problem has various versions, some of which  have weights on the edges.
%
Such variants include finding maximum weight matching, maximum/minimum weight perfect matching etc. 
%\textbf{Goal:} Find maximum weight matching.
\begin{definition}[Perfect matching]
A matching is perfect if it covers all vertices. Fig.\ref{fig:pmatching} shows an example of perfect matching as all vertices are covered in the matching.
\begin{figure}[H]
    \centering
    \includegraphics[width=6cm, height=5cm]{images/pmatching.PNG}
    \caption{Example of Perfect Matching}
    \label{fig:pmatching}
\end{figure}
\end{definition}
These variants turn out to be equivalent. 
One can reduce the first two to minimum weight perfect matching as follows.
\begin{itemize}
    \item We can convert maximum weight matching problem to maximum weight perfect matching by converting the given graph into a complete graph by adding 0 weighted edges. As the weight of newly added edges is 0, the sum of weights will be the same as before. In Fig.\ref{fig:cgraph}, the dotted edges with weight 0 are added to the graph to make the Bipartite Graph Complete.  Moreover, if the both sides don't have equal number of vertices then one can add new vertices on the smaller side
    again with zero weighted edges. 
    \begin{figure}[H]
    \centering
    \includegraphics[width=7cm, height=6cm]{images/cgraph.PNG}
    \caption{Bipartite Graph to Complete Bipartite Graph by adding edges}
    \label{fig:cgraph}
    \end{figure}
    \item We can also convert the maximum weight perfect matching problem into minimum weight perfect matching by just multiplying the weights on the edges by -1. 
\end{itemize}
%\begin{claim}
If a bipartite graph is complete and balanced, then a perfect matching exists. 
%Also, the number of vertices on both sides should be the same.
%\end{claim}
Next, the plan is to solve this weighted version of matching using linear programming.
%
We will also need to use the augmenting path algorithm to find a maximum size matching as a subroutine.
%
In a sense, it will be a reduction from weighted to unweighted matching. 
%
Let us first see the LP formulation of minimum weight perfect matching. 

\subsection{Linear program for min weight perfect matching}
Let $\{w_e\}_{e\in E}$ be the given weights on the edges. 
%
As usual, we will have one variable for each edge, that is, $\{x_e\}_{e\in E} $. 
%
We can write the following LP relaxation for minimum weight perfect matching. 
%\[\{X_e\}_{e\in E} \ Given \  \{w_e\}_{e\in E}\] 
\begin{eqnarray*}
\min \sum_{e \in E} w_e x_e &&\text{s.t.} \\
0 \leq x_e \leq 1 && \text{ for } e \in E ,\\
\sum_{e\in \delta(v)}  x_e = 1 && \text{ for }  v \in V .
\end{eqnarray*}

%\[ \min \mathlarger{\sum}_{e \in E} w_e X_e  \]
%\[\  0 \leq X_e \leq 1\]
%\[\mathlarger{\sum_{e\in \delta(v)}} X_e = 1 , \ where\  v\in V \]\\
\textbf{Homework:} Argue that integral optimal value is equals to the fractional optimal value. In other words, 
there is always an integral optimal solution for this LP. And thus, it is a exact LP formulation for minimum 
weight bipartite matching. 

\paragraph{Dual LP.}
The following will be the dual linear program for the above LP. 
%\[\{y_v\}_{v\in V} \]
\begin{eqnarray*}
\max \sum_{u \in V} y_u &&\text{s.t.} \\
  y_u + y_v \leq w_e  && \text{ for }  e=(u,v) \in E .
\end{eqnarray*}

%\[Max \mathlarger{\sum}_{v \in V} y_v\]

%\[\forall e \in E, y_u + y_v \leq w_e\ , \ where\  e = (u,v) \]

\subsection{Primal Dual Schema}
For the above Primal and Dual LP the \textbf{Complementary Slackness Condition} is as follows:
\[ \text{ for each } e = (u,v) \in E, \text{ we have } x_e (w_e - y_u - y_v )=0  \]
In other words, $x_e$ can be nonzero only for tight edges, that is, those edges that satisfy $y_u +y_v = w_e$.
%
We can apply the Primal Dual Schema to the problem as follows:
\begin{enumerate}
    \item First we find some feasible dual solution. 
    This can be done by first taking the dual variables  for the left vertices to be zero 
    and then choosing the dual variables for right vertices according to the constraints. 
    To be specific, let $L,R$ be sets of left and right vertices respectively.
    Set $y_u = 0$ for $u \in L$ and for $v \in R$, 
    set  $y_v = \min\{w_e \mid e \text{ is incident on } v\}$.
    In Fig. \ref{fig:primaldual}, we have constructed a feasible dual solution by giving the vertices on the left value zero and assigned values to the vertices on the right appropriately. 
    \begin{figure}[H]
    \centering
    \includegraphics[width=10cm, height=5cm]{images/primaldual.PNG}
    \caption{Example of weighted graph with a dual feasible solution.}
    \label{fig:primaldual}
\end{figure}

    \item The next step is to try and find a Primal feasible solution that satisfies complementary slackness.
\textbf{Tight Edges:} which satisfy $w_e = y_u + y_v$.
    If dual constraints corresponding to $e$ is not tight, then $x_e$ must be $0$.
Let  $G'$ be a subgraph having only the tight edges. Now, try to find a perfect matching in $G'$. If we find one
then that will be a primal feasible solution satisfying complementary slackness.
\end{enumerate}
The rest of the primal-dual scheme will be covered in the next lecture.
\end{document}