Dummy/phantom constraints #301
-
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Welcome @DarioSlaifsteinSk! Interesting model, let me do my best to answer your questions. With regard to the "dummy" constraints, this has to do with defining point variables which you are currently doing implicitly in your balance constraints. Point variables inherit all the properties of their parent infinite variable (e.g., bounds), but these can be changed to differ from their corresponding infinite variable. The good news here is that although the simple printing routine shows these point variable bounds as extra constraints (due to printing all the info of each point variable), the relationship between point variables and infinite variables is rigorously considered when the model is transcribed such that the model actually solved by Ipopt doesn't actually include these "redundant" constraints. However, the argument can be made to make this more transparent when printing which relates to #148. Your balance constraints don't exactly do what I think you intend. Consider for instance: model[:thBalance]=@constraint(model, [tw ∈ Dtw], Pst[tw]+model[:Phpe](tw).*ηHP+model[:Ptess](tw) .== Plt[tw]) Here, I believe using Interpolations
Pst_interp = linear_interpolation(Dtw, Pst)
@parameter_function(model, Pst_cont == (t) -> Pst_interp(t)) # make InfiniteOpt compatible Pst(t) work for arbitrary times
Plt_interp = linear_interpolation(Dtw, Plt)
@parameter_function(model, Plt_cont == (t) -> Plt_interp(t)) # make InfiniteOpt compatible Plt(t) work for arbitrary times Then we can rewrite the balance constraint in continuous time: @constraint(model, thBalance, Pst_cont + model[:Phpe] .* ηHP + model[:Ptess] .== Plt_cont) I would also redefine your infinite parameter @infinite_parameter(model, t in [0, tend], supports = sets.dTime, derivative_method = FiniteDifference(Backward()) ) So you ensure you are using the supports you include in I am also not quite sure why you have As for why it is hanging at build_optimizer_model!(model) and see if that runs with the suggested changes. If that works without issue then, please share the Ipopt output when you |
Beta Was this translation helpful? Give feedback.
-
As you said the whole problem came from the use of the discrete time data. A couple of hours later after the post I found yp=hcat(data["grid"].λ[1:length(Dtw), 1])
λbuy = parameter_function(t, name = "buyPrice") do t_supp
if t_supp <= Dtw[1]
return yp[1]
end
if t_supp >= Dtw[end]
return yp[end]
end
k = 2
while t_supp > Dtw[k]
k += 1
end
return yp[k-1]
end But this is "too" local and I´d prefer the syntax you did with PS: the timestep |
Beta Was this translation helpful? Give feedback.
-
I am glad it works! I opened #302 to track adding to the documentation to make this more obvious in the future. For a "zero order hold object", the most efficient way would be something like: function zero_order_time_index(ts, t)
inds = searchsorted(ts, t)
if !isempty(inds) || inds.start == 1
return inds.start
elseif inds.start > length(ts)
return length(ts)
else # we don't have an exact match so let's choose the earlier time index
return inds.stop
end
end
@parameter_function(model, λbuy == (t) -> yp[zero_order_time_index(Dtw, t)]) Note, I haven't run the above so it may have a minor typo/bug. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Welcome @DarioSlaifsteinSk!
Interesting model, let me do my best to answer your questions.
With regard to the "dummy" constraints, this has to do with defining point variables which you are currently doing implicitly in your balance constraints. Point variables inherit all the properties of their parent infinite variable (e.g., bounds), but these can be changed to differ from their corresponding infinite variable. The good news here is that although the simple printing routine shows these point variable bounds as extra constraints (due to printing all the info of each point variable), the relationship between point variables and infinite variables is rigorously considered when the model i…