diff --git a/Project.toml b/Project.toml index d2e94d89a..9d3ad220d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ModelPredictiveControl" uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c" authors = ["Francis Gagnon"] -version = "1.8.1" +version = "1.8.2" [deps] ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e" diff --git a/benchmark/2_bench_state_estim.jl b/benchmark/2_bench_state_estim.jl index 2967d4550..078796e28 100644 --- a/benchmark/2_bench_state_estim.jl +++ b/benchmark/2_bench_state_estim.jl @@ -303,6 +303,7 @@ mhe_pendulum_ipopt_curr = MovingHorizonEstimator( ) mhe_pendulum_ipopt_curr = setconstraint!(mhe_pendulum_ipopt_curr; v̂min, v̂max) JuMP.unset_time_limit_sec(mhe_pendulum_ipopt_curr.optim) +JuMP.set_attribute(mhe_pendulum_ipopt_curr.optim, "tol", 1e-7) optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false) direct = false @@ -311,6 +312,7 @@ mhe_pendulum_ipopt_pred = MovingHorizonEstimator( ) mhe_pendulum_ipopt_pred = setconstraint!(mhe_pendulum_ipopt_pred; v̂min, v̂max) JuMP.unset_time_limit_sec(mhe_pendulum_ipopt_pred.optim) +JuMP.set_attribute(mhe_pendulum_ipopt_pred.optim, "tol", 1e-7) optim = JuMP.Model(MadNLP.Optimizer, add_bridges=false) direct = true @@ -319,6 +321,7 @@ mhe_pendulum_madnlp_curr = MovingHorizonEstimator( ) mhe_pendulum_madnlp_curr = setconstraint!(mhe_pendulum_madnlp_curr; v̂min, v̂max) JuMP.unset_time_limit_sec(mhe_pendulum_madnlp_curr.optim) +JuMP.set_attribute(mhe_pendulum_madnlp_curr.optim, "tol", 1e-7) optim = JuMP.Model(MadNLP.Optimizer, add_bridges=false) direct = false @@ -327,6 +330,7 @@ mhe_pendulum_madnlp_pred = MovingHorizonEstimator( ) mhe_pendulum_madnlp_pred = setconstraint!(mhe_pendulum_madnlp_pred; v̂min, v̂max) JuMP.unset_time_limit_sec(mhe_pendulum_madnlp_pred.optim) +JuMP.set_attribute(mhe_pendulum_madnlp_pred.optim, "tol", 1e-7) samples, evals, seconds = 10, 1, 15*60 CASE_ESTIM["Pendulum"]["MovingHorizonEstimator"]["Ipopt"]["Current form"] = diff --git a/test/2_test_state_estim.jl b/test/2_test_state_estim.jl index 846416f61..6b05651d2 100644 --- a/test/2_test_state_estim.jl +++ b/test/2_test_state_estim.jl @@ -916,6 +916,7 @@ end nonlinmodel = setop!(nonlinmodel, uop=[10,50], yop=[50,30], dop=[5]) mhe1 = MovingHorizonEstimator(nonlinmodel, He=2) + JuMP.set_attribute(mhe1.optim, "tol", 1e-7) preparestate!(mhe1, [50, 30], [5]) x̂ = updatestate!(mhe1, [10, 50], [50, 30], [5]) @test x̂ ≈ zeros(6) atol=1e-9 @@ -944,6 +945,7 @@ end @test mhe1([5]) ≈ [51, 32] atol=1e-3 mhe1 = MovingHorizonEstimator(nonlinmodel, He=2, nint_u=[1, 1], nint_ym=[0, 0], direct=false) + JuMP.set_attribute(mhe1.optim, "tol", 1e-7) preparestate!(mhe1, [50, 30], [5]) x̂ = updatestate!(mhe1, [10, 50], [50, 30], [5]) @test x̂ ≈ zeros(6) atol=1e-9 @@ -1065,7 +1067,8 @@ end updatestate!(mhe1, [0.0], y) updatestate!(model, [0.1]) end - @test mhe1() ≈ model() atol = 1e-9 + preparestate!(mhe1, model()) + @test mhe1() ≈ model() atol = 1e-6 model = NonLinModel(f, h, 10.0, 1, 1, 1, solver=nothing) mhe2 = MovingHorizonEstimator(model, nint_u=[1], He=3, direct=false) for i = 1:40 @@ -1074,7 +1077,8 @@ end updatestate!(mhe2, [0.0], y) updatestate!(model, [0.1]) end - @test mhe2() ≈ model() atol = 1e-9 + preparestate!(mhe2, model()) + @test mhe2() ≈ model() atol = 1e-6 end @testitem "MovingHorizonEstimator fallbacks for arrival covariance estimation" setup=[SetupMPCtests] begin diff --git a/test/3_test_predictive_control.jl b/test/3_test_predictive_control.jl index 8f6876053..f8ffa4282 100644 --- a/test/3_test_predictive_control.jl +++ b/test/3_test_predictive_control.jl @@ -1022,12 +1022,13 @@ end end @testitem "NonLinMPC constraint violation" setup=[SetupMPCtests] begin - using .SetupMPCtests, ControlSystemsBase, LinearAlgebra + using .SetupMPCtests, ControlSystemsBase, LinearAlgebra, JuMP gc(Ue, Ŷe, _ ,p , ϵ) = [p[1]*(Ue[1:end-1] .- 4.2 .- ϵ); p[2]*(Ŷe[2:end] .- 3.14 .- ϵ)] Hp=50 linmodel = LinModel(tf([2], [10000, 1]), 3000.0) nmpc_lin = NonLinMPC(linmodel; Hp, Hc=5, gc, nc=2Hp, p=[0; 0]) + JuMP.set_attribute(nmpc_lin.optim, "constr_viol_tol", 1e-3) setconstraint!(nmpc_lin, x̂min=[-1e6,-Inf], x̂max=[1e6,+Inf]) setconstraint!(nmpc_lin, umin=[-10], umax=[10]) @@ -1098,6 +1099,7 @@ end h = (x,_,p) -> p.C*x nonlinmodel = NonLinModel(f, h, linmodel.Ts, 1, 1, 1, solver=nothing, p=linmodel) nmpc = NonLinMPC(nonlinmodel; Hp, Hc=5, gc, nc=2Hp, p=[0; 0]) + JuMP.set_attribute(nmpc.optim, "constr_viol_tol", 1e-3) setconstraint!(nmpc, x̂min=[-1e6,-Inf], x̂max=[+1e6,+Inf]) setconstraint!(nmpc, umin=[-1e6], umax=[+1e6]) @@ -1167,6 +1169,7 @@ end nmpc_ms = NonLinMPC( nonlinmodel; Hp, Hc=5, transcription=MultipleShooting(), gc, nc=2Hp, p=[0; 0] ) + JuMP.set_attribute(nmpc_ms.optim, "constr_viol_tol", 1e-3) setconstraint!(nmpc_ms, x̂min=[-1e6,-Inf], x̂max=[+1e6,+Inf]) setconstraint!(nmpc_ms, ymin=[-100], ymax=[100])