简体   繁体   中英

Error in min max optimization formulation using PYOMO

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM