# Metric k-center

In graph theory, the metric k-center problem or vertex k-center problem is a classical combinatorial optimization problem studied in theoretical computer science that is NP-hard. Given n cities with specified distances, one wants to build k warehouses in different cities and minimize the maximum distance of a city to a warehouse. In graph theory, this means finding a set of k vertices for which the largest distance of any point to its closest vertex in the k-set is minimum. The vertices must be in a metric space, providing a complete graph that satisfies the triangle inequality. It has application in facility location and clustering.

## Formal definition

The problem was first proposed by Hakimi in 1964.
Let $(X,d)$ be a metric space where $X$ is a set and $d$ is a metric A set $\mathbf {V} \subseteq {\mathcal {X}}$, is provided together with a parameter $k$. The goal is to find a subset ${\mathcal {C}}\subseteq \mathbf {V}$ with $|{\mathcal {C}}|=k$ such that the maximum distance of a point in $\mathbf {V}$ to the closest point in ${\mathcal {C}}$ is minimized. The problem can be formally defined as follows:
For a metric space (${\mathcal {X}}$,d),
* Input: a set $\mathbf {V} \subseteq {\mathcal {X}}$, and a parameter $k$.
* Output: a set ${\mathcal {C}}\subseteq \mathbf {V}$ of $k$ points.
* Goal: Minimize the cost $r^{\mathcal {C}}(\mathbf {V} )={\underset {v\in V}{\max }}$ d(v,${\mathcal {C}}$)
That is, every point in a cluster is in distance at most $r^{\mathcal {C}}(V)$ from its respective center.
The k-Center Clustering problem can also be defined on a complete undirected graph G = (V, E) as follows: Given a complete undirected graph G = (V, E) with distances d(v$_i$, v$_j$) ∈ N satisfying the triangle inequality, find a subset C ⊆ V with |C| = k while minimizing:
    $\max _{v\in V}\min _{c\in C}d(v,c)$

## Computational complexity

In a complete undirected graph G = (V, E), if we sort the edges in non-decreasing order of the distances: d(e$_1$) ≤ d(e$_2$) ≤ ... ≤ d(e$_m$) and let G$_i$ = (V, E$_i$), where E$_i$ = {e$_1$, e$_2$, ..., e$_i$}. The k-center problem is equivalent to finding the smallest index i such that G$_i$ has a dominating set of size at most k.
Although Dominating Set is NP-complete, the k-center problem remains NP-hard. This is clear, since the optimality of a given feasible solution for the k-center problem can be determined through the Dominating Set reduction only if we know in first place the size of the optimal solution (i.e. the smallest index i such that G$_i$ has a dominating set of size at most k), which is precisely the difficult core of the NP-Hard problems. Although a Turing reduction can get around this issue by trying all values of k.

## Approximations
### A simple greedy algorithm

A simple greedy approximation algorithm that achieves an approximation factor of 2 builds ${\mathcal {C}}$ using a farthest-first traversal in k iterations. This algorithm simply chooses the point farthest away from the current set of centers in each iteration as the new center. It can be described as follows:
* Pick an arbitrary point ${\bar {c}}_{1}$ into $C_{1}$
* For every point $v\in \mathbf {V}$ compute $d_{1}[v]$ from ${\bar {c}}_{1}$
* Pick the point ${\bar {c}}_{2}$ with highest distance from ${\bar {c}}_{1}$.
* Add it to the set of centers and denote this expanded set of centers as $C_{2}$. Continue this till k centers are found

#### Running time

* The ith iteration of choosing the ith center takes ${\mathcal {O}}(n)$ time.
* There are k such iterations.
* Thus, overall the algorithm takes ${\mathcal {O}}(nk)$ time.

#### Proving the approximation factor

