1

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)
Sundar R
  • 13,776
  • 6
  • 49
  • 76

1 Answers1

0

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 what u and h 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.

Oscar Dowson
  • 2,395
  • 1
  • 5
  • 13