Hello,
Pyomo is having trouble generating constraints that contain summations over empty sets.
For example, when trying the following (note that this is a ConcreteModel where I am using list of objects as sets):
def _p_balance_EQ(m, op, bus):
return op.demand[bus.name] * (bus.pf) == \
sum(m.gen_p[op, gen] for gen in m.IDX_gen if gen.bus == bus.name) + \
sum(m.flow_p_r[op, line] for line in m.IDX_lin if line.toBus == bus.name) - \
sum(m.flow_p_s[op, line] for line in m.IDX_lin if line.fromBus == bus.name)
model.p_balance_EQ = pyo.Constraint(model.IDX_op,
model.IDX_bus,
rule=_p_balance_EQ)
I get the following error:
ValueError: Constraint 'q_balance_EQ[OperatingPoint(T4),Bus(B39)]' does not have a proper value. Found 'True'
Expecting a tuple or equation. Examples:
summation(model.costs) == model.income
(0, model.price[item], 50)
Instead, if I write it like this (i.e. explicitly forcing summation terms that could be over empty sets to be equal to 0) no error is raised and the optimiser works fine.
def _p_balance_EQ(m, op, bus):
local_gen = [gen for gen in m.IDX_gen if gen.bus == bus.name]
incoming_lines = [line for line in m.IDX_lin if line.tomBus == bus.name]
outgoing_lines = [line for line in m.IDX_lin if line.fromBus == bus.name]
if len(local_gen) == 0:
local_gen_p = 0
else:
local_gen_p = sum(m.gen_p[op, gen] for gen in local_gen)
if len(incoming_lines) == 0:
incoming_flows = 0
else:
incoming_flows = sum(m.flow_p[op, line] for line in incoming_lines)
if len(outgoing_lines) == 0:
outgoing_flows = 0
else:
outgoing_flows = sum(m.flow_p[op, line] for line in outgoing_lines)
return local_gen_p + incoming_flows - outgoing_flows + \
m.p_slack_up[op, bus] - m.p_slack_dn[op, bus] == op.demand[bus.name] * bus.pf
model.p_balance_EQ = pyo.Constraint(model.IDX_op,
model.IDX_bus,
rule=_p_balance_EQ)
My question are:
1. is there a way to make the first approach work? am i missing something?
2. does the pyomo team plan to include such capability in the future (i.e. internal checking to see if some terms of the constraints are summations over empty sets and replace them with 0). this will greatly simplify code-writing and make our lives easier.
thanks in advance