We have $n$ customers, $(x_1, \dots, x_n)$, sorted on the read line. For convenience, we also use $x_i$ to denote its coordinate on the line. We need to locate $m$ facilities on the real line. We note that these facilities can be located anywhere on the real line. Each facility $j\in [m]$ is associated with an entrance fee $f_j$, such as the ticket money for a swimming pool. Given a location profile $(y_1, \dots, y_m)\in \mathcal{R}^m$ for the facilities($(y_1, \dots, y_m)$ is not necessarily ordered), the cost for customer $i$ at facility $j$ is $c_{ij} = |x_i- y_j|+f_j$, which can be understood as the aggregate money of the travelling cost and the entrance fee when you taxi to a swimming pool and purchase a ticket to swim inside. And the customer will always choose the facility so as to minimize her cost.

Our goal is to find a location profile $(y_1, \dots, y_m)$ for the given $m$ facilities such that the total minimum cost

$$\sum_{i\in [n]}\min_{j\in [m]}c_{ij}$$ is minimized.

An easy but critical obserbation is that there is an optimal solution where each facility is located in the median agent of the continuous region of agents it serves. If we have identical entrance fees, we only need to find the optimal $m$ continuous partitions, which can be solved by dynamic programming in $O(mn^2)$. For the general case, similar DP algortihm runs in $O(2^mn^2)$. The algorithm, however, is exponential in $m$ and only makes sense after we've proved the problem is NP-hard. Another observation which may be helpful is that for if we have known the optimal $m$ continuous partitions, we just assign the facility of the $k$-th smallest entrance fee to the partition of the $k$-th most customers.

So is this problem NP-hard? Or is there an algorithm running in polynomial time?


Below is the detailed DP algorithms for the special case where all entrance fees are identical and the general case:

  1. For the spcial case, denote by $M(i,j,k)$ the minimum total cost when customer $i$ is in the $k$-th partition and customer $j$ the right boundary of this partition. Depending on whether or not customer $i-1$ is still in the $k$-partition, we derive the following transition function: $$M(i,j,k)= \min\{M(i-1,j,k), M(i-1,i-1,k-1)+c(i,j)\}$$ where $c(i,j)$ is the minimum total cost of partition $[i,j]$, i.e., total cost for these customers when exact one facility is located in the median of $[i,j]$.

    Obvious, this DP runs in $O(mn^2)$.

  2. For the general case, the key difference is that we have to decide which facility is located in the rightmost partition since now facilities are heterogeneous. Similarly we denote by $M(i,j,F)$ the minimum total cost when customer $i$ is in the rightmost partiton, customer $j$ is the right boundary of this partition and $F$ is the set of facilities to be located. Similarly again, we can derive the following transition function: $$M(i,j,F)= \min\{M(i-1,j,F), \\ \min_{s\in F}\{M(i-1,i-1,F\setminus\{s\})+c^{\prime}(i,j,f_s)\}\}$$ where $c^{\prime}(i,j,f_s)$ is the total cost of $[i,j]$ when a facility with entrance fee $f_s$ is locate in the median of $[i,j]$.

    This DP runs in $O(2^mn^2)$

  • 1
    $\begingroup$ I don't think your formulation is as you intended. In your formulation there's a separate cost $f_j$ for every client i connected to facility j (since $f_j$ is a part of $c_{ij}$). Assuming that I read that correctly, I think there should exist a simple DP along the number line. The only relevant state at every DP point is the rightmost open facility to the left of the current DP point (and the minimum cost achieved this way for all clients located to the left of that facility). $\endgroup$ Jan 3, 2021 at 1:00
  • 2
    $\begingroup$ @MagnusWahlström I didn't completely get how your DP works. The exponential part of my DP lies in the fact that we have to decide which facility is located in the rightmost partition. Do you think your DP could bypass this difficulty? And I've updated the details of my DP algorithms for your information, please have a look when you have time. Thanks a lot! $\endgroup$
    – asdfqwer
    Jan 5, 2021 at 3:38
  • $\begingroup$ Actually, I misread the instructions. Apologies. $\endgroup$ Jan 5, 2021 at 10:10
  • $\begingroup$ @MagnusWahlström That's all right. Now I tend to think the problem is NP-hard. But I could barely find an appropriate base NP-hard problem for the reduction, being stuck for three weeks :) $\endgroup$
    – asdfqwer
    Jan 5, 2021 at 11:18