@@ -589,19 +589,6 @@ function get_optim_functions(
589589 grad_backend:: AbstractADType ,
590590 jac_backend :: AbstractADType
591591) where JNT<: Real
592- # ------ update simulation function (all args after `mpc` are mutated) ----------------
593- function update_simulations! (Z̃, mpc, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq)
594- model, transcription = mpc. estim. model, mpc. transcription
595- U0 = getU0! (U0, mpc, Z̃)
596- ΔŨ = getΔŨ! (ΔŨ, mpc, transcription, Z̃)
597- Ŷ0, x̂0end = predict! (Ŷ0, x̂0end, X̂0, Û0, mpc, model, transcription, U0, Z̃)
598- Ue, Ŷe = extended_vectors! (Ue, Ŷe, mpc, U0, Ŷ0)
599- ϵ = getϵ (mpc, Z̃)
600- gc = con_custom! (gc, mpc, Ue, Ŷe, ϵ)
601- g = con_nonlinprog! (g, mpc, model, transcription, x̂0end, Ŷ0, gc, ϵ)
602- geq = con_nonlinprogeq! (geq, X̂0, Û0, mpc, model, transcription, U0, Z̃)
603- return nothing
604- end
605592 # ----- common cache for Jfunc, gfuncs, geqfuncs called with floats -------------------
606593 model = mpc. estim. model
607594 nu, ny, nx̂, nϵ, Hp, Hc = model. nu, model. ny, mpc. estim. nx̂, mpc. nϵ, mpc. Hp, mpc. Hc
@@ -622,12 +609,12 @@ function get_optim_functions(
622609 function Jfunc (Z̃arg:: Vararg{T, N} ) where {N, T<: Real }
623610 if isdifferent (Z̃arg, Z̃)
624611 Z̃ .= Z̃arg
625- update_simulations! (Z̃, mpc, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq)
612+ update_predictions! ( ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq, mpc, Z̃ )
626613 end
627614 return obj_nonlinprog! (Ŷ0, U0, mpc, model, Ue, Ŷe, ΔŨ):: T
628615 end
629616 function Jfunc! (Z̃, mpc, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq)
630- update_simulations! (Z̃, mpc, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq)
617+ update_predictions! ( ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq, mpc, Z̃ )
631618 return obj_nonlinprog! (Ŷ0, U0, mpc, model, Ue, Ŷe, ΔŨ)
632619 end
633620 Z̃_∇J = fill (myNaN, nZ̃)
@@ -658,14 +645,14 @@ function get_optim_functions(
658645 gfunc_i = function (Z̃arg:: Vararg{T, N} ) where {N, T<: Real }
659646 if isdifferent (Z̃arg, Z̃)
660647 Z̃ .= Z̃arg
661- update_simulations! (Z̃, mpc, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq)
648+ update_predictions! ( ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq, mpc, Z̃ )
662649 end
663650 return g[i]:: T
664651 end
665652 gfuncs[i] = gfunc_i
666653 end
667654 function gfunc! (g, Z̃, mpc, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, geq)
668- return update_simulations! (Z̃, mpc, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq)
655+ return update_predictions! ( ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq, mpc, Z̃ )
669656 end
670657 Z̃_∇g = fill (myNaN, nZ̃)
671658 ∇g_context = (
@@ -706,14 +693,14 @@ function get_optim_functions(
706693 geqfunc_i = function (Z̃arg:: Vararg{T, N} ) where {N, T<: Real }
707694 if isdifferent (Z̃arg, Z̃)
708695 Z̃ .= Z̃arg
709- update_simulations! (Z̃, mpc, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq)
696+ update_predictions! ( ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq, mpc, Z̃ )
710697 end
711698 return geq[i]:: T
712699 end
713700 geqfuncs[i] = geqfunc_i
714701 end
715702 function geqfunc! (geq, Z̃, mpc, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g)
716- return update_simulations! (Z̃, mpc, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq)
703+ return update_predictions! ( ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq, mpc, Z̃ )
717704 end
718705 Z̃_∇geq = fill (myNaN, nZ̃)
719706 ∇geq_context = (
@@ -743,6 +730,31 @@ function get_optim_functions(
743730 return Jfunc, ∇Jfunc!, gfuncs, ∇gfuncs!, geqfuncs, ∇geqfuncs!
744731end
745732
733+ """
734+ update_predictions!(
735+ ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq,
736+ mpc::PredictiveController, Z̃
737+ ) -> nothing
738+
739+ Update in-place all vectors for the predictions of `mpc` controller at decision vector `Z̃`.
740+
741+ The method mutates all the arguments before the `mpc` argument.
742+ """
743+ function update_predictions! (
744+ ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq, mpc:: PredictiveController , Z̃
745+ )
746+ model, transcription = mpc. estim. model, mpc. transcription
747+ U0 = getU0! (U0, mpc, Z̃)
748+ ΔŨ = getΔŨ! (ΔŨ, mpc, transcription, Z̃)
749+ Ŷ0, x̂0end = predict! (Ŷ0, x̂0end, X̂0, Û0, mpc, model, transcription, U0, Z̃)
750+ Ue, Ŷe = extended_vectors! (Ue, Ŷe, mpc, U0, Ŷ0)
751+ ϵ = getϵ (mpc, Z̃)
752+ gc = con_custom! (gc, mpc, Ue, Ŷe, ϵ)
753+ g = con_nonlinprog! (g, mpc, model, transcription, x̂0end, Ŷ0, gc, ϵ)
754+ geq = con_nonlinprogeq! (geq, X̂0, Û0, mpc, model, transcription, U0, Z̃)
755+ return nothing
756+ end
757+
746758@doc raw """
747759 con_custom!(gc, mpc::NonLinMPC, Ue, Ŷe, ϵ) -> gc
748760
0 commit comments