@@ -606,15 +606,16 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
606606 Ue, Ŷe = zeros (NT, nUe), zeros (NT, nŶe)
607607 U0, Ŷ0 = zeros (NT, nU), zeros (NT, nŶ)
608608 Û0, X̂0 = zeros (NT, nU), zeros (NT, nX̂)
609+ Ûi = zeros (NT, nU)
609610 gc, g = zeros (NT, nc), zeros (NT, ng)
610611 gi, geq = zeros (NT, ngi), zeros (NT, neq)
611612 J_cache = (
612613 Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
613- Cache (Û0), Cache (K), Cache (X̂0),
614+ Cache (Û0), Cache (Ûi), Cache ( K), Cache (X̂0),
614615 Cache (gc), Cache (g), Cache (geq),
615616 )
616- function J! (Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K , X̂0, gc, g, geq)
617- update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K , X̂0, gc, g, geq, mpc, Z̃)
617+ function J! (Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄ , X̂0, gc, g, geq)
618+ update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄ , X̂0, gc, g, geq, mpc, Z̃)
618619 return obj_nonlinprog! (Ŷ0, U0, mpc, Ue, Ŷe, ΔŨ)
619620 end
620621 if ! isnothing (hess)
@@ -629,11 +630,11 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
629630 # --- inequality constraint derivatives ---
630631 ∇g_cache = (
631632 Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
632- Cache (Û0), Cache (K), Cache (X̂0),
633+ Cache (Û0), Cache (Ûi), Cache ( K), Cache (X̂0),
633634 Cache (gc), Cache (geq), Cache (g)
634635 )
635- function gi! (gi, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K, X̂0, gc, geq, g)
636- update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K, X̂0, gc, g, geq, mpc, Z̃)
636+ function gi! (gi, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K, X̂0, gc, geq, g)
637+ update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K, X̂0, gc, g, geq, mpc, Z̃)
637638 gi .= @views g[i_g]
638639 return nothing
639640 end
@@ -657,11 +658,13 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
657658 end
658659 ∇²g_cache = (
659660 Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
660- Cache (Û0), Cache (K), Cache (X̂0),
661+ Cache (Û0), Cache (Ûi), Cache ( K), Cache (X̂0),
661662 Cache (gc), Cache (geq), Cache (g), Cache (gi)
662663 )
663- function ℓ_gi (Z̃, λi, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K, X̂0, gc, geq, g, gi)
664- update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K, X̂0, gc, g, geq, mpc, Z̃)
664+ function ℓ_gi (Z̃, λi, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, geq, g, gi)
665+ update_predictions! (
666+ ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, g, geq, mpc, Z̃
667+ )
665668 gi .= @views g[i_g]
666669 return dot (λi, gi)
667670 end
@@ -674,11 +677,13 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
674677 # --- equality constraint derivatives ---
675678 geq_cache = (
676679 Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
677- Cache (Û0), Cache (K ), Cache (X̂0),
680+ Cache (Û0), Cache (Ûi ), Cache (K), Cache (X̂0),
678681 Cache (gc), Cache (g)
679682 )
680- function geq! (geq, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K, X̂0, gc, g)
681- update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K, X̂0, gc, g, geq, mpc, Z̃)
683+ function geq! (geq, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, g)
684+ update_predictions! (
685+ ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, g, geq, mpc, Z̃
686+ )
682687 return nothing
683688 end
684689 ∇geq_prep = prepare_jacobian (geq!, geq, mpc. jacobian, mpc. Z̃, geq_cache... )
@@ -701,11 +706,13 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
701706 end
702707 ∇²geq_cache = (
703708 Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
704- Cache (Û0), Cache (K ), Cache (X̂0),
709+ Cache (Û0), Cache (Ûi ), Cache (K), Cache (X̂0),
705710 Cache (gc), Cache (geq), Cache (g)
706711 )
707- function ℓ_geq (Z̃, λeq, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K, X̂0, gc, geq, g)
708- update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K, X̂0, gc, g, geq, mpc, Z̃)
712+ function ℓ_geq (Z̃, λeq, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, geq, g)
713+ update_predictions! (
714+ ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, g, geq, mpc, Z̃
715+ )
709716 return dot (λeq, geq)
710717 end
711718 ∇²ℓgeq_prep = prepare_hessian (ℓ_geq, hess, mpc. Z̃, Constant (λeq), ∇²geq_cache... )
@@ -846,16 +853,17 @@ function get_nonlinobj_op(mpc::NonLinMPC, optim::JuMP.GenericModel{JNT}) where J
846853 Ue:: Vector{JNT} , Ŷe:: Vector{JNT} = zeros (JNT, nUe), zeros (JNT, nŶe)
847854 U0:: Vector{JNT} , Ŷ0:: Vector{JNT} = zeros (JNT, nU), zeros (JNT, nŶ)
848855 Û0:: Vector{JNT} , X̂0:: Vector{JNT} = zeros (JNT, nU), zeros (JNT, nX̂)
856+ Ûi:: Vector{JNT} = zeros (JNT, nU)
849857 gc:: Vector{JNT} , g:: Vector{JNT} = zeros (JNT, nc), zeros (JNT, ng)
850858 geq:: Vector{JNT} = zeros (JNT, neq)
851- function J! (Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K̄, X̂0, gc, g, geq)
852- update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K̄, X̂0, gc, g, geq, mpc, Z̃)
859+ function J! (Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, g, geq)
860+ update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, g, geq, mpc, Z̃)
853861 return obj_nonlinprog! (Ŷ0, U0, mpc, Ue, Ŷe, ΔŨ)
854862 end
855863 Z̃_J = zeros (JNT, nZ̃)
856864 J_cache = (
857865 Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
858- Cache (Û0), Cache (K̄), Cache (X̂0),
866+ Cache (Û0), Cache (Ûi), Cache ( K̄), Cache (X̂0),
859867 Cache (gc), Cache (g), Cache (geq),
860868 )
861869 ∇J_prep = prepare_gradient (J!, grad, Z̃_J, J_cache... ; strict)
@@ -974,24 +982,25 @@ function get_nonlincon_oracle(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JN
974982 Ue:: Vector{JNT} , Ŷe:: Vector{JNT} = zeros (JNT, nUe), zeros (JNT, nŶe)
975983 U0:: Vector{JNT} , Ŷ0:: Vector{JNT} = zeros (JNT, nU), zeros (JNT, nŶ)
976984 Û0:: Vector{JNT} , X̂0:: Vector{JNT} = zeros (JNT, nU), zeros (JNT, nX̂)
985+ Ûi:: Vector{JNT} = zeros (JNT, nU)
977986 gc:: Vector{JNT} , g:: Vector{JNT} = zeros (JNT, nc), zeros (JNT, ng)
978987 gi:: Vector{JNT} , geq:: Vector{JNT} = zeros (JNT, ngi), zeros (JNT, neq)
979988 λi:: Vector{JNT} , λeq:: Vector{JNT} = rand (JNT, ngi), rand (JNT, neq)
980989 # -------------- inequality constraint: nonlinear oracle -----------------------------
981- function gi! (gi, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K̄, X̂0, gc, geq, g)
982- update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K̄, X̂0, gc, g, geq, mpc, Z̃)
990+ function gi! (gi, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, geq, g)
991+ update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, g, geq, mpc, Z̃)
983992 gi .= @views g[i_g]
984993 return nothing
985994 end
986- function ℓ_gi (Z̃, λi, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K̄, X̂0, gc, geq, g, gi)
987- update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K̄, X̂0, gc, g, geq, mpc, Z̃)
995+ function ℓ_gi (Z̃, λi, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, geq, g, gi)
996+ update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, g, geq, mpc, Z̃)
988997 gi .= @views g[i_g]
989998 return dot (λi, gi)
990999 end
9911000 Z̃_∇gi = zeros (JNT, nZ̃)
9921001 ∇gi_cache = (
9931002 Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
994- Cache (Û0), Cache (K̄), Cache (X̂0),
1003+ Cache (Û0), Cache (Ûi), Cache ( K̄), Cache (X̂0),
9951004 Cache (gc), Cache (geq), Cache (g)
9961005 )
9971006 ∇gi_prep = prepare_jacobian (gi!, gi, jac, Z̃_∇gi, ∇gi_cache... ; strict)
@@ -1000,7 +1009,7 @@ function get_nonlincon_oracle(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JN
10001009 if ! isnothing (hess)
10011010 ∇²gi_cache = (
10021011 Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
1003- Cache (Û0), Cache (K̄), Cache (X̂0),
1012+ Cache (Û0), Cache (Ûi), Cache ( K̄), Cache (X̂0),
10041013 Cache (gc), Cache (geq), Cache (g), Cache (gi)
10051014 )
10061015 ∇²gi_prep = prepare_hessian (
@@ -1044,18 +1053,18 @@ function get_nonlincon_oracle(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JN
10441053 eval_hessian_lagrangian = isnothing (hess) ? nothing : ∇²gi_func!
10451054 )
10461055 # ------------- equality constraints : nonlinear oracle ------------------------------
1047- function geq! (geq, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K̄, X̂0, gc, g)
1048- update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K̄, X̂0, gc, g, geq, mpc, Z̃)
1056+ function geq! (geq, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, g)
1057+ update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, g, geq, mpc, Z̃)
10491058 return nothing
10501059 end
1051- function ℓ_geq (Z̃, λeq, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K̄, X̂0, gc, geq, g)
1052- update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K̄, X̂0, gc, g, geq, mpc, Z̃)
1060+ function ℓ_geq (Z̃, λeq, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, geq, g)
1061+ update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, g, geq, mpc, Z̃)
10531062 return dot (λeq, geq)
10541063 end
10551064 Z̃_∇geq = zeros (JNT, nZ̃)
10561065 ∇geq_cache = (
10571066 Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
1058- Cache (Û0), Cache (K̄ ), Cache (X̂0),
1067+ Cache (Û0), Cache (Ûi ), Cache (K̄), Cache (X̂0),
10591068 Cache (gc), Cache (g)
10601069 )
10611070 ∇geq_prep = prepare_jacobian (geq!, geq, jac, Z̃_∇geq, ∇geq_cache... ; strict)
@@ -1064,7 +1073,7 @@ function get_nonlincon_oracle(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JN
10641073 if ! isnothing (hess)
10651074 ∇²geq_cache = (
10661075 Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
1067- Cache (Û0), Cache (K̄ ), Cache (X̂0),
1076+ Cache (Û0), Cache (Ûi ), Cache (K̄), Cache (X̂0),
10681077 Cache (gc), Cache (geq), Cache (g)
10691078 )
10701079 ∇²geq_prep = prepare_hessian (
@@ -1119,7 +1128,7 @@ end
11191128
11201129"""
11211130 update_predictions!(
1122- ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K̄, X̂0, gc, g, geq,
1131+ ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, g, geq,
11231132 mpc::PredictiveController, Z̃
11241133 ) -> nothing
11251134
@@ -1128,18 +1137,18 @@ Update in-place all vectors for the predictions of `mpc` controller at decision
11281137The method mutates all the arguments before the `mpc` argument.
11291138"""
11301139function update_predictions! (
1131- ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K̄, X̂0, gc, g, geq,
1140+ ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, Ûi, K̄, X̂0, gc, g, geq,
11321141 mpc:: PredictiveController , Z̃
11331142)
11341143 model, transcription = mpc. estim. model, mpc. transcription
11351144 U0 = getU0! (U0, mpc, Z̃)
11361145 ΔŨ = getΔŨ! (ΔŨ, mpc, transcription, Z̃)
1137- Ŷ0, x̂0end = predict! (Ŷ0, x̂0end, X̂0, Û0, K̄, mpc, model, transcription, U0, Z̃)
1146+ Ŷ0, x̂0end = predict! (Ŷ0, x̂0end, X̂0, Û0, Ûi, K̄, mpc, model, transcription, U0, Z̃)
11381147 Ue, Ŷe = extended_vectors! (Ue, Ŷe, mpc, U0, Ŷ0)
11391148 ϵ = getslack (mpc, Z̃)
11401149 gc = con_custom! (gc, mpc, Ue, Ŷe, ϵ)
11411150 g = con_nonlinprog! (g, mpc, model, transcription, x̂0end, Ŷ0, gc, ϵ)
1142- geq = con_nonlinprogeq! (geq, X̂0, Û0, K̄, mpc, model, transcription, U0, Z̃)
1151+ geq = con_nonlinprogeq! (geq, X̂0, Û0, Ûi, K̄, mpc, model, transcription, U0, Z̃)
11431152 return nothing
11441153end
11451154
0 commit comments