算法设计与分析项目-有容量设施选址问题

算法设计与分析项目-有容量设施选址问题 Capacitated Facility Location Problem(CFLP)

问题描述

Suppose there are n facilities and m customers. We wish to choose:

1.which of the n facilities to open
2. the assignment of customers to facilitiesThe objective is to minimize the sum of the opening costand the assignment cost.
3.The total demand assigned to a facility must not exceed its capacity.

数据集结构

斜体样式
注意demand of customer和Assignment cost 都是十个数据一换行,与Facility和customer数量无关。Assignment cost第1第2个数据为:将第1第2个顾客分配到工厂1的花费,而不是将第1个顾客分配到第1第2个工厂的花费,注意顺序。
还要注意有些数据集demand of customer和Assignment cost的数据后面有一个点,这里所有数据都可以视为整型。

项目

项目使用贪心算法和SA模拟退火算法
源代码,数据集和结果上传到github

贪心算法

贪心算法思路很简单,对于每个顾客,寻找能容纳其需求的且Assignment cost最小的工厂。
主要代码:

 facility_occpy.resize(facilities.size(), 0);
    for (auto &i : facility_occpy) i = 0;
    custumer_assign.resize(demands.size());

    for (int i = 0; i < demands.size(); i++) {
        size_t mincost = std::numeric_limits<size_t>::max();
        int min_index;
        //寻找能容纳其需求的且Assignment cost最小的工厂
        for (int j = 0; j < facilities.size(); j++) {
            if (get_cost(j, i) < mincost && demands[i] <= facilities[j].capacity - facility_occpy[j]) {
                min_index = j;
                mincost = get_cost(j, i);
            }
        }
        facility_occpy[min_index] += demands[i];
        custumer_assign[i] = min_index;
    }

部分结果

数据集 花费 时间
  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值