Skip to content

Commit fa84fb3

Browse files
committed
added: validate economic function JE argument signature
1 parent fd1f7b9 commit fa84fb3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/controller/nonlinmpc.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct NonLinMPC{
5454
model = estim.model
5555
nu, ny, nd, nx̂ = model.nu, model.ny, model.nd, estim.nx̂
5656
= copy(model.yop) # dummy vals (updated just before optimization)
57+
validate_JE(NT, JE)
5758
validate_weights(model, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt)
5859
# convert `Diagonal` to normal `Matrix` if required:
5960
M_Hp = Hermitian(convert(Matrix{NT}, M_Hp), :L)
@@ -284,6 +285,21 @@ function NonLinMPC(
284285
)
285286
end
286287

288+
"""
289+
validate_JE(NT, JE) -> nothing
290+
291+
Validate `JE` function argument signature
292+
"""
293+
function validate_JE(NT, JE)
294+
if !hasmethod(JE, Tuple{Vector{NT}, Vector{NT}, Vector{NT}, Any})
295+
error(
296+
"the economic function has no method with type signature "*
297+
"JE(UE::Vector{$(NT)}, ŶE::Vector{$(NT)}, D̂E::Vector{$(NT)}, p::Any)"
298+
)
299+
end
300+
return nothing
301+
end
302+
287303
"""
288304
addinfo!(info, mpc::NonLinMPC) -> info
289305

test/test_predictive_control.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ end
521521

522522
@test_throws ArgumentError NonLinMPC(nonlinmodel, Hp=15, Ewt=[1, 1])
523523
@test_throws ArgumentError NonLinMPC(nonlinmodel)
524+
@test_throws ErrorException NonLinMPC(nonlinmodel, Hp=15, JE=(_,_,_)->0.0)
524525
end
525526

526527
@testset "NonLinMPC moves and getinfo" begin

0 commit comments

Comments
 (0)