首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python工具开放订单SCIP优化

python工具开放订单SCIP优化
EN

Stack Overflow用户
提问于 2021-01-19 12:13:00
回答 1查看 44关注 0票数 1

我正在尝试使用SCIP optimization来寻找设施的最佳开放顺序,给定距离居民区的距离,并对该地区的居民数量进行加权。

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

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

此外,如果我将alpha更改为正值,则不会产生任何影响。

代码语言:javascript
复制
import pandas as pd
from pyscipopt import Model, quicksum, multidict, exp
num_fac_to_open = 3
order_to_open = []
opened_fac = []
closed_fac = [0, 1, 2]
# Facility id
S = [0, 1, 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, (1, 11): 2012.1, (2, 11): 10009.2, (0, 12): 3.2, (1, 12): 1798.3, (2, 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

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

在这个问题上的任何帮助都是很棒的!

EN

回答 1

Stack Overflow用户

发布于 2021-01-21 23:17:52

您在这里发布的程序仅查找要打开的设施以及如何将这些设施分配给居民区。代码中没有任何东西会导致S的元素改变它们的顺序,这就是为什么当你最后在S上循环时,你会得到它们原来的顺序。

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65785373

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档