The solution obtained using the simple greedy algorithm is a 2-approximation to the optimal solution. This section focuses on proving this approximation factor.
Given a set of n points $\mathbf {V} \subseteq {\mathcal {X}}$, belonging to a metric space (${\mathcal {X}}$,d), the greedy K-center algorithm computes a set K of k centers, such that K is a 2-approximation to the optimal k-center clustering of V.
i.e. $r^{\mathbf {K} }(\mathbf {V} )\leq 2r^{opt}(\mathbf {V} ,{\textit {k}})$
This theorem can be proven using two cases as follows,
Case 1: Every cluster of ${\mathcal {C}}_{opt}$ contains exactly one point of $\mathbf {K}$
* Consider a point $v\in \mathbf {V}$
* Let ${\bar {c}}$ be the center it belongs to in ${\mathcal {C}}_{opt}$
* Let ${\bar {k}}$ be the center of $\mathbf {K}$ that is in $\Pi ({\mathcal {C}}_{opt},{\bar {c}})$
* $d(v,{\bar {c}})=d(v,{\mathcal {C}}_{opt})\leq r^{opt}(\mathbf {V} ,k)$
* Similarly, $d({\bar {k}},{\bar {c}})=d({\bar {k}},{\mathcal {C}}_{opt})\leq r^{opt}$
* By the triangle inequality: $d(v,{\bar {k}})\leq d(v,{\bar {c}})+d({\bar {c}},{\bar {k}})\leq 2r^{opt}$
Case 2: There are two centers ${\bar {k}}$ and ${\bar {u}}$ of $\mathbf {K}$ that are both in $\Pi ({\mathcal {C}}_{opt},{\bar {c}})$, for some ${\bar {c}}\in {\mathcal {C}}_{opt}$ (By pigeon hole principle, this is the only other possibility)
* Assume, without loss of generality, that ${\bar {u}}$ was added later to the center set $\mathbf {K}$ by the greedy algorithm, say in ith iteration.
* But since the greedy algorithm always chooses the point furthest away from the current set of centers, we have that ${\bar {k}}\in {\mathcal {C}}_{i-1}$and,
${\begin{aligned}r^{\mathbf {K} }(\mathbf {V} )\leq r^{{\mathcal {C}}_{i-1}}(\mathbf {V} )&=d({\bar {u}},{\mathcal {C}}_{i-1})\\&\leq d({\bar {u}},{\bar {k}})\\&\leq d({\bar {u}},{\bar {c}})+d({\bar {c}},{\bar {k}})\\&\leq 2r^{opt}\end{aligned}}$

### Another 2-factor approximation algorithm

Another algorithm with the same approximation factor takes advantage of the fact that the k-Center problem is equivalent to finding the smallest index i such that G$_i$ has a dominating set of size at most k and computes a maximal independent set of G$_i$, looking for the smallest index i that has a maximal independent set with a size of at least k.
It is not possible to find an approximation algorithm with an approximation factor of 2 − ε for any ε > 0, unless P = NP.
Furthermore, the distances of all edges in G must satisfy the triangle inequality if the k-center problem is to be approximated within any constant factor, unless P = NP.

### Parameterized approximations

It can be shown that the k-Center problem is W[2]-hard to approximate within a factor of 2 − ε for any ε > 0, when using k as the parameter. This is also true when parameterizing by the doubling dimension (in fact the dimension of a Manhattan metric), unless P=NP. When considering the combined parameter given by k and the doubling dimension, k-Center is still W[1]-hard but it is possible to obtain a parameterized approximation scheme. This is even possible for the variant with vertex capacities, which bound how many vertices can be assigned to an opened center of the solution.

## Approximation algorithms

If $P\neq NP$, the vertex k-center problem can not be (optimally) solved in polynomial time. However, there are some polynomial time approximation algorithms that get near-optimal solutions. Specifically, 2-approximated solutions. Actually, if $P\neq NP$ the best possible solution that can be achieved by a polynomial time algorithm is a 2-approximated one. In the context of a minimization problem, such as the vertex k-center problem, a 2-approximated solution is any solution $C'$ such that $r(C')\leq 2\times r({\text{OPT}})$, where $r({\text{OPT}})$ is the size of an optimal solution. An algorithm that guarantees to generate 2-approximated solutions is known as a 2-approximation algorithm. The main 2-approximated algorithms for the vertex k-center problem reported in the literature are the Sh algorithm, the HS algorithm, and the Gon algorithm. Even though these algorithms are the (polynomial) best possible ones, their performance on most benchmark datasets is very deficient. Because of this, many heuristics and metaheuristics have been developed through the time. Contrary to common sense, one of the most practical (polynomial) heuristics for the vertex k-center problem is based on the CDS algorithm, which is a 3-approximation algorithm

### The Sh algorithm

Formally characterized by David Shmoys in 1995, the Sh algorithm takes as input a complete undirected graph $G=(V,E)$, a positive integer $k$, and an assumption $r$ on what the optimal solution size is. The Sh algorithm works as follows: selects the first center $c_{1}$ at random. So far, the solution consists of only one vertex, $C=\{c_{1}\}$. Next, selects center $c_{2}$ at random from the set containing all the vertices whose distance from $C$ is greater than $2\times r$. At this point, $C=\{c_{1},c_{2}\}$. Finally, selects the remaining $k-2$ centers the same way $c_{2}$ was selected. The complexity of the Sh algorithm is $O(kn)$, where $n$ is the number of vertices.

### The HS algorithm

