代码及结果
python代码:anneal.py
贪心算法:
- 结果:greedy_result
- 具体结果:greedy_detail_result
模拟退火:
- 结果:anneal_result
- 具体结果:anneal_detail_result
禁忌搜索:
- 结果:tabu_result
- 具体结果:tabu_detail_result
目录
题目描述
题意分析
样例格式
贪心算法
- python代码(部分)
- Detailed solution (部分)
模拟退火
- python代码(部分)
- Detailed solution (部分)
禁忌搜索
- python代码(部分)
- Detailed solution (部分)
题目描述
Suppose there are n facilities and m customers. We wish to choose:
- which of the n facilities to open
- the assignment of customers to facilities
The objective is to minimize the sum of the opening cost and the assignment cost.
The total demand assigned to a facility must not exceed its capacity.
题意分析
可以这样理解:
有n个facility, 每个facility具有一个capacity,如果开启这个facility,那么就会产生一个open cost。
有m个customer, 每个customer具有一个demond,customer可以自由选择去哪个facility, 但是选择这个facility的所有customer的demond之和不能大于它的capacity。每当customer选定一个facility,就会产生一个assign cost。
题目还有个隐含条件:所有customer的demond都要满足。
因此,总的cost可以表示为:所有开启了的facility的open cost之和 + 所有customer选择facility所产生的assign cost之和
我们的目标是令总的cost最小。
样例格式
例如:
1 贪心算法
我们可以让customer按顺序选择facility,当一个customer在选择时,它可以从所有facility中选择最优惠的那个。那么什么样的facility才是最优惠的呢?我目前想到三种方案:
- assign cost 最小的
- assign cost + open cost 最小的
- assign cost (如果该facility未开启,+ open cost) 最小的
实践证明,第一种方案得到的cost最小。第二种方案由于未考虑facility已开启的情况,导致错过了更优惠的facility,而第三种方案,由于过于在意facility是否开启,最终更倾向于已开启的facility,导致错过了很多开启后可能更优惠的facility。
1.1 python代码(部分)
def greedy():
global total_cost
// 对于每个customer
for i in range(len(assign[0]))