[期末项目]Capacitated Facility Location Problem工厂选址问题的两种算法

项目要求

[期末项目]Capacitated Facility Location Problem工厂选址问题的两种算法_第1张图片

从项目给出的信息中可以略窥一二,按数据划分的行也可以了解到:


工厂的数目n,消费者的数目m


工厂1的最大容量和开厂开销
工厂2的最大容量和开厂开销



工厂n的最大容量和开厂开销


m个消费者的各自需求


所有消费者分别到工厂1的开销
所有消费者分别到工厂2的开销



所有消费者分别到工厂n的开销


总开销=消费者开销+开厂开销
额外要求:单个工厂中各个消费者的需求之和不能超过其最大容量

需要关注的坑:

1.消费者和工厂相关的矩阵中行是工厂,列才是消费者,不能弄混了,贪心算法也是基于这个前提去实现才有价值
2.原数据的格式实在是一言难尽(尤其是文件p26),,,不但数据不规整,一些数字后会多出个小数点,而且在行数和结尾的结束符上也有区别,花了不少时间加条件判断甄别。还好总体不算大问题

具体思路

1.贪心算法

第一个想法就是用局部最优的方法来解,也就是贪心算法。思路也比较清晰:对于每个消费者而言,先选取当前开销最小的工厂,若该消费者的需求小于该工厂的剩余容量,则匹配之;反之,寻找开销第二小的工厂,重复上述过程。我选择按顺序从前往后遍历所有消费者,得到一个相对最优的结果。由上述推论可知结果波动很大,一般都与数据的排布有关,局部最优,但整体来看并不是一种很好的解法
相关代码如下:

import time

allfile = ""
for line in open("p1","r"):                      #相关的数据文件已经放在python文件的目录下
    allfile = allfile + line
str = allfile.split()                            #已经切割好的字符串元组

data = []
for i in range(0, len(str)):
    if len(str[i]) > 10:
        break
    if str[i][-1] == '.':                        #源数据中一些莫名其妙的格式
        data.append(int(str[i][:-1]))
    else:
        data.append(int(str[i]))                 #将所有数据从string转为int类型存在data中

#设置所需的参数
facility_num = data[0]                           #工厂的数目
customer_num = data[1]                           #消费者数目
capacity = []                                    #工厂的容量
opening_cost = []                                #开厂开销
customer_demand = []                             #消费者需求
cost = []                                        #消费者开销

for i in range (0, facility_num):
    capacity.append(data[2 + i * 2])
    opening_cost.append(data[3 + i * 2])

for i in range(facility_num * 2 + 2, facility_num * 2 + customer_num + 2):
    customer_demand.append(data[i])

for i in range(facility_num * 2 + customer_num + 2, len(data)):
    cost.append(data[i])

all_cost = 0                                     #总开销
facility_table = []                              #维持一个工厂的开关表
for i in range(0, facility_num):
    facility_table.append(0)

#开始贪心算法,对消费者进行遍历

starttime = time.time()              #计时开始

for i in range(0, customer_num):
    one_customer_cost = []                       #单个消费者对应的元组
    for j in range(0, facility_num):
        if customer_demand[i] > capacity[j]:     #如果需求大于剩余容量,设置一个极大值导入元组
            one_customer_cost.append(100000)
        else:
            one_customer_cost.append(cost[i + customer_num * j])    #元组输入完毕
    min_index = one_customer_cost.index(min(one_customer_cost))     #在剩余合理的工厂目标中挑选一个最小的代价,返回索引
    facility_table[min_index] = 1                                   #工厂开关打开
    capacity[min_index] = capacity[min_index] - customer_demand[i]  #最大容量减小(减去的是该消费者的需求)
    all_cost = all_cost + cost[i + customer_num * min_index]        #总代价增加

#针对开关表加上开厂开销
for i in range (0, facility_num):
    if facility_table[i] == 1:
        all_cost = all_cost + opening_cost[i]

#计时结束
endtime = time.time()

print(all_cost)

print (endtime - starttime)




结果

