指数项上的 SCIP 目标函数快和

问题描述

我在对指数方程求和并使用时遇到问题 这就是目标函数。

我可以在目标函数中使用指数方程吗? 如果不是,是否可以将指数函数作为 约束?

对此的任何帮助将不胜感激。

import pandas as pd
from pyscipopt import Model,quicksum,multidict,exp

num_fac_to_open = 1
order_to_open = []
opened_fac = []
closed_fac = [0,1,2]
S = [0,2]
R = [10,11,12]
distance_dict = {(0,10): 300.8,(1,10): 150.6,(2,10): 1567.8,(0,11): 1241.0,11): 2012.1,11): 789.2,12): 563.2,12): 1798.3,12): 946.3}
population_dict = {10:54,11:46,12:22}

# 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:
    want_list = (distance_dict[s,r]*y[s,r] for s in S)
    want_list_quicksum = quicksum(want_list)
    exp_power = population_dict[r]*want_list_quicksum
    w = exp(exp_power)

model.setObjective(quicksum([w]),'minimize')
model.optimize()

这段代码出现的错误是:

Traceback (most recent call last):
  File "stack_overflow_code.py",line 38,in <module>
    model.setObjective(quicksum([w]),'minimize')
  File "src/pyscipopt/scip.pyx",line 1246,in pyscipopt.scip.Model.setObjective
AssertionError: given coefficients are neither Expr or number but SumExpr

据我了解,目标函数的格式应该是(这是我打印 exp_power 得到的结果):

Expr({Term(): 0.0,Term(x4): 12390.400000000001,Term(x8): 39562.6,Term(x12): 20818.6})

但是,一旦加上指数项(w),格式就变成:

exp(sum(0.0,prod(12390.400000000001,x4),prod(39562.6,x8),prod(20818.6,x12)))

进一步,当加入quicksum[w]时,格式变为:

sum(0.0,exp(sum(0.0,x12))))

目标是最小化\sum_{r=1}^N W_r

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

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