@@ -535,8 +535,16 @@ function init_optimization!(
535535 else
536536 # Test new experimental feature:
537537
538+ model = mpc. estim. model
539+ grad, jac = mpc. gradient, mpc. jacobian
540+ nu, ny, nx̂, nϵ, nk = model. nu, model. ny, mpc. estim. nx̂, mpc. nϵ, model. nk
541+ Hp, Hc = mpc. Hp, mpc. Hc
542+ ng, nc, neq = length (mpc. con. i_g), mpc. con. nc, mpc. con. neq
543+ nZ̃, nU, nŶ, nX̂, nK = length (mpc. Z̃), Hp* nu, Hp* ny, Hp* nx̂, Hp* nk
544+ nΔŨ, nUe, nŶe = nu* Hc + nϵ, nU + nu, nŶ + ny
545+ strict = Val (true )
546+ myNaN = convert (JNT, NaN )
538547
539- J:: Vector{JNT} = zeros (JNT, 1 )
540548 ΔŨ:: Vector{JNT} = zeros (JNT, nΔŨ)
541549 x̂0end:: Vector{JNT} = zeros (JNT, nx̂)
542550 K0:: Vector{JNT} = zeros (JNT, nK)
@@ -566,11 +574,15 @@ function init_optimization!(
566574 function geqfunc_set! (geq, Z̃)
567575 return geqfunc! (geq, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g)
568576 end
569- function ∇geqfunc_set! (∇geq , Z̃)
577+ function ∇geqfunc_set! (∇geq_vec , Z̃)
570578 value_and_jacobian! (geqfunc!, geq, ∇geq, ∇geq_prep, jac, Z̃, ∇geq_context... )
579+ ∇geq_vec .= nonzeros (∇geq)
571580 return nothing
572581 end
573582
583+ I_∇geq, J_∇geq = SparseArrays. findnz (∇geq)
584+ ∇geq_structure = collect (zip (I_∇geq, J_∇geq))
585+
574586 #=
575587 # Langragian of the optimization problem:
576588 function Lfunc!(Z̃, μ, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq)
@@ -583,13 +595,14 @@ function init_optimization!(
583595
584596
585597 set = Ipopt. _VectorNonlinearOracle (;
586- mpc . con . neq ,
587- geq_min,
588- geq_max,
589- geqfunc_set!,
590- jacobian_structure,
591- ∇geqfunc_set!
598+ dimension = nZ̃ ,
599+ l = geq_min,
600+ u = geq_max,
601+ eval_f = geqfunc_set!,
602+ jacobian_structure = ∇geq_structure ,
603+ eval_jacobian = ∇geqfunc_set!
592604 )
605+ @constraint (optim, Z̃var in set)
593606 end
594607 return nothing
595608end
0 commit comments