Result Time(s)
p1 9440 0.001275162494950258
p2 8126 0.001345366225354791
p3 10126 0.0012887105832739415
p4 12126 0.0012878894870118895
p5 9375 0.0013170384043143663
p6 8061 0.0012981531902874072
p7 10061 0.00129692154589435
p8 12061 0.0012981531902874072
p9 9040 0.0013240177225417316
p10 7726 0.0013211438856245705
p11 9726 0.0013178595005764182
p12 11726 0.0016495823904411344
p13 12032 0.002377894774871825
p14 9180 0.002377073678609759
p15 13180 0.0024743735856617155
p16 17180 0.002362704494024065
p17 12032 0.00241361246227062
p18 9180 0.0024025276627330783
p19 13180 0.0023688627159893505
p20 17180 0.0026619940815381105
p21 12032 0.002392674507588566
p22 9180 0.002400885470209002
p23 13180 0.00251132291745354
p24 17180 0.002668152303503424
p25 19197 0.01019965776707793
p26 16131 0.010837649562684126
p27 21531 0.010063355787579113
p28 26931 0.010405752928850369
p29 19305 0.009607647362146157
p30 16239 0.010017374396904796
p31 21639 0.009776793192126682
p32 27039 0.012489695241911375
p33 19055 0.009549760075672237
p34 15989 0.010188572967540416
p35 21389 0.009952097244072478
p36 26789 0.009742307149120943
p37 19055 0.009877788032357782
p38 15989 0.009826469515980207
p39 21389 0.009650754915903281
p40 26789 0.009810458138870382
p41 7226 0.0022530881430415373
p42 9957 0.0036427935665466205
p43 12448 0.004556673706198611
p44 7585 0.002252267046779499
p45 9848 0.003752820465660167
p46 12639 0.0046839436268151236
p47 6634 0.0022025907229260566
p48 9044 0.0035508307851979115
p49 12420 0.004512334508048332
p50 10062 0.0024628782379930714
p51 11351 0.004432277622499425
p52 10364 0.0024645204305172586
p53 12470 0.0043715164991082744
p54 10351 0.002434550416952619
p55 11970 0.004453626125312415
p56 23882 0.01280992278410753
p57 32882 0.013749667456013914
p58 53882 0.01423165096183221
p59 39121 0.014062505131851588
p60 23882 0.013539056264800342
p61 32882 0.013088274416939605
p62 53882 0.0185941354020579
p63 39121 0.013483632267112466
p64 23882 0.013649083163913778
p65 32882 0.013320644659097214
p66 53882 0.0143281297726221
p67 39671 0.016380459879594467
p68 23882 0.014084264182795847
p69 32882 0.014132298314125213
p70 53882 0.015234620045915692
p71 39121 0.01343682978017613

更详细的答案:

p1
9440
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[8, 5, 4, 7, 10, 4, 3, 2, 4, 3]

p2
8126
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[8, 5, 4, 7, 10, 4, 3, 2, 4, 3]

p3
10126
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[8, 5, 4, 7, 10, 4, 3, 2, 4, 3]

p4
12126
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[8, 5, 4, 7, 10, 4, 3, 2, 4, 3]

p5
9375
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[6, 6, 5, 6, 7, 4, 3, 3, 7, 3]

p6
8061
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[8, 3, 8, 6, 8, 7, 7, 6, 9, 5, 7, 8, 7, 6, 3, 5, 7, 4, 8, 12, 5, 6, 4, 6, 9, 8, 4, 9, 11, 4]

p70
53882
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[8, 3, 8, 6, 8, 7, 7, 6, 9, 5, 7, 8, 7, 6, 3, 5, 7, 4, 8, 12, 5, 6, 4, 6, 9, 8, 4, 9, 11, 4]

p71
39121
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[8, 3, 8, 6, 8, 7, 7, 6, 9, 5, 7, 8, 7, 6, 3, 5, 7, 4, 8, 12, 5, 6, 4, 6, 9, 8, 4, 9, 11, 4]

2.模拟退火算法

