/(:: variableref,:: quadexpr)未定义
我正在尝试解决跳跃问题,这是一个非线性问题。因此,我有错误的bellow:
/(::VariableRef,::QuadExpr) is not defined. Are you trying to build a nonlinear problem? Make sure you use @NLconstraint/@NLobjective.
我正在使用@NlObjective
和@nlconstraint
。
当我在函数中调用它bvpsolve
:
function hamiltonien(z,eps)
u = z[:,8]./(2*eps*Cd2*z[:,6].*z[:,2])
h = z[:,5] .* z[:,1] .* [sin(z[i,4]) for i in size(z[:,4])] + z[:,6] .* (T(z[:,1])./z[:,3] - phi(z[:,1]) * S * z[:,2].^2 /(2*z[:,3])* (Cd1+Cd2*u^2) - g *sin(z[:,4])) - z[:,7] *Cs(z[:,2])*T(z[:,1]) + 1/eps * z[:,8] *(phi(z[:,1])*S*z[:,2] *u /(2*z[:,3]) - g/z[:,2] *cos(z[:,4]))
return 1
end
function bvpsolve(eps,N)
sys = Model(optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 5))
set_optimizer_attribute(sys,"tol",1e-8)
set_optimizer_attribute(sys,"constr_viol_tol",1e-6)
@variables(sys, begin
tf
x[1:N+1 , 1:n]
y[1:N+1 , 1:n]
0. ≤ h[1:N] ≤ 10
end)
Δt = (tf-t0)/N
# Objective
@NLobjective(sys, Min, sum(sum((x[i,j]-y[i,j])^2 for i in 1:N+1) for j in 1:n )/N + α*sum((h[i]-Δt)^2 for i in 1:N))
hx = hamiltonien(x,eps)
hy = hamiltonien(y,eps)
xpoint , ppointx = hvfun(hx,x)
ypoint , ppointy = hvfun(hy,y)
@NLconstraints(sys, begin
con_h0, x[1,1] - 3480. == 0
con_hf, x[N+1,1] - 9144. == 0
con_v0, x[1,2] - 151.67 == 0
con_vf, x[N+1,2] - 191. == 0
con_m0, x[1,3] - 69000. == 0
con_mf, x[N+1,3] - 68100. == 0
con_g0, x[1,4] - 69000. == 0
con_gf, x[N+1,4] - 68100. == 0
end)
...
end)
I'm trying to solve a problem with JuMp and it's a non linear problem. So I have the error bellow :
/(::VariableRef,::QuadExpr) is not defined. Are you trying to build a nonlinear problem? Make sure you use @NLconstraint/@NLobjective.
And I'm using @NLobjective
and @NLconstraint
.
I have the problem at the second line of this function when I call it in my function bvpsolve
:
function hamiltonien(z,eps)
u = z[:,8]./(2*eps*Cd2*z[:,6].*z[:,2])
h = z[:,5] .* z[:,1] .* [sin(z[i,4]) for i in size(z[:,4])] + z[:,6] .* (T(z[:,1])./z[:,3] - phi(z[:,1]) * S * z[:,2].^2 /(2*z[:,3])* (Cd1+Cd2*u^2) - g *sin(z[:,4])) - z[:,7] *Cs(z[:,2])*T(z[:,1]) + 1/eps * z[:,8] *(phi(z[:,1])*S*z[:,2] *u /(2*z[:,3]) - g/z[:,2] *cos(z[:,4]))
return 1
end
function bvpsolve(eps,N)
sys = Model(optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 5))
set_optimizer_attribute(sys,"tol",1e-8)
set_optimizer_attribute(sys,"constr_viol_tol",1e-6)
@variables(sys, begin
tf
x[1:N+1 , 1:n]
y[1:N+1 , 1:n]
0. ≤ h[1:N] ≤ 10
end)
Δt = (tf-t0)/N
# Objective
@NLobjective(sys, Min, sum(sum((x[i,j]-y[i,j])^2 for i in 1:N+1) for j in 1:n )/N + α*sum((h[i]-Δt)^2 for i in 1:N))
hx = hamiltonien(x,eps)
hy = hamiltonien(y,eps)
xpoint , ppointx = hvfun(hx,x)
ypoint , ppointy = hvfun(hy,y)
@NLconstraints(sys, begin
con_h0, x[1,1] - 3480. == 0
con_hf, x[N+1,1] - 9144. == 0
con_v0, x[1,2] - 151.67 == 0
con_vf, x[N+1,2] - 191. == 0
con_m0, x[1,3] - 69000. == 0
con_mf, x[N+1,3] - 68100. == 0
con_g0, x[1,4] - 69000. == 0
con_gf, x[N+1,4] - 68100. == 0
end)
...
end)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法在宏之外构建非线性表达式。
请参阅文档: https://jump.dev/jump.dev/jump.jump.jl/stable/smanual/stable/manual/manual /nlp/
您可以使用用户定义的功能,但我不明白您的示例。它硬编码
返回1
,所以我不知道u
和h
是什么。您的示例也不可复制,因为我不知道
hvfun
是什么。PS,如果您想进行更长的讨论,请在社区论坛上发布: https:https:https:https:https:https: //discourse.julialang.org/c/domain/opt/13 。具有后卫比在堆栈溢出上要容易得多。
You can't construct nonlinear expressions outside the macros.
See the documentation: https://jump.dev/JuMP.jl/stable/manual/nlp/
You can use a user-defined function, but I don't understand your example. It hard-codes
return 1
, so I don't know whatu
andh
are for.Your example is also non-reproducible, because I don't know what
hvfun
is.p.s., If you want to have a longer discussion, please post on the community forum: https://discourse.julialang.org/c/domain/opt/13. It's a bit easier to have a back-and-forward than on stack overflow.