Skip to content

Commit e77e930

Browse files
committed
Merge branch 'main' into bench_cont_2
2 parents 0646d5b + 11ea3df commit e77e930

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

src/precompile.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,18 @@ exmpc.estim()
7979
u = exmpc([55, 30])
8080
sim!(exmpc, 2, [55, 30])
8181

82-
f(x,u,_,model) = model.A*x + model.Bu*u
83-
h(x,_,model) = model.C*x
82+
function f!(xnext, x, u, _, model)
83+
mul!(xnext, model.A , x)
84+
mul!(xnext, model.Bu, u, 1, 1)
85+
return nothing
86+
end
87+
function h!(y, x, _, model)
88+
mul!(y, model.C, x)
89+
return nothing
90+
end
8491

8592
nlmodel = setop!(
86-
NonLinModel(f, h, Ts, 2, 2, 2, solver=nothing, p=model),
93+
NonLinModel(f!, h!, Ts, 2, 2, 2, solver=nothing, p=model),
8794
uop=[10, 10], yop=[50, 30]
8895
)
8996
y = nlmodel()
@@ -118,7 +125,7 @@ u = nmpc_mhe([55, 30])
118125
sim!(nmpc_mhe, 2, [55, 30])
119126

120127
function JE( _ , Ŷe, _ , R̂y)
121-
= Ŷe[3:end]
128+
= @views Ŷe[3:end]
122129
= R̂y -
123130
return dot(Ȳ, Ȳ)
124131
end

test/2_test_state_estim.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,16 @@ end
10351035
info = getinfo(mhe5)
10361036
@test info[:x̂] x̂ atol=1e-9
10371037
@test info[:Ŷ][end-1:end] [50, 30] atol=1e-9
1038+
1039+
# coverage of the branch with error termination status (with an infeasible problem):
1040+
mhe_infeas = MovingHorizonEstimator(nonlinmodel, He=1, Cwt=Inf)
1041+
mhe_infeas = setconstraint!(mhe_infeas, v̂min=[1, 1], v̂max=[-1, -1])
1042+
@test_logs(
1043+
(:error, "MHE terminated without solution: estimation in open-loop "*
1044+
"(more info in debug log)"),
1045+
preparestate!(mhe_infeas, [0, 0], [0])
1046+
)
1047+
10381048
# for coverage of NLP functions, the univariate syntax of JuMP.@operator
10391049
mhe6 = MovingHorizonEstimator(nonlinmodel, He=1, Cwt=Inf)
10401050
setconstraint!(mhe6, v̂min=[-51,-52], v̂max=[53,54])

test/3_test_predictive_control.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ end
121121
ΔU_diff = diff(getinfo(mpc7)[:U])
122122
@test ΔU_diff[[2, 4, 5, 7, 8, 9]] zeros(6) atol=1e-9
123123

124+
# coverage of the branch with error termination status (with an infeasible problem):
125+
mpc_infeas = LinMPC(linmodel2, Hp=1, Hc=1, Cwt=Inf)
126+
mpc_infeas = setconstraint!(mpc_infeas, umin=[+1], umax=[-1])
127+
preparestate!(mpc_infeas, [0], [0])
128+
@test_logs(
129+
(:error, "MPC terminated without solution: returning last solution shifted "*
130+
"(more info in debug log)"),
131+
moveinput!(mpc_infeas, [0], [0])
132+
)
133+
124134
@test_throws DimensionMismatch moveinput!(mpc1, [0,0,0])
125135
@test_throws DimensionMismatch moveinput!(mpc1, [0], [0,0])
126136
@test_throws DimensionMismatch moveinput!(mpc1; D̂ = fill(0, mpc1.Hp+1))
@@ -823,6 +833,17 @@ end
823833
ΔU_diff = diff(getinfo(nmpc11)[:U])
824834
@test ΔU_diff[[2, 4, 5, 7, 8, 9]] zeros(6) atol=1e-9
825835

836+
# coverage of the branch with error termination status (with an infeasible problem):
837+
nmpc_infeas = NonLinMPC(nonlinmodel, Hp=1, Hc=1, Cwt=Inf)
838+
nmpc_infeas = setconstraint!(nmpc_infeas, umin=[+1], umax=[-1])
839+
preparestate!(nmpc_infeas, [0], [0])
840+
@test_logs(
841+
(:error, "MPC terminated without solution: returning last solution shifted "*
842+
"(more info in debug log)"),
843+
moveinput!(nmpc_infeas, [0], [0])
844+
)
845+
846+
826847
@test_nowarn ModelPredictiveControl.info2debugstr(info)
827848
end
828849

0 commit comments

Comments
 (0)