Skip to content

Commit 8883034

Browse files
committed
wip: starting to work!
1 parent 0927d5e commit 8883034

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/controller/nonlinmpc.jl

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
595608
end

src/general.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ function limit_solve_time(optim::GenericModel, Ts)
5858
end
5959

6060
"Init a differentiation result matrix as dense or sparse matrix, as required by `backend`."
61-
init_diffmat(T, backend::AbstractADType, _ , nx , ny) = Matrix{T}(undef, ny, nx)
62-
init_diffmat(T, backend::AutoSparse ,prep , _ , _ ) = similar(sparsity_pattern(prep), T)
61+
init_diffmat(T, ::AbstractADType, _ , nx , ny) = Matrix{T}(undef, ny, nx)
62+
init_diffmat(T, ::AutoSparse ,prep , _ , _ ) = similar(sparsity_pattern(prep), T)
6363

6464
"Verify that x and y elements are different using `!==`."
6565
isdifferent(x, y) = any(xi !== yi for (xi, yi) in zip(x, y))

0 commit comments

Comments
 (0)