最小最大优化公式的错误使用PYOMO

发布于 2025-01-27 21:03:35 字数 867 浏览 5 评论 0原文

我正在为下面写的最小问题问题制定目标功能,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

欲拥i 2025-02-03 21:03:35

您以错误的方式进行操作。 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 use t as your objective function and minimize it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文