python 设施开单 SCIP 优化

问题描述

我正在尝试使用 SCIP optimization 找到设施的最佳打开顺序 给定距离住宅区的距离并为数量加权 该地区的居民。

我已经设置了距离字典,以便从设施到 每个住宅区应为设施产生 [2,1,0] 订单的输出。

但是,我收到的输出是 [0,2]

此外,如果我将 alpha 更改为正值,则没有任何影响。

import pandas as pd
from pyscipopt import Model,quicksum,multidict,exp
num_fac_to_open = 3
order_to_open = []
opened_fac = []
closed_fac = [0,2]
# Facility id
S = [0,2]
# Residential block id
R = [10,11,12]
distance_dict = {(0,10): 0.8,(1,10): 150.6,(2,10): 100007.8,(0,11): 1.0,11): 2012.1,11): 10009.2,12): 3.2,12): 1798.3,12): 10006.3}
population_dict = {10:54,11:46,12:22}
alpha = -1
# n is the desired number of facilities to open
n = len(opened_fac) + num_fac_to_open
# create a model
model = Model()
z,y= {},{}
for s in S:
    # x_i is binary,1 if service facility i is opened,0 otherwise
    z[s] = model.addVar(vtype="B")
    for r in R:
        # y_i,j is binary,1 if service facility i is assigned to residential area j,0 otherwise
        y[s,r] = model.addVar(vtype="B")

for r in R:
    model.addCons(quicksum(y[s,r] for s in S) == 1)
#
for s in S:
    for r in R:
        model.addCons(y[s,r]-z[s] <= 0)
#
model.addCons(quicksum(z[s] for s in S) == n)
#
for facility in opened_fac:
    model.addCons(z[facility] == 1)

x,w = {},{}
for r in R:
    x[r] = model.addVar(vtype="C",name="x(%s)"%(r))
    w[r] = model.addVar(vtype="C",name="w(%s)"%(r))
for r in R:
    x[r] = quicksum(distance_dict[s,r]*y[s,r] for s in S)
    exp_power = alpha*population_dict[r]*x[r]
    model.addCons((w[r] - exp(exp_power)) >= 0)
#
#print(quicksum(w[r] for r in R))
model.setObjective(quicksum(w[r] for r in R),'minimize')
model.optimize()

new_facilities = []
for s in S:
    if ((model.getVal(z[s]) == 1) and (not s in opened_fac)):
        new_facilities.append(s)
        if len(new_facilities) == num_fac_to_open:
            break
print(new_facilities)

我正在尝试优化以下问题:

目标是minimize sum_{r=1}^N W_r

哪里W_r = exp(population_dict[r]*sum_{s∈S} d_r,s * y_r,s) ∀r ∈ R

对这个问题的任何帮助都会很棒!

解决方法

您在此处发布的程序仅查找要开放的设施以及如何将设施分配到住宅区。代码中的任何内容都不会导致 S 的元素改变它们的顺序,这就是为什么当你最终循环 S 时,你会得到它们原始顺序的设施。

首先,您需要以数学方式定义设施的排序方式。实现将取决于此定义。一个简单的选择是获得一些反映设施重要性的分数,并根据这些分数对设施进行排序。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...