模拟退火算法是通过赋予搜索过程一种时变且最终趋于零的概率突跳性,从而可有效避免陷入局部极小并最终趋于全局最优的串行结构的优化算法。它是贪心算法中的一种,但是它的搜索过程引入了随机因素。在迭代更新可行解时,以一定的概率来接受一个比当前解要差的解,因此有可能会跳出这个局部的最优解,达到全局的最优解。

简而言之,依然采取对消费者遍历的方式,每一趟迭代随机找到一个解,逐渐接近最后的最优解。最后计算开销。具体步骤如下:

1.初始化:初始温度T,初始解为贪心算法的解,每个T值的迭代次数L=200;
2.对l=1,2,…,L做第3至第6步;
3.产生新解x_new,随机产生消费者与工厂之间的关系;
4.利计算增量Δcost=costx_new−costx,其中最小的cost为优化目标;
5.若Δcost<0则接受x_new作为新的当前解,否则以概率exp(−Δcost/T)接受x_new作为新的当前解;
6.迭代结束时终止算法
7.取a = 0.96,每次令T=T*a让T逐渐减小,然后转第2步。

相关代码如下:

import time
import random
import math

allfile = ""
for line in open("p1","r"):                      #相关的数据文件已经放在python文件的目录下
    allfile = allfile + line
str1 = allfile.split()                            #已经切割好的字符串元组

data = []
for i in range(0, len(str1)):
    if len(str1[i]) > 10:
        break
    if str1[i][-1] == '.':                        #源数据中一些莫名其妙的格式
        data.append(int(str1[i][:-1]))
    else:
        data.append(int(str1[i]))                 #将所有数据从string转为int类型存在data中

#设置所需的参数
facility_num = data[0]                           #工厂的数目
customer_num = data[1]                           #消费者数目
capacity = []                                    #工厂的容量
opening_cost = []                                #开厂开销
customer_demand = []                             #消费者需求
cost = []                                        #消费者开销

for i in range (0, facility_num):
    capacity.append(data[2 + i * 2])
    opening_cost.append(data[3 + i * 2])

for i in range(facility_num * 2 + 2, facility_num * 2 + customer_num + 2):
    customer_demand.append(data[i])

for i in range(facility_num * 2 + customer_num + 2, len(data)):
    cost.append(data[i])

facility_table = []                              #维持一个工厂的开关表
for i in range(0, facility_num):
    facility_table.append(0)

#开始模拟退火算法,对消费者进行遍历

a = 0.96
T = 1000                                     #温度为1000
starttime =  time.clock()              #计时开始
last_cost = 9440
it = 0

while 1:
    if it > 200:
        break
    #更新容量和工厂信息表
    for i in range(0, facility_num):
        capacity.append(data[2 + i * 2])
    facility_table = []
    for i in range(0, facility_num):
        facility_table.append(0)

    current_cost = 0
    for i in range(0, customer_num):
        one_customer_cost = []                       #单个消费者对应的元组
        valid_cost = []
        for j in range(0, facility_num):
            if customer_demand[i] > capacity[j]:     #如果需求大于剩余容量,设置一个极大值导入元组
                one_customer_cost.append(10000)
            else:
                one_customer_cost.append(cost[i + customer_num * j])    #元组输入完毕
                valid_cost.append(cost[i + customer_num * j])
        index = one_customer_cost.index(one_customer_cost[random.randint(0, len(valid_cost) - 1)]) #索引值
        facility_table[index] = 1                                   #工厂开关打开
        capacity[index] = capacity[index] - customer_demand[i]      #最大容量减小(减去的是该消费者的需求)
        current_cost = current_cost + cost[i + customer_num * index]        #总代价增加
    if current_cost <= last_cost:
        last_cost = current_cost
    else:
        rate = random.random()
        if rate < math.exp(-(current_cost - last_cost)/T):
            last_cost = current_cost
    T = T * a
    it = it + 1


#针对开关表加上开厂开销
for i in range (0, facility_num):
    if facility_table[i] == 1:
        last_cost = last_cost + opening_cost[i]

#计时结束
endtime =  time.clock()

print(last_cost)

print (endtime - starttime)

结果

