\chapter{Max-sum Problem}\label{chapter1}

This chapter defines the binary max-sum problem and presents the basic terms that are related to it followed by the description of algorithms solving it -- this first section is primarily based on \cite{4204160} and \cite{research_report}, which summarize the previous work based on \cite{schlesinger1976syntactic}. The term max-sum problem is also known as Weighted CSP or Valued CSP and it is used so e.g. in \cite{cooper2010soft}.

%\subsection{Problem definition}

\begin{definition}
The {\em binary max-sum labelling problem} is defined by a tuple $(G, X, \bm{g})$, where
\begin{enumerate}
	\setlength\itemsep{0.1em}
  \item[$\bullet$] $G = (T, E)$ is an undirected graph with {\em objects} $T$ and {\em object pairs}\footnote{The terms \textit{node} and \textit{edge} are reserved for different concepts, therefore the constituents of the graph $G$ are called differently to avoid ambiguity.} $E \subseteq  {T \choose 2}$,
  \item[$\bullet$] $X$ is a finite set of {\em labels},
  \item[$\bullet$] $\bm{g}$ is a vector consisting of elements $g_t(x) \in \mathbb{R}_{ - \infty }$ for each $t \in T$ and $x \in X$ and elements $g_{t,t'}(x,x') \in \mathbb{R}_{ - \infty }$ for each pair $\{t,t'\} \in E$ and labels $x,x' \in X$. For all pairs, it holds that $g_{t,t'}(x,x') = g_{t',t}(x',x)$.
\end{enumerate}
\end{definition}

The task of a max-sum labelling problem is to assign each object $t \in T$ a label $x_t \in X$ while maximizing the criterion function

\begin{equation}
F(\bm{x}| \bm{g}) =  \sum_{t \in T}{g_t(x_t)} + \sum_{ \{ t,t' \} \in E}{g_{t,t'}(x_t,x_{t'})}
\end{equation}
whose value is called the {\em quality of a labelling} $\bm{x} \in X^{T}$. In other words, we want to maximize

\begin{equation}\label{maximization_equation_25}
\max_{\bm{x} \in X^{T}} F(\bm{x}| \bm{g}).
\end{equation}

\begin{definition} \label{detailed_graph}
This setting allows us to define another undirected graph $H = (T \times X,E_X)$, where $E_X = \left\lbrace \left\lbrace (t,x),(t',x')  \right\rbrace \mid \{t, t'\} \in E, x,x' \in X\, \right\rbrace$. The elements of $T \times X$ will be called {\em nodes} and the elements of $E_X$ {\em edges}.
\end{definition}

\begin{definition}
For a pair of objects $t, t' \in T$ such that $\{t, t'\} \in E$ and a label $x \in X$, the {\em pencil} $(t,t',x)$ is defined as the set of edges that connect the node $(t,x)$ with nodes $(t',x')$, where $x' \in X$, i.e.

\begin{equation}
P(t,t',x) = \{ \{(t,x), (t',x')\} \mid x' \in X \, \}.
\end{equation}
\end{definition}

Using the constituents of graph $H$, we can observe that the length of the vector $\bm{g}$ equals $|I|$, where $I =  (T \times X) \cup E_X$, i.e. the vector has $\abs{E} \cdot \abs{X}^2 + \abs{T} \cdot \abs{X}$ components.

\begin{figure}
\centering
\begin{tikzpicture}
\begin{scope}[every node/.style={circle,thick,draw}]
    \node (B1) at (0,0) {1};
    \node (A1) at (0,2) {4};
    \node (B2) at (4,0) {2};
    \node (A2) at (4,2) {2};

    \node (B3) at (8,0) {3};
    \node (A3) at (8,2) {2};
\end{scope}

\foreach \x in {0,4,8}
\draw [shift={(\x,0)}] (-0.5,-0.5) -- (0.5,-0.5) -- (0.5,2.5) -- (-0.5,2.5) -- cycle;

    \node at (0,3) {object 1};
    \node at (4,3) {object 2};
    \node at (8,3) {object 3};
    \node[anchor=east] at (-0.7,2) {label $A$:};
    \node[anchor=east] at (-0.7,0) {label $B$:};
    

\begin{scope}[>={Stealth[black]},
              every node/.style={fill=white,circle},
              every edge/.style={draw=red,very thick}]
    \path [-] (A1)[bend left=15] edge node {$5$} (B2);
    \path [-] (A1) edge node {$3$} (A2);
    \path [-] (B1) edge node {$4$} (B2);
    \path [-] (B1)[bend right=15] edge node {$3$} (A2);
    
    \path [-] (A2)[bend left=15] edge node {$-1$} (B3);
    \path [-] (A2) edge node {$0$} (A3);
    \path [-] (B2) edge node {$8$} (B3);
    \path [-] (B2)[bend right=15] edge node {$5$} (A3);
\end{scope}
\end{tikzpicture}
\caption{Example of a binary max-sum problem.}
\label{binarymaxsum_example}
\end{figure}

\begin{example}
In the Figure \ref{binarymaxsum_example}, there is a small instance of a binary max-sum problem with $X = \{A, B\}$, $T = \{1, 2, 3\}$ and $E = \{\{1,2\}, \{2,3\}\}$. The values of the $\bm{g}$ vector are written in the figure, for example $g_1(A) = 4$, $g_{2,3}(A,B) = -1$. The quality of labelling $\bm{x} = (B, B, A)$ equals
\begin{equation}
g_1(B) + g_2(B) + g_3(A) + g_{1,2}(B,B) + g_{2,3}(B,A) = 14.
\end{equation}
\exampleEnd
\end{example}

\section{Linear Programming Relaxation}

The above maximization problem \ref{maximization_equation_25} can be formulated as an ILP whose variables are values $\mu_t(x)$ and $\mu_{t,t'}(x,x')$ that are binary. It is a straightforward idea to relax this condition and create an LP with the same variables that create a {\em fractional labelling}.

\begin{definition}
The conditions for vector  $\bm{\mu} $, which consists of variables $\mu_t(x)$ and $\mu_{t,t'}(x,x')$, to be a {\em fractional labelling} are


\begin{subequations}\label{partiallydecided}
\begin{align}
  \sum_{x'} {\mu_{t,t'}(x,x')} & = \mu_{t}(x), & \quad \forall \{t,t' \} \in E, \; \forall  x \in X \\
  \sum_x {\mu_t(x)} & = 1, \; & \forall t \in T \\
  \bm{\mu} & \geq \bm{0},
\end{align}
\end{subequations}
where ${\mu_{t,t'}(x,x')} = {\mu_{t',t}(x',x)}$. The set of all $\bm{\mu}$ satisfying these conditions will be denoted as $\Lambda_{G,X}$.
\end{definition}

If the vector $\bm{\mu}$ contains only values 0 or 1, then it is a "decided" labelling because there is a corresponding labelling where $x_t = x$ holds if and only if $\mu_t(x) = 1$. It can be easily seen that the $\mu_{t,t'}(x,x')$ values are also binary in this case.

The {\em relaxed max-sum problem} is the linear program

\begin{equation} \label{primal}
\max_{\bm{\mu} \in \Lambda_{G,X}} \left[ \sum_{\substack{t \in T \\ x \in X}}{  g_t(x) \, \mu_t(x)} + \sum_{\substack{ \{ t,t' \} \in E \\ x,x' \in X}}{g_{t,t'}(x_t,x_{t'}) \, \mu_{t,t'}(x_t,x_{t'}) } \right],
\end{equation}
where the objective function is in fact the scalar product of vectors $\bm{\mu}$ and $\bm{g}$, therefore it can be rewritten into a simpler form
\begin{equation} \label{primal2}
\max_{\bm{\mu} \in \Lambda_{G,X}} \bm{g}^T \bm{\mu} .
\end{equation}

\section{Equivalent Max-sum Problems}

\begin{definition}
Two max-sum problems $(G,X,\bm{g})$ and $(G,X,\bm{g'})$ are called { \em equivalent} (denoted as $\bm{g} \sim  \bm{g'}$) if the corresponding quality functions are identical, that is
\begin{equation}
F(\bm{x}| \bm{g}) = F(\bm{x}| \bm{g'}), \hspace{5mm} \forall  \bm{x} \in X^{T}.
\end{equation}
\end{definition}

Observe that if we assign a value $\varphi_{t,t'}(x)$ to each pencil $(t,t',x)$ of a given binary max-sum problem $(G,X,\bm{g})$ and create a new vector $\bm{g^\varphi}$ in the following way:
\begin{subequations}
\label{phiequivalent}
\begin{align}
g_t^{\bm{\varphi}}(x) & = g_t(x) + \sum_{\{t,t'\} \in E} \varphi_{t,t'}(x) \\
g^{\bm{\varphi}}_{t,t'}(x, x') & = g_{t,t'}(x,x') - \varphi_{t,t'}(x) - \varphi_{t',t}(x')
\end{align}
\end{subequations}
then, $(G,X,\bm{g})$ and $(G,X,\bm{g^{\bm{\varphi}}})$ are equivalent. This can be proven by expressing $F(\bm{x}| \bm{g^{\varphi}})$ using $\bm{g}$ and $\varphi_{t,t'}(x)$ because the $\varphi_{t,t'}(x)$ terms cancel out.

However, not all problems that are in one equivalence class are necessarily tied to each other by the shown transformation. It holds in general for connected graphs $G$ and vectors $\bm{g}$ with finite values.

Notice that when we defined the $\bm{g}$ values, writing either $g_{t,t'}(x,x')$ or $g_{t',t}(x',x)$ was the same, because both were just simpler notations of $g(\{(t,x), (t',x')\})$, i.e. the assigned value to the given edge. On the other hand, $\varphi_{t,t'}(x)$ and $\varphi_{t',t}(x')$ are different variables and can generally have different values.


\begin{figure}
\centering
\begin{tikzpicture}
\begin{scope}[every node/.style={circle,thick,draw}]
    \node (B1) at (0,0) {1};
    \node (A1) at (0,2) {4};
    \node (B2) at (4,0) {5};
    \node (A2) at (4,2) {2};

    \node (B3) at (8,0) {3};
    \node (A3) at (8,2) {2};
\end{scope}

\foreach \x in {0,4,8}
\draw [shift={(\x,0)}] (-0.5,-0.5) -- (0.5,-0.5) -- (0.5,2.5) -- (-0.5,2.5) -- cycle;

    \node at (0,3) {object 1};
    \node at (4,3) {object 2};
    \node at (8,3) {object 3};
    \node[anchor=east] at (-0.7,2) {label $A$:};
    \node[anchor=east] at (-0.7,0) {label $B$:};
    

\begin{scope}[>={Stealth[black]},
              every node/.style={fill=white,circle},
              every edge/.style={draw=red,very thick}]
    \path [-] (A1)[bend left=15] edge node {$2$} (B2);
    \path [-] (A1) edge node {$3$} (A2);
    \path [-] (B1) edge node {$1$} (B2);
    \path [-] (B1)[bend right=15] edge node {$3$} (A2);
    
    \path [-] (A2)[bend left=15] edge node {$-1$} (B3);
    \path [-] (A2) edge node {$0$} (A3);
    \path [-] (B2) edge node {$8$} (B3);
    \path [-] (B2)[bend right=15] edge node {$5$} (A3);
\end{scope}
\end{tikzpicture}
\caption{Equivalent problem to the previous example.}
\label{equivalent_example}
\end{figure}

\begin{example}
The problem shown in Figure \ref{equivalent_example} is equivalent to the one in Figure~\ref{binarymaxsum_example}. It was obtained using a transformation vector $\bm{\varphi}$ which contains only zeros, except for $\varphi_{2,1}(B) = 3$. Because of this, the value of the corresponding node and the values of the edges in pencil $P(2,1,B)$ change, i.e.
\begin{subequations}
\begin{align}
g_2^{\bm{\varphi}}(B) & = g_2(B) + \varphi_{2,1}(B)+\varphi_{2,3}(B) = 2 + 3 + 0 = 5 \\
g^{\bm{\varphi}}_{2,1}(B, A) & = g_{2,1}(B,A) - \varphi_{2,1}(B) - \varphi_{1,2}(A) = 5 - 3 - 0 = 2 \\
g^{\bm{\varphi}}_{2,1}(B, B) & = g_{2,1}(B,B) - \varphi_{2,1}(B) - \varphi_{1,2}(B) = 4 - 3 - 0 = 1.
\end{align}
\end{subequations}
\exampleEnd
\end{example}

\section{Upper Bound}\label{upper_bound_minimization}

It is easy to formulate an upper bound on the maximum quality of a solution. This upper bound was introduced by \cite{schlesinger1976syntactic} and is therefore sometimes called {\em Schlesinger's upper bound} or the {\em height}.

\begin{definition}
The {\em height} of a binary max-sum problem $(G,X,\bm{g})$ is defined as
\begin{equation}
U(\bm{g}) =  \sum_{t \in T}{u_t} + \sum_{ \{ t,t' \} \in E}{u_{t,t'}},
\end{equation}
where
\begin{equation}
u_t = \max_{x \in X}{g_t(x)}, \hspace{5mm}
u_{t,t'} = \max_{ \{ x,x' \} \in X}{g_{t,t'}(x,x')}.
\end{equation}
The term $u_t$ is called the {\em height of object} $t$ and $u_{t,t'}$ is the {\em height of pair} $\{t, t'\}$.
\end{definition}

\begin{corollary}
The height of a max-sum problem is an upper bound on its quality,
\begin{equation}\label{gap}
F(\bm{x}| \bm{g}) \leq U(\bm{g}).
\end{equation}
\end{corollary}

\begin{proof}
It is truly an upper bound because $u_t \geq g_t(x)$ for all $t \in T$, $x \in X$ and $u_{t,t'} \geq {g_{t,t'}(x,x')}$ for all $\{t,t'\} \in E$, $x,x' \in X$ and exactly one node from each object and exactly one edge from each pair is used in any labelling.
\end{proof}

As opposed to the optimal quality of a binary max-sum problem, the height of a problem is not invariant to equivalent transformations and it is therefore possible to minimize the height by transforming the problem. This can be formulated as the linear program
\begin{subequations}\label{dual}
\begin{align}
\min_{\bm{u, \varphi}} \sum_{t \in T}{u_t}  & + \sum_{ \{ t,t' \} \in E}{u_{t,t'}} \\
  \varphi_{t't}(x) & \in \mathbb{R} \\
  u_t & \in \mathbb{R} \\
  u_{t,t'} & \in \mathbb{R} \\
  u_t & \geq g_t(x) + \sum_{\{t,t'\} \in E} \varphi_{t,t'}(x) \\
  u_{t,t'} & \geq g_{t,t'}(x, x') - \varphi_{t,t'}(x) - \varphi_{t',t}(x')
\end{align}
\end{subequations}
which is actually the dual to the LP relaxation \eqref{primal2}.

To find the minimum height of a problem, we can formulate the criterion of the previous LP also differently, for example
%(\abs{T} + \abs{E}) \min_{\bm{\varphi}} \max \big\{ \max_{t \in T}{\max_{x \in X}{g_t^{\bm{\varphi}}(x)}} , \max_{ \{ t,t' \} \in E}{\max_{ \{ x,x' \} \in X}{g^{\bm{\varphi}}_{tt'}(x,x')}} \big\},

\begin{equation}\label{maf_lp_form}
(\abs{T} + \abs{E}) \min_{\bm{\varphi}} \max \big\{ \max_{t \in T}u_t(x) , \max_{ \{ t,t' \} \in E}u_{t,t'}(x,x') \big\},
\end{equation}
where the constant $(\abs{T} + \abs{E})$ can be removed from the criterion function during optimization. The criterion can be also written in the form
\begin{equation}\label{augdag_lp_form}
\min_{\bm{\varphi} \, \mid \, g^{\bm{\varphi}}_{t,t'}(x,x') \leq 0} \, \sum_{t \in T}u_t(x),
\end{equation}
which requires an additional constraint on $g^{\bm{\varphi}}_{t,t'}(x,x')$ values.

\vspace{1cm}

\section{Tightness of the Bound}

\begin{definition}
Given a binary max-sum problem $(G,X,\bm{g})$, node $(t,x)$ is a {\em maximal node} if $u_t = g_t(x)$. Likewise, edge $\{ (t,x), (t',x')\}$ is a {\em maximal edge} if $u_{t,t'} = g_{t,t'}(x,x')$.
\end{definition}

Whether a node is maximal or not can be encoded into a binary vector $\bm{\bar{g}}$ by setting 
\begin{subequations}\label{maximal}
\begin{align}
   \bar{g}_t(x) & = \iverson{g_t(x) = u_t} \\
    \bar{g}_{t,t'}(x,x') & = \iverson{g_{t,t'}(x,x') = u_{t,t'}}.
\end{align} 
\end{subequations}

The binary max-sum problem $(G,X,\bar{\bm{g}})$ is essentially a constraint satisfaction problem, in which we search for a labelling (or fractional labelling) that uses only those edges and nodes that correspond to ones in the vector $\bm{\bar{g}}$.


\begin{theorem}\label{csp_sat_min_height_thm}
The CSP $(G,X,\bar{\bm{g}})$ corresponding to a binary max-sum problem $(G,X,\bm{g})$ is satisfiable iff
\begin{equation}\label{csp_sat_min_h_thm_eqn}
\max_{\bm{x} \in X^{T}} F(\bm{x}| \bm{g}) = U(\bm{g}).
\end{equation}
\end{theorem}

\begin{proof}
To show that the previous claim holds is easy because the satisfiability of the CSP implies that there is a labelling $\bm{x}$ that uses only the maximal nodes and edges. And for this labelling, it holds that the $\bm{g}$ value of each used node (resp. edge) corresponds to the maximum in the corresponding object $t$ (resp. pair $\{t,t'\}$) that equals $u_t$ (resp. $u_{t,t'}$), therefore $F(\bm{x}| \bm{g}) = U(\bm{g})$ and the quality of this labelling is the highest because it uses only the maximal edges and maximal nodes.

For the inverse implication, we can choose the labelling $\bm{x}^*$ that maximizes $F(\bm{x}^*| \bm{g})$, which equals $U(\bm{g})$. So it must necessarily hold that this labelling uses only the maximal nodes and edges (otherwise, its quality would be lower than $U(\bm{g})$), therefore the corresponding CSP is satisfiable.
\end{proof}


\begin{corollary}\label{proposition_min_ub_57}
If condition \eqref{csp_sat_min_h_thm_eqn} is satisfied, then the upper bound is minimal.
\end{corollary}

\begin{example}
The CSP corresponding to the problem shown in Figure \ref{binarymaxsum_example} is depicted in Figure \ref{binarymaxsum_example_maximum_nodes}. The maximal nodes in the figure are filled and the non-maximal nodes are white. The  maximal edges are drawn with full lines, whereas the non-maximal edges are dotted. Because the CSP is satisfiable, it means that there is a labelling that uses only the maximal nodes and edges, therefore the original problem has minimum height. The CSP thus revealed the optimal labelling of the original problem as $\bm{x} = (A, B, B)$.

On the other hand, the problem shown in Figure \ref{equivalent_example} does not have minimum height, because the corresponding CSP, which is shown in Figure \ref{equivalent_example_maximum_nodes}, is not satisfiable. 
\exampleEnd
\end{example}

\begin{figure}
\centering
\begin{tikzpicture}
\begin{scope}[every node/.style={circle,thick,draw}]
    \node (B1) at (0,0) {};
    \node[fill] (A1) at (0,2) {};
    \node[fill] (B2) at (4,0) {};
    \node[fill] (A2) at (4,2) {};

    \node[fill] (B3) at (8,0) {};
    \node (A3) at (8,2) {};
\end{scope}

\foreach \x in {0,4,8}
\draw [shift={(\x,0)}] (-0.5,-0.5) -- (0.5,-0.5) -- (0.5,2.5) -- (-0.5,2.5) -- cycle;

    \node at (0,3) {object 1};
    \node at (4,3) {object 2};
    \node at (8,3) {object 3};
    \node[anchor=east] at (-0.7,2) {label $A$:};
    \node[anchor=east] at (-0.7,0) {label $B$:};
    

\begin{scope}[>={Stealth[black]},
              every node/.style={fill=white,circle},
              every edge/.style={draw=black,very thick}]
    \path [-] (A1) edge (B2); %[bend left=15]
    \path [-,dotted] (A1) edge (A2);
    \path [-,dotted] (B1) edge (B2);
    \path [-,dotted] (B1) edge (A2); %[bend right=15]
    
    \path [-,dotted] (A2) edge (B3); %[bend left=15]
    \path [-,dotted] (A2) edge (A3);
    \path [-] (B2) edge (B3);
    \path [-,dotted] (B2) edge  (A3);%[bend right=15]
\end{scope}
\end{tikzpicture}
\caption{The CSP corresponding to Figure \ref{binarymaxsum_example}.}
\label{binarymaxsum_example_maximum_nodes}
\end{figure}

\begin{figure}
\centering
\begin{tikzpicture}
\begin{scope}[every node/.style={circle,thick,draw}]
    \node (B1) at (0,0) {};
    \node[fill] (A1) at (0,2) {};
    \node[fill] (B2) at (4,0) {};
    \node (A2) at (4,2) {};

    \node[fill] (B3) at (8,0) {};
    \node (A3) at (8,2) {};
\end{scope}

\foreach \x in {0,4,8}
\draw [shift={(\x,0)}] (-0.5,-0.5) -- (0.5,-0.5) -- (0.5,2.5) -- (-0.5,2.5) -- cycle;

    \node at (0,3) {object 1};
    \node at (4,3) {object 2};
    \node at (8,3) {object 3};
    \node[anchor=east] at (-0.7,2) {label $A$:};
    \node[anchor=east] at (-0.7,0) {label $B$:};
    

\begin{scope}[>={Stealth[black]},
              every node/.style={fill=white,circle},
              every edge/.style={draw=black,very thick}]
    \path [-,dotted] (A1) edge (B2); %[bend left=15]
    \path [-] (A1) edge (A2);
    \path [-,dotted] (B1) edge (B2);
    \path [-] (B1) edge (A2); %[bend right=15]
    
    \path [-,dotted] (A2) edge (B3); %[bend left=15]
    \path [-,dotted] (A2) edge (A3);
    \path [-] (B2) edge (B3);
    \path [-,dotted] (B2) edge  (A3); %[bend right=15]
\end{scope}
\end{tikzpicture}
\caption{The CSP corresponding to Figure \ref{equivalent_example}.}
\label{equivalent_example_maximum_nodes}
\end{figure}


%\begin{theorem}
%Let C be a class of equivalent max-sum problems. If C contains a trivial problem, then any problem in C is trivial if and only if its height is minimal in C.
%\end{theorem}

%\begin{proof}
%Assume there is a trivial problem $(G,X,\bm{g})$ in $C$ and $\bm{x^*}$ be its labelling that uses only the maximal nodes and edges. Then, for any problem $(G,X,\bm{g'})$ in $C$ it holds that
%\begin{equation}
%U(\bm{g'}) \geq F(\bm{x^*}|\bm{g'}) = F(\bm{x^*}|\bm{g}) = U(\bm{g}).
%\end{equation}
%The first inequality holds obviously. The equality between the qualities of the labelling follows from the equivalence of the problems and the equality between $F(\bm{x^*}|\bm{g})$ and $U(\bm{g})$ holds, because the labelling $\bm{x^*}$ uses only maximal nodes and edges. Therefore, $(G,X,\bm{g})$ has minimal height.
%On the other hand, assume that $(G,X,\bm{g''})$ has minimal height, then $U(\bm{g''}) = U(\bm{g})$, because $(G,X,\bm{g})$ also has minimal height. And since the problems are equivalent, $F(\bm{x^*}|\bm{g''}) = F(\bm{x^*}|\bm{g}) = U(\bm{g}) = U(\bm{g''})$, we get $F(\bm{x^*}|\bm{g''}) = U(\bm{g''})$, which can be only obtained when  $\bm{x^*}$ is a labelling that uses only maximal nodes and edges, so we conclude that $(G,X,\bm{g''})$ is necessarily trivial.
%\end{proof}

\section{Minimality of the Upper Bound}

Due to duality of the corresponding linear programs \eqref{primal2} and \eqref{dual}, $\bm{g}^T\bm{\mu}\leq~U(\bm{g})$. Knowing this and using the complementary slackness condition, it can be seen that $\bm{g}^T \bm{\mu} = U(\bm{g})$ iff

\begin{subequations}\label{slackness}
\begin{align}
  \mu_t(x) \left(u_t - g_t(x)\right) & = 0,  & \forall t \in T, x \in X \\
  \mu_{t,t'}(x,x') \left( u_{t,t'} - g_{t,t'}(x,x')\right) & = 0,  & \forall \{t,t' \} \in E, \; x, x' \in X.
  \end{align}
\end{subequations}

The constraints \eqref{slackness} can be reformulated using the $\bm{\bar{g}}$ vector from \eqref{maximal} as

\begin{subequations}\label{slackness2}
\begin{align}
  \mu_t(x) \left(1 - \bar{g}_t(x)\right) & = 0 \\
  \mu_{t,t'}(x,x') \left( 1 - \bar{g}_{t,t'}(x,x')\right) & = 0.
\end{align}
\end{subequations}


\begin{theorem}\label{tm1}
For a max-sum problem $(G,X,\bm{g})$ and a fractional labelling $\bm{\mu} \in \Lambda_{G,X}$, the following statements are equivalent:
\begin{enumerate}[label=(\alph*)]
\item $(G,X,\bm{g})$ has the minimal height of all its equivalents and $\bm{\mu}$ has the highest quality.
\item $\bm{g}^T \bm{\mu} = U(\bm{g})$
\item $\bm{\mu}$ is zero on non-maximal nodes and edges.
\end{enumerate}
\end{theorem}

The relation between $\textit{(a)}$ and $\textit{(b)}$ in Theorem \ref{tm1} follows from strong duality, whereas the relation between $\textit{(b)}$ and $\textit{(c)}$ is given by complementary slackness conditions \eqref{slackness2}.


The set of vectors $\bm{\alpha}$ satisfying conditions \eqref{partiallydecided} and \eqref{slackness2} will be denoted as
\begin{equation}
\bar{\Lambda}_{G,X}(\bar{\bm{g}}) = \{\bm{\mu} \in \Lambda_{G,X} \mid (1-\bar{\bm{g}})^T\bm{\mu} = 0 \}.
\end{equation}
Such $\bm{\mu}$ does not necessarily need to always exist, i.e. the set $\bar{\Lambda}_{G,X}(\bar{\bm{g}})$ could be empty.

\begin{definition}
We are given a CSP $(G,X,\bar{\bm{g}})$. This instance is called {\em relaxed-satisfiable} if $\bar{\Lambda}_{G,X}(\bar{\bm{g}}) \neq \emptyset$.
\end{definition}

\begin{theorem}\label{tm2}
The height of $(G,X,\bm{g})$ is minimal of all its equivalents if and only if $(G,X,\bm{\bar{g}})$ is relaxed-satisfiable.
\end{theorem}

\section{Arc Consistency and its Closure}

\begin{definition}
We say that a CSP $(G, X, \bar{\bm{g}})$ is {\em arc consistent} if
\begin{equation}\label{arc_consistency_condition}
\bigvee_{x' \in X} \bar{g}_{t,t'}(x,x') = \bar{g}_t(x), \quad \forall \{t, t'\} \in E, \, x \in X,
\end{equation}
where $\bar{g}_{t,t'}(x,x')$ is viewed as true iff it equals 1 (likewise with $\bar{g}_t(x)$).
\end{definition}

The main idea of arc consistency in this case is that if a node (or an edge) has value 1 in the $\bar{\bm{g}}$ vector, then it can be viewed as allowed to be used in a solution. However, if a node (resp. an edge) has value 1 and all its outgoing edges that are in one pencil have value 0 (resp. one of the nodes that it connects has value 0), then there is no solution that would use this node (resp. edge), so it is actually forbidden to use it even though its corresponding value in the $\bar{\bm{g}}$ vector is 1. Arc consistent CSPs do not have this issue.

For the following definition, we need to define what is a subproblem of a CSP. Given a CSP $(G, X, \bar{\bm{g}})$, we say that the CSP $(G, X, \bar{\bm{g}}')$ is its {\em subproblem} iff it holds that $\bar{\bm{g}}' \leq \bar{\bm{g}}$, where the inequality is evaluated element-wise. It is obvious that a CSP could have multiple subproblems.

\vspace{5cm}

Given multiple subproblems $(G, X, \bar{\bm{g}}^1), \cdots, (G, X, \bar{\bm{g}}^n)$ of the same CSP, then the {\em union} of these subproblems is the CSP $(G, X, \bar{\bm{g}}^U)$, where $\bar{\bm{g}}^U$ satisfies
\begin{subequations}
\begin{align}
\bar{g}^U_{t}(x) &= \bigvee_{i = 1}^{n} \bar{g}^i_{t}(x) \quad & \forall t \in T, \, x \in X \\
\bar{g}^U_{t,t'}(x,x') &= \bigvee_{i = 1}^{n} \bar{g}^i_{t,t'}(x,x') \quad & \forall \{t, t'\} \in E, \, x, x' \in X.
\end{align}
\end{subequations}


\begin{definition}
The {\em AC closure} of a CSP is the union of all its arc consistent subproblems.
\end{definition}

\begin{example}
Neither the CSP shown in Figure \ref{binarymaxsum_example_maximum_nodes} nor the one in Figure \ref{equivalent_example_maximum_nodes} is arc consistent, but the CSP corresponding to Figure \ref{binarymaxsum_example_maximum_nodes} has a non-empty AC closure, as opposed to the other CSP, whose AC closure is empty.
\exampleEnd
\end{example}

Now, we observed that the AC closure of a CSP can be empty -- we say that the AC closure is empty iff for some object (or pair), there is no node (or edge) with its $\bar{\bm{g}}$ value equal to 1\footnote{For connected graphs $G$, this means $\bar{\bm{g}} = \bm{0}$.}. In this case, it can be easily seen that a vector $\bm{\mu}$ satisfying conditions \eqref{partiallydecided} and \eqref{slackness2} cannot exist, i.e. $\bar{\Lambda}_{G,X}(\bar{\bm{g}}) = \emptyset$. This observation allows to formulate Theorem \ref{tm3} whose proof is in \cite{4204160}.

\begin{theorem}\label{tm3}
If a CSP is relaxed-satisfiable, then its AC closure is non-empty.
\end{theorem}

Finding out whether the AC closure of a CSP is empty can be done in polynomial time by an arc consistency algorithm. This procedure is derived from the condition on arc consistency \eqref{arc_consistency_condition}. Initially, we are given a CSP $(G, X, \bar{\bm{g}})$. Now, we will be changing the vector $\bar{\bm{g}}$ until the corresponding CSP is arc consistent.

The arc consistency procedure looks for values $\{t, t'\} \in E, \, x \in X$ such that the condition \eqref{arc_consistency_condition} is violated. There are only two ways in which it could be violated. The first one is when the disjunction on the LHS evaluates to true and $\bar{g}_t(x)$ is false. In this case, the elements of the disjunction on the LHS will be set to zero, so that the condition is satisfied for this particular pencil. The second case is when the LHS evaluates to false but $\bar{g}_t(x)$ is true -- then, we need to set $\bar{g}_t(x)$ to zero. This procedure will always surely terminate after a finite amount of steps because the number of non-zero components of $\bar{\bm{g}}$ vector always decreases after each step and it is a finite non-negative value.

The Proposition \ref{proposition_min_ub_57} along with Theorems \ref{csp_sat_min_height_thm}, \ref{tm2} and \ref{tm3} together give the following chain of implications and equivalences.

\begin{table}[h]
\centering
$(G, X, \bar{\bm{g}})$ is satisfiable \\
\rotatebox[origin=c]{-90}{$\Leftrightarrow$} \\
Equality \eqref{csp_sat_min_h_thm_eqn} holds \\
\rotatebox[origin=c]{-90}{$\Rightarrow$} \\
$(G, X, \bm{g})$ has minimal height \\
\rotatebox[origin=c]{-90}{$\Leftrightarrow$} \\
$(G, X, \bar{\bm{g}})$ is relaxed-satisfiable \\
\rotatebox[origin=c]{-90}{$\Rightarrow$} \\
$(G, X, \bar{\bm{g}})$ has non-empty AC closure
\end{table}

\section{Upper Bound Minimization Algorithms}

Algorithms for upper bound minimization can be divided into two categories -- algorithms that find the true minimum of the upper bound \eqref{dual} and algorithms that do not guarantee to find its minimum, but instead find an equivalent transformation such that the corresponding CSP $(G, X, \bar{\bm{g}}^{\bm{\varphi}})$ has a non-empty AC closure. By Theorems \ref{tm2} and \ref{tm3}, having a non-empty AC closure is a necessary condition for having minimum height.

\subsection{Exact Algorithms}

The exact algorithms guarantee to find the optimum in all cases, however the price for the optimality is their longer runtime. \cite{Kappes-study-2013} experimentally shows that exact methods are significantly slower than approximate algorithms in typical practical applications.


%\itodo{Source for max-sum diffusion  , for TRW-S \cite{kolmogorov2006convergent}}

\subsubsection{Linear Programming}

Of course, the problem of height minimization can be optimally solved by general LP solvers because it is directly given as an LP. Thus, we could for example use the simplex method or interior point methods. However, solving large-scale problems using these methods may need huge memory and could be time-demanding.


\subsubsection{Subgradient Methods}

Subgradient method of convex function minimization is described e.g. in \cite{boyd2003subgradient}. Its core idea is the same as with gradient descent but we do not use the gradient to find a decreasing direction. Instead, we use a subgradient and the subgradient method converges to a global optimum of a convex function that can be non-differentiable. Subgradient methods for minimization of the height of a max-sum problem are used for example by \cite{Komodakis07} or \cite{schlesinger2007solving}.

\subsubsection{Smoothing Methods}

It is also possible to replace the original minimized function by its smooth approximation, this was done for example in \cite{weiss2012map}, \cite{johnson2007lagrangian} or \cite{ravikumar2008message}. The replacement results in a differentiable function which can be minimized by any method of convex differentiable minimization.


\subsection{Approximate Algorithms}

As indicated above, the exact algorithms are more time-demanding and that is the reason why algorithms that enforce only the weaker condition of arc consistency are used. These algorithms can be seen as a special version of coordinate-wise minimization. It is known that the coordinate-wise minimization is guaranteed to converge to a global minimum only if the objective function is convex and differentiable. If it is convex but non-differentiable, it may converge to a local\footnote{Local is meant not as a topological neighbourhood, but only with respect to movements along the individual coordinates.} minimum.

Max-sum diffusion and Augmenting DAG algorithms contradict the common wisdom in optimization that coordinate-wise minimization applied to convex non-differentiable functions typically converges to very poor local minima.

\subsubsection{Max-sum Diffusion}

The procedure of max-sum diffusion was introduced in \cite{Kovalevsky-diffusion} and its pseudocode is shown in Algorithm \ref{maxsumdiffalg}. In one step of the algorithm, the $\varphi_{t,t'}(x)$ value is chosen such that the transformed values $g_t^{\bm{\varphi}}(x)$ and $u^{\bm{\varphi}}_{t,t'}(x)$ are equal\footnote{Note that $u^{\bm{\varphi}}_{t,t'}(x) = \max_{ x' \in X } {g^{\bm{\varphi}}_{t,t'}(x,x')}$.}. This step is performed for each pencil of the problem until the values converge.


\begin{algorithm}[H] \label{maxsumdiffalg}
 \While{\text{did not converge}}{
  \For{$(t, t', x) \in P$}{
   $\varphi_{t,t'}(x) \leftarrow \varphi_{t,t'}(x) + \frac{1}{2} \left( g_t^{\bm{\varphi}}(x) +  \max_{ x' \in X } {g^{\bm{\varphi}}_{t,t'}(x,x')}\right) $\;
  }
  }
 \caption{Max-sum diffusion}
\end{algorithm}

There is no proof of convergence of this algorithm, but it was at least experimentally shown to converge. Max-sum diffusion can be viewed as a form of coordinate descent method because the upper bound is lowered to its minimum with respect to each updated $\varphi_{t,t'}(x)$ at a time. This fact can be easily seen from the form \eqref{dual}.

\subsubsection{Augmenting DAG Algorithm}

This algorithm uses the graph presented in Definition \ref{detailed_graph}, in which each node and edge is assigned an auxiliary variable that initially stores whether the given node or edge is maximal. Then, the arc consistency algorithm is applied to this graph. If a maximal edge has a non-maximal node on its end, then the edge is marked as dead (i.e. it was killed by the non-maximal node). Likewise, if all edges in a pencil from a given maximal node are non-maximal, then the node is marked as dead (i.e. it was killed by the pencil). Whenever a node or an edge is killed, the pointer to the cause is stored, i.e. a dead edge points at one of its end points and a dead node points at the edges that are in the pencil that caused its death. For next iterations of the algorithm, dead nodes and edges are viewed as non-maximal and can cause further deletions. If it happens that in a given object $t^* \in T$, all nodes $(t,x)$, $x \in X$ are either non-maximal or dead, then the arc consistency procedure can be stopped.

Next, the algorithm searches for a direction $\Delta \bm{\varphi}$ and step size $\lambda$ so that the equivalent transformation by $\lambda \Delta \bm{\varphi}$ would decrease the height of the object $t^*$ and would not increase the height of any other object while satisfying constraints for edges $g^{\bm{\varphi}}_{t,t'}(x,x') \leq 0$\footnote{This algorithm uses the criterion function in the form \eqref{augdag_lp_form}.}.

The procedure explained in the previous paragraphs is then iteratively repeated and after each iteration, the value of $\lambda \Delta \bm{\varphi}$ is accumulated in a vector $\bm{\varphi}$, i.e.
\begin{equation}
\bm{\varphi} \leftarrow \bm{\varphi} + \lambda \Delta \bm{\varphi}.
\end{equation}

In this way, the Augmenting DAG algorithm gradually decreases the upper bound by equivalent transformations and ends when the arc consistency algorithm cannot mark any edge or node as killed and every object $t \in T$ still has at least one maximal node.

It holds for both Augmenting DAG and max-sum diffusion that after the algorithm ends, if the maxima of $g_t^{\bm{\varphi}}(x)$ over $x$ are unique for each $t~\in~T$ and the same holds for the $g^{\bm{\varphi}}_{t,t'}(x,x')$ values for all $x, x' \in X$ and $\{t, t'\} \in E$, then the optimal labelling can be simply obtained as the maximizing labels of $g_t^{\bm{\varphi}}(x)$. In such case, we are sure that the found upper bound is minimal.

However, if the maxima are not unique, the result of both algorithms is at least arc consistent, which is a necessary condition for optimality, but not a sufficient one.



\iffalse
\subsection{Algorithms}

\itodo{I could not find a proper place in 2nd chapter for coordinate descent yet, so I left it here temporarily}

\subsubsection{Coordinate descent}

Coordinate descent is a method that can be used to find a local minimum of an arbitrary function. However, if we want to minimize a MAF, it will not necessarily find the minimum in all cases and may end in a non-extremal point.

At the start of the algorithm, an initial value is assigned to the variable $\mathbf{x} \in \mathbb{R}^n$. Then, the following procedure is repeated in each iteration. First, a coordinate is chosen, after that the minimum of function $f$ with respect to this coordinate is found while all other components of $\mathbf{x}$ are fixed. Finally, the chosen coordinate of $\mathbf{x}$ is updated to the previously found minimizer and the process repeats while any coordinate changes.

This procedure is shown more formally in algorithm \ref{coorddesc}.

\begin{algorithm}[H] \label{coorddesc}
$\mathbf{x} \leftarrow $ initial value\; 
 \While{did not converge}{
 $j \leftarrow $ random($\{1, \dotsc, n\}$)\;
 $\xi^* \leftarrow$ choose$\Big(\argmin\limits_{\xi \in \mathbb{R}} f(x_1, \, \dotsc \, x_{j-1}, \xi, x_{j+1}, \, \dotsc \, , x_n)\Big)$\;
 $x_j \leftarrow \xi^*$\;
  }
 \caption{Coordinate descent}
\end{algorithm}

\begin{example}
A case, in which the algorithm does not find the minimum of a MAF, is the following one, where
\begin{equation} \label{examplenonmin}
    f(x,y)=\max\{x-2y,y-2x,x+y\}.
  \end{equation}
It can be seen that the minimum is at $x = y = 0$, however the algorithm stops the descent at any $x = y = c < 0$ and ends with suboptimal value $-c$ instead of $0$. The reason for this is that the minimizer of $\max\{x-2c,c-2x,x+c\}$ for $c<0$ is $x = c$. It holds also vice versa for $y$, because $f(x,y) = f(y,x)$.
\exampleEnd
\end{example}

\subsubsection{Modification of the coordinate descent algorithm}

The way of obtaining $\xi^*$ in the algorithm \ref{coorddesc} can be tailored to a function which is a MAF. This change could sometimes overcome the issue with ending in non-extremal points.

\begin{corollary}
Observe that if we define two sets

\begin{subequations}
\begin{equation}
\Xi^0 = \argmin\limits_{x_j \in \mathbb{R}} \max\limits_{i}(\mathbf{a}_i^T\mathbf{x}+b_i),
\end{equation}    
\begin{equation} \label{newformulation}
\Xi = \argmin\limits_{x_j \in \mathbb{R}} \max\limits_{i | a_{i,j} \neq 0}(\mathbf{a}_i^T\mathbf{x}+b_i)
\end{equation}
\end{subequations}
then it holds that $\Xi \subseteq \Xi^0$ if $\forall j \, \exists i: a_{i,j} \neq 0$. (This condition was added, because if it was violated, the set $\Xi$ would not be well-defined.)
\end{corollary}

\begin{proof}
Firstly, consider the trivial case in which all $a_{i,j} \leq 0$ or all $a_{i,j} \geq 0$, then the corresponding function that is minimized in \ref{newformulation} is not bounded and does not have a minimum, therefore $\Xi = \emptyset$ and $\emptyset \subseteq \Xi^0$ holds for any set $\Xi^0$. Secondly, consider that for all $j$, there exist indices $i_1$ and $i_2$ such that  $a_{i_1j} < 0$ and $a_{i_2j} > 0$. Then, the set $\Xi$ consists of a unique minimizer, which is also contained in the set $\Xi^0$, because adding constant terms into the set over which we maximize could only extend the set of minimizers.
\end{proof}

Now, we could alter the algorithm \ref{coorddesc} and choose $\xi^*$ from $\Xi$ instead of $\Xi^0$.

\begin{example}
Consider the function

\begin{equation} \label{examplenonmin2}
    f(x,y)=\max\{x,y,-x-y\}
\end{equation}
and coordinates $x = y = c > 0$. Then, the original procedure could choose $x = c$ as the minimizer of $\max\{x,c,-x-c\}$ (and similarly for $y$) and end with suboptimal value $c$. On the other hand, the altered procedure would converge towards the true minimum at $x = y = 0$.
\exampleEnd
\end{example}


\fi

