This is a reasonable way to initialize this. The only thing to change is that you should initialize BatteryCap = Array{AffExpr,2}(undef, nHours, n)
. (Linear JuMP expressions are type AffExpr
, not Float64
.)
The other option is to write it as something like
@expression(
model,
BatteryCap[k = 1:nHours, j = 1:n],
initialCapacity[j] + sum(Charging[i, j] - Discharging[i, j] for i = 2:k)
)