# Linear programming maximizes the minimum distance problem

I have a problem with creating an equation for linear programming solver.

Company wants to open stores in k cities. For the purpose of even coverage of the entire area, these cities should be selected from the available n candidates in such a way that it maximizes the minimum distance between any pair of selected cities.

I don't know how to define maximizes the minimum problem in graph in linear equation. Can any one give me some hints?

Thank you very much.

Let's first define some variables.

$$x_i \in \{0, 1\}$$ $$w_i \in \mathbb{Z}^+$$

Where $$x_i=1\iff$$ location $$i$$ is selected and $$w_i$$ equals the minimum distance from node $$i$$ to any selected city if $$x_i=1$$ and $$\infty$$ otherwise. We will use $$D$$ to represent $$\infty$$ and in practice $$D$$ can just be the diameter of the graph. We can constrain these variables below.

\begin{align} \sum_{i=1}^nx_i &= k\\ w_i & \leq \texttt{distance}(i,j) + D(2 - x_i - x_j)& \forall j\neq i \end{align}

It remains to find the minimum across all $$w_i$$. We will let this minimum be $$y$$. We constrain $$y$$ as follows $$y \leq w_i \;\; \forall i$$

Now the objective function is clear, we want to find the largest $$y$$ that satisfies our constraints $$\text{maximize }{y}$$

Our first constraint verifies that we select $$k$$ locations. The second gives us the minimum distance from a selected point to any other selected point. The third ensures that we find the minimum across these distances. Unfortunately, this is not a linear program but a mixed integer program.

If I have understood your question right, this an open NP problem. For 1D problem, there is a polynomial dynamic-programming algorithm. But for 2D, there exists an approximative greedy algorithm for solving it.

Algorithm

selectedStores = {}
randCity = choose a random city
stores ∪ {A}
while 1 to k
choose the farthest city from all cities in selectedStores
end


As you may have guessed, you need to run a preprocess in O(n^2) to find all the minimum distances from each city to all other cities in case all of them are simple points on a plane or you can use the Floyd-Warshall algorithm for extracting shortest path from each city to others if you have a graph-based input.

Note that, by farthest city from all cities in selectedStores in the algorithm, it means considering the distance of all cities which are not selected for building a store to their nearest center (the city that is selected for building the store inside it) inside the selectedStores set. From all the left cities select the one which has the farthest distance to its nearest center (This policy is responsible for maximizing the minimum distance).

The selected cities are not the best optimal solution but it solves the problem in polynomial time and it is proved that the problem of cities on a plane (without path between them) solves the problem with cities needed to cover an area with a radius twice the covering radius of the optimal solution and it's not really important if there exists a path between them until you have calculated all the shortest paths before running the greedy algorithm.

With the hope of providing insight into how to solve your problem, I will refer to the case of a grid $$N\times N$$. Let $$\rho_{ij}$$ denote the distance between two points $$i$$ and $$j$$, $$i, j\in G$$. The distances between any pair of nodes shall be stored as a parameter of your linear programming task, and can be given any values ---e.g., euclidean distance, Manhattan distance ...

There are various ways to model your case but I will go straight ahead to the one that (I think!) performs better because it requires less binary variables than other methods. Let $$x_{ij}$$ denote the decision variable which takes the value 1 if and only if points $$i$$ and $$j$$ are selected and 0 otherwise ---it is also possible to set up a linear programming task with a binary decision variable $$x_i$$ taking the value 1 if and only if location $$i$$ is selected but that leads to a quadratic number of binary variables. Obviously, $$x_{ij}=x_{ji}, \forall i, j$$, and this is the first constraint.

Secondly, to ensure that no more than $$k$$ points are selected, note that if $$\sum_j x_{ij} > 0$$ then point $$i$$ has been selected (same reasoning could have been followed by columns). Thus, let $$r_i$$ denote a binary variable whose value is computed with the following constraint: $$Mr_i >= \sum_j x_{ij}, \forall i$$. Clearly, if point $$i$$ is selected, then at least one variable $$x_{ij}=1$$ for some $$j$$. Because $$r_i$$ can only take values from the set $$\{0, 1\}$$, it is required to multiply it by an arbitrarily large constant $$M$$.

Only in appearance the constraint $$\sum_i r_i = k$$ ensures that exactly k points are selected. Note, however, that $$r_i=1$$ means that point $$i$$ is connected to at least 1 point, so that the constraint just guarantees that at least $$k$$ points have been selected. Alternatively, the constraint $$\sum_{i,j} x_{ij} = k (k-1)$$ seemingly solves the issue by constraining the solver to select $$k$$ pairs of nodes so that the total number of pairs is exactly equal to $$2{k\choose 2}$$. This is wrong again as it is not guaranteed that these pairs are taken with the minimum number of points. However, putting both constraints $$k$$ points are necessarily selected.

We come now to the core of your question, how to model the minimum distance between each pair of selected points. As $$x_{ij}$$ denotes whether points $$i$$ and $$j$$ have been selected, then let $$d_<$$ denote the minimum distance among all pairs of selected points: $$d_< \leq x_{ij}\rho_{ij}$$. This almost works as $$d_<$$ will be certainly upper-bounded by the minimum distance between each pair of selected nodes. Unfortunately, it forces $$d_<$$ to take the value $$0$$ because $$x_{ij}\rho_{ij}=0$$ for those cases where neither $$i$$ nor $$j$$ have been selected. To properly compute the minimum distance between each pair of selected nodes it is necessary thus to ignore those cases where either point has not been selected. For this, it just suffices adding $$M (1-x_{ij})$$ resulting in the constraint $$d_< \leq x_{ij}\rho_{ij} + M (1-x_{ij})$$ with $$M$$ being an arbitrarily large constant.

Finally, the objective function shall just simply maximize the minimum distance $$d_<$$: $$\max z = d_<$$

Hope this helps,