Multi indexed constraints or objectives in Pyomo

649 views Asked by At

I have a fairly basic MILP that I'm trying to solve, but while my code runs ok I do not actually get any values. I think this is because of my objective function (since changing it to something trivial does produce an answer):

def OPEX (m):
    return sum (m.Q_ng[u,t]*m.ng_price[t] + m.E_imp[t]*m.el_price_imp[t] - m.E_exp[t]*m.el_price_exp[t] for u in m.U for t in m.P)
m.obj = Objective(rule=OPEX)

I need to minimise the sum over u and t, is this how you would go about it?

1

There are 1 answers

0
Sebastian On

My problem ended up being how I wrote my constraints. According to the book by William E. Hart, Carl Laird, Jean-Paul Watson and David L. Woodruff: Pyomo - Optimization Modeling in Python, you can write functions with _rule appended to them and then when you define your constraint just name it the same without using rule, e.g.

def BOIL_off_rule (m,t):
    return (0,m.f["BOIL",t]*Boiler_max,Boiler_max*y["BOIL",t])
m.BOIL_off = Constraint(m.P)

However this doesn't seem to work (possibly because in the book they use coopr which includes other libraries / modules and not just Pyomo)