Constraint modelling error: "check_belongs_to_model(::NonlinearExpression, ::Model)" #317
-
Dear community, I am trying to solve a stochastic optimal control problem where the goal is to minimize the total time. subjected to The When I try to simulate this, I obtain the following error: ERROR: LoadError: MethodError: no method matching check_belongs_to_model(::NonlinearExpression, ::Model) However if I implement it with a given maximum time and define the objective as a minimization problem of the expected value, i.e.,
I do not get this error. How can I solve this problem? Any help is greatly appreciated :) Example code for the first optimization problem (which gives the aforementioned error): using Distributions
using InfiniteOpt
using Ipopt
using Distributions
model = InfiniteModel(Ipopt.Optimizer)
sup = 100
Ξ = [Uniform(5, 25), Uniform(5, 25)]
@infinite_parameter(model, t in [0, 1.0], num_supports = sup)
@infinite_parameter(model, ξ[c in 1:2] ~ Ξ[c],num_supports = 400)
@variable(model, 1 <= tf <= 10, start = 1)
@variable(model, x >= 0, Infinite(t))
@variable(model, y >= 0, Infinite(t))
p = (x_n, y_n, ωx_n, ωy_n) -> x_n* y_n* ωx_n* ωy_n
@constraint(model,support_sum(-∫(p(x, y, ξ[1], ξ[2]) ,t),ξ)<=100)
@objective(model,Min,tf)
@constraint(model, 5 <= x <= 25)
@constraint(model, 5 <= y <= 25)
optimize!(model) Example code for the second problem (which works): using Distributions
using InfiniteOpt
using Ipopt
using Distributions
model = InfiniteModel(Ipopt.Optimizer)
sup = 100
Ξ = [Uniform(5, 25), Uniform(5, 25)]
@infinite_parameter(model, t in [0, 1.0], num_supports = sup)
@infinite_parameter(model, ξ[c in 1:2] ~ Ξ[c],num_supports = 400)
@variable(model, x >= 0, Infinite(t))
@variable(model, y >= 0, Infinite(t))
p = (x_n, y_n, ωx_n, ωy_n) -> x_n* y_n* ωx_n* ωy_n
@objective(model,Min,support_sum(-∫(p(x, y, ξ[1], ξ[2]) ,t),ξ))
@constraint(model, 5 <= x <= 25)
@constraint(model, 5 <= y <= 25)
optimize!(model) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hi there and welcome! You found a bug, thanks for sharing. It will be fixed by #318. Also, note that your final time problem will not minimize the final time as you currently have it posed. To use the reformulation trick with On a more minor note, you can and probably should move the variable bound constraints into |
Beta Was this translation helpful? Give feedback.
-
Dear pulsipher, Thanks alot! Actually, the full problem I am considering is an optimal control one. So I have scaled these differential equations by the parameter tf. Do I also need to reformulate the integral and scale it then? If so, could you give me a pointer how to apply the reformulation of the integral? |
Beta Was this translation helpful? Give feedback.
-
As an update, v |
Beta Was this translation helpful? Give feedback.
Hi there and welcome!
You found a bug, thanks for sharing. It will be fixed by #318.
Also, note that your final time problem will not minimize the final time as you currently have it posed. To use the reformulation trick with
tf
you will need to reformulate the integral as a differential equation that is scaled bytf
. Otherwise, as formulated thetf
has no effect on the integral and can be trivially set to1
.On a more minor note, you can and probably should move the variable bound constraints into
@variable
.