Result Time(s)
p1 9440 0.34176366550508913
p2 8126 0.34857548009498446
p3 10126 0.3367344509000856
p4 12126 0.2829920583569536
p5 9375 0.331698667524986
p6 8061 0.32265921877617254
p7 10061 0.33061030442965
p8 12061 0.32605239907905803
p9 9040 0.3144708363029647
p10 7726 0.3296545483806339
p11 9726 0.3430614081472454
p12 11726 0.3386779857523372
p13 12032 0.5558214082786215
p14 9180 0.5339818899008444
p15 13180 0.5415257118083492
p16 17180 0.5369333204147528
p17 12032 0.5079859822446142
p18 9180 0.5445752633255712
p19 13180 0.5757687103205225
p20 17180 0.5458734165158585
p21 12032 0.6022137576320894
p22 9180 0.5100407756403715
p23 13180 0.5248094235575813
p24 17180 0.4979714816846279
p25 19197 2.1844387478610443
p26 16131 2.0849038167838643
p27 21531 1.4866789447927697
p28 26773 1.9061322753234293
p29 19305 2.21977626769052
p30 16239 2.2291379967221836
p31 21639 2.062501847466592
p32 26773 2.1729729596578977
p33 19055 2.090996761596344
p34 15989 2.1222649283511394
p35 21389 2.4185345238134346
p36 26773 2.452577174837664
p37 19055 2.1746188471151626
p38 15989 2.2721962847036323
p39 21389 2.2998072887072993
p40 26773 2.3514238630280033
p41 7226 0.6161719835386634
p42 10540 0.906725517372756
p43 7923 1.1789813315553843
p44 7585 0.604161808513787
p45 13518 0.8692030603899923
p46 12696 1.1256724778386058
p47 6634 0.5923187265782275
p48 10124 0.8427526759527169
p49 9123 1.1399394359397164
p50 10062 0.715002824571144
p51 11351 1.1206699488621297
p52 10364 0.7075435755786259
p53 12470 1.251005432372871
p54 10351 0.7474767711867472
p55 11970 1.2537171027782605
p56 23882 3.004201549572869
p57 32882 3.17177662240411
p58 56425 2.798629015571265
p59 39121 3.439444150674447
p60 23882 3.075291242844145
p61 32882 2.9152066206633833
p62 53882 2.9608304239155814
p63 39121 2.6408927286999386
p64 23882 2.983030403552391
p65 32882 2.835209675141485
p66 53882 2.9013407680862855
p67 39671 2.5932863885230404
p68 23882 2.906108874079962
p69 32882 2.761170193548807
p70 53882 2.9099048020993763
p71 39121 2.7447113189761865

更详细结果:

p1
9440
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[6, 6, 5, 6, 2, 6, 7, 6, 5, 1]

p2
8126
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[8, 7, 5, 5, 9, 3, 4, 2, 6, 1]

p3
10126
[1, 1, 1, 1, 1, 1, 1, 0, 1, 1]
[9, 6, 5, 8, 4, 5, 3, 0, 5, 5]

p4
12126
[1, 1, 1, 1, 1, 1, 1, 1, 1, 0]
[8, 12, 4, 6, 7, 5, 3, 2, 3, 0]

p5
9375
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[6, 6, 5, 5, 5, 3, 5, 6, 5, 4]

p6
8061
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[7, 3, 6, 3, 5, 8, 3, 3, 8, 4]

p7
10061
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[11, 7, 6, 6, 3, 3, 6, 3, 4, 1]

p8
12061
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[7, 10, 5, 3, 7, 6, 6, 2, 3, 1]

p9
9040
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[6, 7, 4, 5, 4, 6, 5, 7, 1, 5]

p10
7726
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[6, 3, 8, 3, 5, 7, 6, 4, 5, 3]

p11
9726
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[4, 6, 11, 8, 5, 2, 6, 4, 3, 1]

p12
11726
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[2, 6, 2, 5, 5, 5, 8, 10, 3, 4]

p13
12032
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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4, 6, 5, 3, 10, 13, 6, 6, 11, 4]


你可能感兴趣的:([期末项目]Capacitated Facility Location Problem工厂选址问题的两种算法)