Add constraints to Binary Flow

Hi there,
i am trying to add a spinning reserve constraint to my operational model.
here is the code:

srblock = Block()

def spinning_reserve_rule(m, t):
    expr = om.BinaryFlow.status[generator, b_el, t] * (om.flows[generator, b_el].max[t]*
                                                       om.flows[generator, b_el].nominal_value-
           >=feedin['demand_el'][t] * SPINNING_RESERVE
    return expr

srblock.sr_constr = Constraint(om.TIMESTEPS, rule=spinning_reserve_rule)
om.add_component('Spinning Reserve', srblock)

When i run the code, i get:
“ValueError: Solver unable to handle quadratic expressions. Constraint at issue: ‘Spinning Reserve.sr_constr[0]’”

I don’t really see the problem. Why is that constraint considered a qudratic expression? Basically its a binary variable multiplied with a flow variable, similar to the constraints added to BinaryFlows within oemof.solph.blocks.BinaryFlows.

Thanks in advance for your advice!

Yeah the problem is that your constraint is… well: not linear, gurobi might be able to handle it, though I think it only allows to solve quadratic programs (only quadratic in objective function, but linear in constraints).

Inside our (oemof) implementation, there are only linear equations.

So you need to either find another constraint or you can replace multiplication of binary with continuous variables by 4 other constraints:

If we have a quadratic term: z = yx (y is binary, x is continuous)
and if x is is bounded by L ≤ x ≤ U we can transform the
quadratic term:
z ≤ Uy
z ≥ Ly
z ≤ x − L(1 − y )
z ≥ x − U(1 − y )

Hope this helps


Thanks. for the fast response. It helped me to understand the problem.

I came up with a simple solution for the spinning reserve constraint.

Before i had this (simplified, for 1 generator):
z>=y*(max-x) … with max and f are constants , y[0,1], and x==flow
which would lead to the nonlinear correlation yx.
Now i changed this constraint to
assuming that the requirement if x=0 then y=0 is already satisfied. So in case y=0 , yx wouln’t give me any new information.

I will implement it it now for the sum of all (n) generator flows as z>=sum(yi*maxi)-sum(xi) for i = 0,…,n

Text and images licensed under CC BY 4.0Data licensed under CC0 1.0Code licensed under MITSite terms of serviceOpenmod mailing list.