Skip to content

Commit d42013d

Browse files
committed
add test for con_nonlinprog_i methods
1 parent 0876fb7 commit d42013d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/controller/nonlinmpc.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ function init_optimization!(mpc::NonLinMPC)
261261
function con_nonlinprog_i(i, ΔŨtup::NTuple{N, Float64}) where {N}
262262
C = get_tmp(C_cache, ΔŨtup[1])
263263
if ΔŨtup != last_ΔŨtup_float
264-
= get_tmp(Ŷ_cache, ΔŨtup_1)
264+
= get_tmp(Ŷ_cache, ΔŨtup[1])
265265
ΔŨ = collect(ΔŨtup)
266266
Ŷ[:] = predict(mpc, model, ΔŨ)
267267
C[:] = con_nonlinprog(mpc, model, Ŷ, ΔŨ)
@@ -272,7 +272,7 @@ function init_optimization!(mpc::NonLinMPC)
272272
function con_nonlinprog_i(i, ΔŨtup::NTuple{N, Real}) where {N}
273273
C = get_tmp(C_cache, ΔŨtup[1])
274274
if ΔŨtup != last_ΔŨtup_dual
275-
= get_tmp(Ŷ_cache, ΔŨtup_1)
275+
= get_tmp(Ŷ_cache, ΔŨtup[1])
276276
ΔŨ = collect(ΔŨtup)
277277
Ŷ[:] = predict(mpc, model, ΔŨ)
278278
C[:] = con_nonlinprog(mpc, model, Ŷ, ΔŨ)

test/test_predictive_control.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ end
173173
nmpc5 = NonLinMPC(nonlinmodel, Mwt=[0], Nwt=[0], Cwt=Inf, Ewt=1, JE=JE, Hp=Hp, Hc=1)
174174
u = moveinput!(nmpc5)
175175
@test u [1] atol=1e-2
176+
nmpc6 = setconstraint!(NonLinMPC(nonlinmodel, Cwt=Inf), ŷmin=[-1])
177+
C_Ŷmax_end = nmpc6.optim.nlp_model.operators.registered_multivariate_operators[end].f
178+
@test C_Ŷmax_end(Float64.((1.0, 1.0))) 0.0 # test con_nonlinprog_i(i,::NTuple{N, Float64})
179+
@test C_Ŷmax_end(Float32.((1.0, 1.0))) 0.0 # test con_nonlinprog_i(i,::NTuple{N, Real})
176180
end
177181

178182
@testset "NonLinMPC other methods" begin

0 commit comments

Comments
 (0)