JuMP - constraint for specific indices

Hello,

I am formulating LP problem using JuMP for energy system

one of the constraints is the nodal electricity balance, say I have indices of node, time, and technologies

How do I make a certain expression valid for a specific index?

In the example below, what I am trying to achieve is that I only want the first sum expression to apply when index x is CHP, though it will be expanded later

using DataFrames, CSV, XLSX, UnPack, JuMP, HiGHS

@constraints model begin

Electricity_Balance[i in NODES, k in NODES, t in HOURS],
            eldemand_data[i, t] + sum(Generation_Dispatch[i, x, t; x == "CHP"] / gentechdata[x; x == "CHP"].efficiency for x in GEN_TECHS) ≤
            sum(Generation_Dispatch[i, x, t] for x in GEN_TECHS) + Active_Flow[i, k, t] + 
            sum(Storage_Dispatch[i, s, t; s == "BAT"] for s in STO_TECHS)

end

but it throws this error

LoadError: At c:\Users… : unsupported operator +
LoadError: syntax: unexpected semicolon in array expression around C:\Users…

How should I formulate it better?
Or should I define different constraints that apply to these indices?

Thank you very much in advance!

Hello,

Would simply replacing x by "CHP" work ?
Don’t need to use a sum if you only want one term.

Something like that:

eldemand_data[i, t] + Generation_Dispatch[i, "CHP", t] / gentechdata["CHP"].efficiency <= ...

Or do multiple elements in GEN_TECHS can be equal to “CHP” ?
If that’s the case, you can also do:

eldemand_data[i, t] + sum(Generation_Dispatch[i, x, t] / gentechdata[x].efficiency for x in GEN_TECHS if x == "CHP") ≤ ...

Hi,

more like GEN_TECHS will include other techs beside CHP,
for example CHP, HeatPumps, Boilers, etc.
so it is like a subset of the GEN_TECHS set

I did not put them just to show my minimum example

but maybe I can just put like this?

eldemand_data[i, t] + sum(Generation_Dispatch[i, x, t] / gentechdata[x].efficiency for x in GEN_TECHS if x == ["CHP", "HeatPumps", "Boilers"]) ≤ ...

thanks for the suggested code!

Oh, ok

If the subset is always included in GEN_TECHS, you can write directly the sum on the subset like this:

eldemand_data[i, t] + sum(Generation_Dispatch[i, x, t] / gentechdata[x].efficiency for x in ["CHP", "HeatPumps", "Boilers"]) ≤ ...
2 Likes

Thanks!

this works as intended!

1 Like