Proposed by Dorit Hochbaum and David Shmoys in 1985, the HS algorithm takes the Sh algorithm as basis. By noticing that the value of $r({\text{OPT}})$ must equals the cost of some edge in $E$, and since there are $O(n^{2})$ edges in $E$, the HS algorithm basically repeats the Sh algorithm with every edge cost. The complexity of the HS algorithm is $O(n^{4})$. However, by running a binary search over the ordered set of edge costs, its complexity is reduced to $O(n^{2}\log n)$.

### The Gon algorithm

Proposed independently by Teofilo Gonzalez, and by Martin Dyer and Alan Frieze in 1985, the Gon algorithm is basically a more powerful version of the Sh algorithm. While the Sh algorithm requires a guess $r$ on $r({\text{OPT}})$, the Gon algorithm prescinds from such guess by noticing that if any set of vertices at distance greater than $2\times r({\text{OPT}})$ exists, then the farthest vertex must be inside such set. Therefore, instead of computing at each iteration the set of vertices at distance greater than $2\times r$ and then selecting a random vertex, the Gon algorithm simply selects the farthest vertex from every partial solution $C'$. The complexity of the Gon algorithm is $O(kn)$, where $n$ is the number of vertices.

### The CDS algorithm

Proposed by García Díaz et al. in 2017, the CDS algorithm is a 3-approximation algorithm that takes ideas from the Gon algorithm (farthest point heuristic), the HS algorithm (parametric pruning), and the relationship between the vertex k-center problem and the Dominating Set problem. The CDS algorithm has a complexity of $O(n^{4})$. However, by performing a binary search over the ordered set of edge costs, a more efficiente heuristic named CDSh is proposed. The CDSh algorithm complexity is $O(n^{2}\log n)$. Despite the suboptimal performance of the CDS algorithm, and the heuristic performance of CDSh, both present a much better performance than the Sh, HS, and Gon algorithms.

### Parameterized approximations

It can be shown that the k-Center problem is W[2]-hard to approximate within a factor of 2 − ε for any ε > 0, when using k as the parameter. This is also true when parameterizing by the doubling dimension (in fact the dimension of a Manhattan metric), unless P=NP. When considering the combined parameter given by k and the doubling dimension, k-Center is still W[1]-hard but it is possible to obtain a parameterized approximation scheme. This is even possible for the variant with vertex capacities, which bound how many vertices can be assigned to an opened center of the solution.

### Experimental comparison

Some of the most widely used benchmark datasets for the vertex k-center problem are the pmed instances from OR-Lib., and some instances from TSP-Lib. Table 1 shows the mean and standard deviation of the experimental approximation factors of the solutions generated by each algorithm over the 40 pmed instances from OR-Lib
Table 1. Experimental approximation factor over pmed instances from OR-Lib :
| Algorithm | $\mu$ | $\sigma$ | Complexity |
| HS | 1.532 | 0.175 | $O(n^{2}\log n)$ |
| Gon | 1.503 | 0.122 | $O(kn)$ |
| CDSh | 1.035 | 0.031 | $O(n^{2}\log n)$ |
| CDS | 1.020 | 0.027 | $O(n^{4})$ |
Table 2. Experimental approximation factor over instances from TSP-Lib :
| Algorithm | $\mu$ | $\sigma$ | Algorithm |
| Gon | 1.396 | 0.091 | $O(kn)$ |
| HS | 1.318 | 0.108 | $O(n^{2}\log n)$ |
| CDSh | 1.124 | 0.065 | $O(n^{2}\log n)$ |
| CDS | 1.042 | 0.038 | $O(n^{4})$ |

## Polynomial heuristics
### Greedy pure algorithm

The greedy pure algorithm (or Gr) follows the core idea of greedy algorithms: to take optimal local decisions. In the case of the vertex k-center problem, the optimal local decision consists in selecting each center in such a way that the size of the solution (covering radius) is minimum at each iteration. In other words, the first center selected is the one that solves the 1-center problem. The second center selected is the one that, along with the previous center, generates a solution with minimum covering radius. The remaining centers are selected the same way. The complexity of the Gr algorithm is $O(kn^{2})$. The empirical performance of the Gr algorithm is poor on most benchmark instances.

### Scoring algorithm

The Scoring algorithm (or Scr) was introduced by Jurij Mihelič and Borut Robič in 2005. This algorithm takes advantage of the reduction from the vertex k-center problem to the minimum dominating set problem. The problem is solved by pruning the input graph with every possible value of the optimal solution size and then solving the minimum dominating set problem heuristically. This heuristic follows the lazy principle, which takes every decision as slow as possible (opossed to the greedy strategy). The complexity of the Scr algorithm is $O(n^{4})$. The empirical performance of the Scr algorithm is very good on most benchmark instances. However, its running time rapidly becomes impractical as the input grows. So, it seems to be a good algorithm only for small instances.