动态规划算法设施位置 [英] Dynamic programming algorithm for facility locations

查看:126
本文介绍了动态规划算法设施位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有n个房子的位置A_1,A_2,...,A_N沿着一条线。我们要建立PORTA便壶沿着同一条线上,这样每家内至少有一个PORTA便盆的距离R。这些门部便壶被限制在指定位置B_1,B_2,...,B_M。让C_I是建立在位置b_i一个PORTA便盆的成本。

There are n houses at locations a_1, a_2,..., a_n along a line. We want to set up porta potties along that same line so that every house is within distance R of at least one porta potty. These porta potties are restricted to the specified locations b_1, b_2,..., b_m. Let c_i be the cost of setting up a porta potty at location b_i.

查找动态规划算法,建立了肝门便壶的总成本最小化。该算法应能检测一个解不存在。假设所有a和b值是不同的。

Find a dynamic programming algorithm that minimizes the total cost of setting up the porta potties. The algorithm should be able to detect if a solution does not exist. Assume that all a and b values are distinct.

输入:

  • A [1,2,... N]持有房子的位置

  • A[1, 2,...n] holds the house locations

B〔1,2,... M]持有潜力PORTA便盆位置

B[1, 2,...m] holds the potential porta potty locations

C [1,2,...米]保持设置在每一个门部便壶的成本 位置

C[1, 2,...m] holds the cost of setting up a porta potty at each location

输出:配售约束下肝门便壶的每家必须在一些PORTA便盆距离R

Output: the minimum cost of placing the porta potties under the constraint that every house must be within distance R of some porta potty

我无法找出一个递归EX pression工作过的。任何帮助将是AP preciated!

I'm having trouble figuring out a recursive expression to work off of. Any help would be appreciated!

推荐答案

您的问题给我写一些$ C $下经常出现类似的问题的机会的手机塔放置问题的或手机基地覆盖问题的。

Your question gave me the chance to write some code for a similar problem which often appears as cellphone tower placing problem or cellphone base coverage problem.

伪code如下:

1) Sort houses in ascending order
2) Sort facilities positions and their costs in ascending order by facilities positions
3) Let dp(i) be the minimum cost to cover i houses and lastBase(j) the last base used to cover j houses
4) Set the base case dp(0) = 0 and lastBase(0) = -1
5) For each house i:
6)   Check if previous solution is either valid or in range of this new house
7)   if it is -> grab it as solution
8)   else
9)     find a new base starting from lastBase(i) + 1 which can cover this house
10)    let it be the minimum-cost one
11)  if a base could be found -> add it to the previous solution
12)  else -> Problem cannot be solved

我建议第一次尝试它自己。

I recommend trying it out yourself first.

有关完整起见:解释,图像和C ++ code 都可以在这里

For completeness' sake: explanation, images and C++ code are available here.

反馈或错误的欢迎。

这篇关于动态规划算法设施位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