最小化图表中的最大距离

时间:2015-04-11 15:01:30

标签: algorithm graph nodes edge

假设我们有一个加权无向图。假设图中有N个节点(城市),我们想要在城市中建立M(M <= N)个医院。现在我们需要选择最佳解决方案,以便最大限度地减少从城市到拥有医院的城市的最大距离。

假设我们有3个城市,我们需要建立1所医院。设有边1-3和2-3,分别具有重物83和71。显然,最佳解决方案是在城市3建立医院,从那时起最大距离为83.

我的想法是使用Floyd-Warshall算法,然后在距离数组中具有最小最大值的城市中建立医院。然后更新另一个数组b,使b1显示从城市1到有医院的城市的最小距离,并且类似地定义bi。之后我想像这样更新距离值:

dist_i_j = min (dist_i_j, b_j)

重复这一过程,直到我们建立了所有M家医院。

但是在某些情况下,此算法会遇到问题。假设我们得到了这张图,我们需要建立3家医院:

edge 1-2 with distance 1
edge 1-3 with distance 2
edge 2-4 with distance 7
edge 2-6 with distance 3
edge 3-4 with distance 5
edge 4-5 with distance 2
edge 5-6 with distance 4

在Floyd-Warshall算法之后,距离表将如下所示:

0 1 2 7 8 4
1 0 3 7 7 3
2 3 0 5 7 6
7 7 5 0 2 6
8 7 7 2 0 4
4 3 6 6 4 0

显然现在最好在6号城市建一所医院,因为最大值为6.现在更新价值:

0 1 2 6 4 0
1 0 3 6 4 0
2 3 0 5 4 0
4 3 5 0 2 0
4 3 6 2 0 0
4 3 6 6 4 0

但是知道我们不知道是在3号城市还是在4号城市建立医院。如果我们在4号城市建立医院,然后更新表格,我们就需要在1号城市建立医院,最大距离为2。

但是如果我们在城市3建立医院并更新价值,我们就会得到最好在4号城市或5号城市建立医院。但在这两种情况下,最大值都是3.那么我该如何克服这个问题?

1 个答案:

答案 0 :(得分:2)

这是k中心问题,并且已知是NP难的。如果图满足三角不等式,则存在2近似算法。见http://algo2.iti.kit.edu/vanstee/courses/kcenter.pdf