python - python设施开放顺序SCIP优化
问题描述
SCIP optimization
考虑到与住宅区的距离并根据该地区的居民数量加权,我试图使用它来找到设施的最佳开放顺序。
我已经建立了距离字典,以便从设施到每个住宅区的距离应该产生[2, 1, 0]
设施的顺序输出。
但是,我收到的输出是[0, 1, 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, 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
在哪里W_r = exp(population_dict[r]*sum_{s∈S} d_r,s * y_r,s)
∀r ∈ R
在这个问题上的任何帮助都会很棒!
解决方案
您在此处发布的程序仅查找要打开的设施以及如何将设施分配给住宅区。代码中的任何内容都不会导致 S 的元素改变它们的顺序,这就是为什么当你最后循环 S 时,你会以原来的顺序获得设施。
首先,您需要以数学方式定义设施的排序方式。实施将取决于此定义。一个简单的选择可能是获得一些反映设施重要性的分数,并根据这些分数对设施进行排序。
推荐阅读
- java - 如何在 java servlet 类中创建对象数组(键、值对)
- html - 如何在给定时间内仅使用不包括 JS 的 HTML/CSS 自动重定向某人或
- mongodb - 如何在 mongodb -> elasticsearch 同步时使用批处理
- git - 显示所有最近的 git 提交,无论它们是否属于本地签出分支
- java - 获取 HSQLDB 中的嵌套集合
- html - 为什么我的部分 html 代码不遵循 CSS 而其他部分是
- python - 在 python 正则表达式中转义括号
- google-cloud-platform - 停止运行 Cloud Run 服务 - 出于安全原因
- youtube - 如何查找广播 ID 的流 ID,反之亦然(YouTube 数据 API)?
- r - 年化每月回报