如何定义根据CXYPY

问题描述

我正在尝试使用CVXPY解决凸优化问题。我的值x,y分别为150和60。这是2个时隙的初始需求。目的是最大程度地降低总成本。

Total cost = x * price1 + y * price2 + penalty
Penalty = (150 - x) * 6

所以我想找到x和y的最佳值。价格1和价格2是基于需求值的。

我的代码是

import cvxpy as cp

def price_func(demand):
    prices = [14,15,.......,36.3]
    limits = [0.51,0.61,......,1]
    for i in range(len(limits)):
        if limits[i] * 155 >= demand:
            return prices[i]


x = cp.Variable()
y = cp.Variable()
x.value = 150
y.value = 60

constraints = [x + y == 210,x >= y,y >= 60]

# Form objective.
obj = cp.Minimize((x*price_func(x.value) + y*price_func(y.value)) * 0.5 + (150 - x.value) * 6)

# Form and solve problem.
prob = cp.Problem(obj,constraints)
prob.solve(warm_start=True)

但是,据我了解,我在cvxpy中的目标看起来像

minimize (var0 @ 144.6 + var1 @ 14.0) @ 0.5 

这意味着cvxpy不使用我的价格函数。而是将其作为固定值。

如何解决该问题并确保cvxpy选择正确的目标函数?

解决方法

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

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

小编邮箱: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...