最小最大优化公式的错误使用PYOMO
我正在为下面写的最小问题问题制定目标功能,
obj_func = power[1, i] for i in range(1, time_slots + 1)
model.obj = pyo.Objective(expr=obj_func, sense=pyo.minimize)
但我会收到以下错误
file“ c:\ nmbu \ temp/ipykernel_24484/3898218797.py”,第21行 obj_func = power [1,i] for in范围(1,time_slots + 1)语法:无效语法
如果我使用以下代码,它也会引发错误
obj_func = (power[1, i] for i in range(1, time_slots + 1))
model.obj = pyo.Objective(expr=obj_func, sense=pyo.minimize)
valueerror:不允许发电机
,但是我不需要优化总和,我只想优化它以获得最低的功率值[1,i]
obj_func = sum(power[1, i] for i in range(1, time_slots + 1))
model.obj = pyo.Objective(expr=obj_func, sense=pyo.minimize)
任何想法使其正常工作,因为PYOMO不直接与Min/Max直接使用?
我已经建模了 power> =(电池中的功率),因为我无法直接在PYOMO中使用Min/Max。
I am formulating my objective function for a min-max problem as written below
obj_func = power[1, i] for i in range(1, time_slots + 1)
model.obj = pyo.Objective(expr=obj_func, sense=pyo.minimize)
but I get the following error
File "C:\NMBU\TEMP/ipykernel_24484/3898218797.py", line 21
obj_func = power[1, i] for i in range(1, time_slots + 1) SyntaxError: invalid syntax
It also throws an error if I use the below code
obj_func = (power[1, i] for i in range(1, time_slots + 1))
model.obj = pyo.Objective(expr=obj_func, sense=pyo.minimize)
ValueError: Generators are not allowed
If I use the below formulation it works fine but then I don't need to optimize for the sum, I just want to optimize it to get the lowest value of power[1,i]
obj_func = sum(power[1, i] for i in range(1, time_slots + 1))
model.obj = pyo.Objective(expr=obj_func, sense=pyo.minimize)
Any ideas how to make it work, since PYOMO does not work with min/max directly?
I have already modeled power >= (power in batteries), as I cant directly use min/max in PYOMO.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您以错误的方式进行操作。 max()和min()函数是非线性的,不能在标准线性编程中使用。
如果您的目标是最大程度地减少值集合中的最小值,则需要引入附加变量,称其为
t
,生成一组约束,以强制该新变量比每个变量大在每个i 的> )中的集合元素(t> = x [i]),然后只用
t
作为您的目标函数并将其最小化。You are going about this the wrong way. The max() and min() functions are non-linear and can't be used in standard linear programming.
If your goal is to minimize the smallest value in a collection of values, you will need to introduce an additional variable, call it
t
, generate a set of constraints to force this new variable to be larger than each of the collection's elements (t >= x[i] for each i
) and then just uset
as your objective function and minimize it.