I have an energy system optimisation model with storage. The energy balance for the storage technology looks something like this:
e[t] = e[t-1] + eff * c[t] - d[t]
The only real decision variables are the charging and discharging (c
and d
) for the energy level you only really need to specify one point. Most people still declare e
a variable and hope that the solver will realise this however, just cause it’s simpler.
For various reasons, that’s not an option for me, so instead of a variable I define an array of expressions:
ax = 1:8760 # hours in a year
e = AxisArray(
Array{GenericAffExpr,dimension}(undef, length.(ax)...),
ax...
)
e0 = @variable(m, e0 >= 0) # Initial energy level, decision variable
e[1] = @expression(m, 1*e0)
for t in ax[2:end]
e[t] = @expression(m, e[t-1] + eff * c[t] - d[t])
end
Doing this however is really slow! Much slower than just letting Gurobi figure this out. Not only that, but Julia crashes when it tries to solve this.
I could try to write something like this:
e[2:end] = @expression(m, [t=2:end], sum(eff * c[tt] - d[tt] for tt=1:t)
But my representation of time is more complex than that so it’s a lot harder than the above expression would make it seem. Also I’m not sure if that would help me with my problem of Julia crashing, so I’m reticent to do it.
Any suggestions? I assume I can’t be the only one to have faced such a problem. Is the problem that with the loop I’m nesting expressions?