Skip to content

Commit 1cec44e

Browse files
committed
debug: ensure no variable clash with _opt
1 parent 4ea21f2 commit 1cec44e

1 file changed

Lines changed: 32 additions & 32 deletions

File tree

src/controller/nonlinmpc.jl

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -554,11 +554,11 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
554554
Ue = [U; U[(end - mpc.estim.model.nu + 1):end]]
555555
Ŷe = [ŷ; Ŷ]
556556
D̂e = [d; D̂]
557-
JE = mpc.JE(Ue, Ŷe, D̂e, mpc.p, ϵ)
558-
LHS = Vector{NT}(undef, mpc.con.nc)
559-
mpc.con.gc!(LHS, Ue, Ŷe, D̂e, mpc.p, ϵ)
560-
info[:JE] = JE
561-
info[:gc] = LHS
557+
JE_opt = mpc.JE(Ue, Ŷe, D̂e, mpc.p, ϵ)
558+
gc_opt = Vector{NT}(undef, mpc.con.nc)
559+
mpc.con.gc!(gc_opt, Ue, Ŷe, D̂e, mpc.p, ϵ)
560+
info[:JE] = JE_opt
561+
info[:gc] = gc_opt
562562
info[:sol] = JuMP.solution_summary(mpc.optim, verbose=true)
563563
# --- objective derivatives ---
564564
model, optim, con = mpc.estim.model, mpc.optim, mpc.con
@@ -574,10 +574,10 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
574574
ΔŨ = zeros(NT, nΔŨ)
575575
x̂0end = zeros(NT, nx̂)
576576
K = zeros(NT, nK)
577-
Ue, Ŷe = zeros(NT, nUe), zeros(NT, nŶe)
578-
U0, Ŷ0 = zeros(NT, nU), zeros(NT, nŶ)
579-
Û0, X̂0 = zeros(NT, nU), zeros(NT, nX̂)
580-
gc, g = zeros(NT, nc), zeros(NT, ng)
577+
Ue, Ŷe = zeros(NT, nUe), zeros(NT, nŶe)
578+
U0, Ŷ0 = zeros(NT, nU), zeros(NT, nŶ)
579+
Û0, X̂0 = zeros(NT, nU), zeros(NT, nX̂)
580+
gc, g = zeros(NT, nc), zeros(NT, ng)
581581
gi, geq = zeros(NT, ngi), zeros(NT, neq)
582582
J_cache = (
583583
Cache(ΔŨ), Cache(x̂0end), Cache(Ue), Cache(Ŷe), Cache(U0), Cache(Ŷ0),
@@ -589,9 +589,9 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
589589
return obj_nonlinprog!(Ŷ0, U0, mpc, Ue, Ŷe, ΔŨ)
590590
end
591591
if !isnothing(mpc.hessian)
592-
_, ∇J, ∇²J = value_gradient_and_hessian(J!, mpc.hessian, mpc.Z̃, J_cache...)
592+
_, ∇J_opt, ∇²J_opt = value_gradient_and_hessian(J!, mpc.hessian, mpc.Z̃, J_cache...)
593593
else
594-
J, ∇²J = gradient(J!, mpc.gradient, mpc.Z̃, J_cache...), nothing
594+
J_opt, ∇²J_opt = gradient(J!, mpc.gradient, mpc.Z̃, J_cache...), nothing
595595
end
596596
# --- inequality constraint derivatives ---
597597
∇g_cache = (
@@ -604,7 +604,7 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
604604
gi .= @views g[i_g]
605605
return nothing
606606
end
607-
g, ∇g = value_and_jacobian(gi!, gi, mpc.jacobian, mpc.Z̃, ∇g_cache...)
607+
g_opt, ∇g_opt = value_and_jacobian(gi!, gi, mpc.jacobian, mpc.Z̃, ∇g_cache...)
608608
if !isnothing(mpc.hessian) && ngi > 0
609609
nonlincon = optim[:nonlinconstraint]
610610
λi = try
@@ -620,7 +620,7 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
620620
rethrow()
621621
end
622622
end
623-
∇²gi_cache = (
623+
∇²g_cache = (
624624
Cache(ΔŨ), Cache(x̂0end), Cache(Ue), Cache(Ŷe), Cache(U0), Cache(Ŷ0),
625625
Cache(Û0), Cache(K), Cache(X̂0),
626626
Cache(gc), Cache(geq), Cache(g), Cache(gi)
@@ -630,9 +630,9 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
630630
gi .= @views g[i_g]
631631
return dot(λi, gi)
632632
end
633-
∇²ℓg = hessian(ℓ_gi, mpc.hessian, mpc.Z̃, Constant(λi), ∇²gi_cache...)
633+
∇²ℓg_opt = hessian(ℓ_gi, mpc.hessian, mpc.Z̃, Constant(λi), ∇²g_cache...)
634634
else
635-
∇²ℓg = nothing
635+
∇²ℓg_opt = nothing
636636
end
637637
# --- equality constraint derivatives ---
638638
geq_cache = (
@@ -644,7 +644,7 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
644644
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K, X̂0, gc, g, geq, mpc, Z̃)
645645
return nothing
646646
end
647-
geq, ∇geq = value_and_jacobian(geq!, geq, mpc.jacobian, mpc.Z̃, geq_cache...)
647+
geq_opt, ∇geq_opt = value_and_jacobian(geq!, geq, mpc.jacobian, mpc.Z̃, geq_cache...)
648648
if !isnothing(mpc.hessian) && con.neq > 0
649649
nonlinconeq = optim[:nonlinconstrainteq]
650650
λeq = try
@@ -669,25 +669,25 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
669669
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K, X̂0, gc, g, geq, mpc, Z̃)
670670
return dot(λeq, geq)
671671
end
672-
∇²ℓgeq = hessian(ℓ_geq, mpc.hessian, mpc.Z̃, Constant(λeq), ∇²geq_cache...)
672+
∇²ℓgeq_opt = hessian(ℓ_geq, mpc.hessian, mpc.Z̃, Constant(λeq), ∇²geq_cache...)
673673
else
674-
∇²ℓgeq = nothing
674+
∇²ℓgeq_opt = nothing
675675
end
676-
info[:∇J] =J
677-
info[:∇²J] = ∇²J
678-
info[:g] = g
679-
info[:∇g] =g
680-
info[:∇²ℓg] = ∇²ℓg
681-
info[:geq] = geq
682-
info[:∇geq] =geq
683-
info[:∇²ℓgeq] = ∇²ℓgeq
676+
info[:∇J] =J_opt
677+
info[:∇²J] = ∇²J_opt
678+
info[:g] = g_opt
679+
info[:∇g] =g_opt
680+
info[:∇²ℓg] = ∇²ℓg_opt
681+
info[:geq] = geq_opt
682+
info[:∇geq] =geq_opt
683+
info[:∇²ℓgeq] = ∇²ℓgeq_opt
684684
# --- non-Unicode fields ---
685-
info[:nablaJ] =J
686-
info[:nabla2J] = ∇²J
687-
info[:nablag] =g
688-
info[:nabla2lg] = ∇²ℓg
689-
info[:nablageq] =geq
690-
info[:nabla2lgeq] = ∇²ℓgeq
685+
info[:nablaJ] =J_opt
686+
info[:nabla2J] = ∇²J_opt
687+
info[:nablag] =g_opt
688+
info[:nabla2lg] = ∇²ℓg_opt
689+
info[:nablageq] =geq_opt
690+
info[:nabla2lgeq] = ∇²ℓgeq_opt
691691
return info
692692
end
693693

0 commit comments

Comments
 (0)