\documentclass[11pt]{article}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{graphicx}
\usepackage{epstopdf}

\DeclareMathOperator*{\E}{\mathbb{E}}
\let\Pr\relax
\DeclareMathOperator*{\Pr}{\mathbb{P}}

\newcommand{\eps}{\epsilon}
\newcommand{\inprod}[1]{\left\langle #1 \right\rangle}
\newcommand{\R}{\mathbb{R}}

\newcommand{\handout}[5]{
	\noindent
	\begin{center} 
		\framebox{
			\vbox{
				\hbox to 5.78in { {\bf CS 388R: Randomized Algorithms } \hfill #2 }
				\vspace{4mm}
				\hbox to 5.78in { {\Large \hfill #5  \hfill} }
				\vspace{2mm}
				\hbox to 5.78in { {\em #3 \hfill #4} }
			}
		}
	\end{center}
	\vspace*{4mm}
}

\newcommand{\lecture}[4]{\handout{#1}{#2}{#3}{Scribe: #4}{Lecture #1}}

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

\newcommand{\argmin}{\operatornamewithlimits{argmin}}

% 1-inch margins, from fullpage.sty by H.Partl, Version 2, Dec. 15, 1988.
\topmargin 0pt
\advance \topmargin by -\headheight
\advance \topmargin by -\headsep
\textheight 8.9in
\oddsidemargin 0pt
\evensidemargin \oddsidemargin
\marginparwidth 0.5in
\textwidth 6.5in

\parindent 0in
\parskip 1.5ex
\begin{document}
	
	\lecture{16 --- Nov. 2, 2015}{Fall 2015}{Prof.\ Eric Price}{Jiong Zhang, Chao-Yuan Wu}
	
	\section{Overview}
	In the last lecture we studied bipartite matching problem. 
	In this lecture we extend our analysis to online setting.
	
	\section{Introduction}
	In the original bipartite matching problem we seek to find a maximum matching, 
	i.e. a matching that contains the largest possible number of edges given a graph. 
	On the other hand, in a ``online" bipartite matching problem, we observe nodes one by one 
	and assign matchings in an online fashion.  
	Our goal is to find an algorithm that maximizes the competitive ratio $R(A)$.
    \begin{definition}
        (Competitive ratio)
        \begin{align}
        R(A) := \liminf_{I}\frac{\E[\mu_A(I)]}{\mu_*(I)}
        \end{align}
        where $\mu_A(I)$ and $\mu_A(I)$ denote the size of matching for an algorithm $A$ 
        and maximum matching size respectively, given input $I := $ \{graph, arriving order\}.  
    \end{definition}
Obviously $R(A) \leq 1$, but can we find a lower bound for $R(A)$?

\section{Naive algorithm}
Since each edge can block at most two edges, we have $R(A) \geq 0.5$. 
On the other hand, for any deterministic algorithm $A$, 
we can easily find an adversarial input $I$ such that $R(A) \leq 0.5$. 
See left hand side of Figure \ref{fig:example} for example. 

Can we achieve better results with random assignments? 
Consider the graph on the right hand side of Figure \ref{fig:example}, 
where there is a perfect matching from $n$ nodes on the left to $n$ nodes on right, 
and the second haft of $u$s are fully connected to the first half of $v$. 
Under this setting, the number of correctly matched vertices in the second half of $v$ is at most $n/2$. The expected number of correctly matched vertices in the first half is given by:   
\begin{align}
\E[\text{\# correctly matched vertices}] &= \sum_{i=1}^{n/2} \Pr[\text{$i$-th vertex is correctly matched}]\\
&\leq\sum_{i=1}^{n/2} \frac{1}{\frac{n}{2}-i+2}\\
&\leq \log(\frac{n}{2}+1)\\
\end{align}
Since $\mu_{*}=n$, the competitive ratio $R$:
\[R(A) = \frac{\E[\text{\# matched}]}{n} \leq \frac{\frac{n}{2}+log(\frac{n}{2}+1)}{n}\rightarrow\frac{1}{2}\]

We see, unfortunately, this randomized algorithm still does not do better than $1/2$. 

\begin{figure}[!t]
	\centering
	\includegraphics[width=0.5\linewidth]{greedyandrandom.jpg}
	\caption{comparison of deterministic and randomized algorithms}\label{fig:example}
\end{figure}

\section{Ranking algorithm}
Here we introduce Ranking Algorithm. Consider a graph $G$ with arriving order $\pi$. Instead of simply choosing a random edge, 
we first randomly permute the $v$'s with permutation $\sigma(\cdot)$. 
We then match $u$ to 
\[v := \argmin_{v' \in \mathcal{N}(u)} \sigma(v')\]
where $\mathcal{N}(u)$ denotes the neighbors of $u$. 

Now we prove that this algorithm achieves a competitive ratio of $1 - 1/e$. 
We begin by defining our notation. The matching is denoted by $\mathrm{Matching}(G,\pi,\sigma)$.
$M^*(v)$ denotes the vertex matched to $v$ in perfect matching. 
$G:=\{U,V,E\}$, where $U, V, E$ denote left nodes, right nodes and edges respectively. 


\begin{lemma}
	Let $H:=G-\{x\}$ with permutation $\pi_H$ and arriving order $\sigma_H$ induced by 
	$\pi, \sigma$ respectively. 
	$\mathrm{Matching}(H, \pi_H, \sigma_H) = \mathrm{Matching}(G, \pi,\sigma)$
	+ augmenting path from $x$ downwards. \\
	\label{lemma:1}
\end{lemma}
This can be easily seen from the design of the algorithm. 

\begin{lemma}
    Let $u\in U$ and $M^*(u) = v$, if $v$ is not matched under $\sigma$, then $u$ is matched to $v'$ 
    with $\sigma(v') \leq \sigma(v)$.\\
    \label{lemma:2}
\end{lemma}
This again is obvious. 

\begin{lemma}
	Let $x_t$ be the probability that the rank-$t$ vertex is matched. Then
	\begin{align}
    	1-x_t \leq \frac{\sum_{s\leq t}x_s}{n}\\
    	\end{align}
	\label{lemma:3}
\end{lemma}
\begin{proof}  (Intuitive but incorrect)
Let $v$ be the vertex with $\sigma(v) = t$. Note, since $\sigma$ is uniformly random, 
$v$ is uniformly random. 
Let $u := M^*(v)$. Denote by $R_{t}$ the set of left nodes that are matched to 
rank $1, 2, \dots, t$ vertices on the right. We have $\E[\,|R_{t-1}|\,] = \sum_{s \leq t - 1} x_s$. 
If $v$ is not matched, $u$ is matched to some $\tilde{v}$ such that $\sigma(\tilde{v}) < \sigma(v) = t$, 
or equivalently, $u \in R_{t - 1}$. That said, 
\[\Pr(\text{$v$ not matched}) = 1 - x_t = \Pr(u \in R_{t-1}) = \Pr(\frac{\E\left[|R_{t-1}|\right]}{n})
\leq \frac{\sum_{s\leq t}x_s}{n}\]
\end{proof}
However this proof is not correct since $u$ and $R_{t-1}$ are not independent and thus
$\Pr(u \in R_{t-1}) \neq \Pr(\frac{\E\left[|R_{t-1}|\right]}{n})$. 
Instead, we use the following lemma to complete the correct proof. 
\begin{lemma}
Given $\sigma$, let $\sigma^{(i)}$ be the permutation that is $\sigma$ with $v$ 
moved to the $i$-th rank. Let $u := M^*(v)$. 
If $v$ is not matched by $\sigma$, for every $i$, $u$ is matched by $\sigma^{(i)}$ to some 
$\tilde{v}$ such that $\sigma^{(i)}(\tilde{v}) \leq t$. 
\label{lemma:4}
\end{lemma}

\begin{proof}
By Lemma \ref{lemma:1}, inserting $v$ to $i$-th rank causes any change to be a move up. 
\[\sigma^{(i)}(\tilde{v}) \leq \sigma(\tilde{v}) + 1 \leq t\]
\end{proof}

\begin{proof} (Correct proof of Lemma \ref{lemma:3})
%Given $\sigma$, let $\sigma^{(i)}$ be the permutation that is $\sigma$ with $v$ 
%moved to the $i$-th rank, where $v$ is picked uniformly at random. Let $u := M^*(v)$. 
%If $v$ is not matched by $\sigma$ (with probability $1 - x_t$), then $u$ is matched by $\sigma'$ 
%to some $\tilde{v}$ such that $\sigma(\tilde{v}) \leq t$, or equivalently $u \in R_{t}$. 

Choose random $\sigma$ and $v$, let $\sigma' = \sigma$ with $v$ moved to rank $t$. 
$u := M^*(v)$. According to Lemma \ref{lemma:4}, if $v$ is not matched by $\sigma$ 
(with probability $x_t$), $u$ in $\sigma'$ is matched to $\tilde{v}$ with $\sigma'(\tilde{v})\leq t$, 
or equivalently $u \in R_t$. 
Note, $u$ and $R_t$ are now independent and $\Pr(u \in R_t) = |R_t| / n$ holds. 
The same arguments as in the previous proof complete the proof. 
\end{proof}

With Lemma \ref{lemma:3}, we can finally obtain the final results. 
Let $s_t := \sum_{s\leq t}x_s$. Lemma \ref{lemma:3} is equivalent to 
$s_t(1 + 1/n)\geq 1 + s_{t-1}$. Solving the recursion, it can also be rewritten as 
$s_t = \sum_{s \leq t}(1 - 1/(1+n))^s$ for all $t$. 
The competitive ratio is thus, $s_n / n \rightarrow 1 - 1/e$. 


\begin{thebibliography}{42}
 \bibitem[MR]{MR}
 Rajeev~Motwani, Prabhakar~Raghavan
 \newblock Randomized Algorithms.
 \newblock {\em Cambridge University Press}, 0-521-47465-5, 1995. %pub - isbn - year
\end{thebibliography}

\end{document}
