@@ -578,17 +578,17 @@ Inspired from: [User-defined operators with vector outputs](@extref JuMP User-de
578578function get_optim_functions (mpc:: NonLinMPC , :: JuMP.GenericModel{JNT} ) where JNT<: Real
579579 # ----- common cache for Jfunc, gfuncs, geqfuncs called with floats -------------------
580580 model = mpc. estim. model
581- nu, ny, nx̂, nϵ, nxi = model. nu, model. ny, mpc. estim. nx̂, mpc. nϵ, model. nxi
581+ nu, ny, nx̂, nϵ, nk = model. nu, model. ny, mpc. estim. nx̂, mpc. nϵ, model. nk
582582 Hp, Hc = mpc. Hp, mpc. Hc
583583 ng, nc, neq = length (mpc. con. i_g), mpc. con. nc, mpc. con. neq
584- nZ̃, nU, nŶ, nX̂, nXi = length (mpc. Z̃), Hp* nu, Hp* ny, Hp* nx̂, Hp* nxi
584+ nZ̃, nU, nŶ, nX̂, nK = length (mpc. Z̃), Hp* nu, Hp* ny, Hp* nx̂, Hp* nk
585585 nΔŨ, nUe, nŶe = nu* Hc + nϵ, nU + nu, nŶ + ny
586586 strict = Val (true )
587587 myNaN = convert (JNT, NaN ) # NaN to force update_simulations! at first call:
588588 Z̃ :: Vector{JNT} = fill (myNaN, nZ̃)
589589 ΔŨ:: Vector{JNT} = zeros (JNT, nΔŨ)
590590 x̂0end:: Vector{JNT} = zeros (JNT, nx̂)
591- X0i :: Vector{JNT} = zeros (JNT, nXi )
591+ K0 :: Vector{JNT} = zeros (JNT, nK )
592592 Ue:: Vector{JNT} , Ŷe:: Vector{JNT} = zeros (JNT, nUe), zeros (JNT, nŶe)
593593 U0:: Vector{JNT} , Ŷ0:: Vector{JNT} = zeros (JNT, nU), zeros (JNT, nŶ)
594594 Û0:: Vector{JNT} , X̂0:: Vector{JNT} = zeros (JNT, nU), zeros (JNT, nX̂)
@@ -598,18 +598,18 @@ function get_optim_functions(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JNT
598598 function Jfunc (Z̃arg:: Vararg{T, N} ) where {N, T<: Real }
599599 if isdifferent (Z̃arg, Z̃)
600600 Z̃ .= Z̃arg
601- update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X0i , X̂0, gc, g, geq, mpc, Z̃)
601+ update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0 , X̂0, gc, g, geq, mpc, Z̃)
602602 end
603603 return obj_nonlinprog! (Ŷ0, U0, mpc, model, Ue, Ŷe, ΔŨ):: T
604604 end
605- function Jfunc! (Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X0i , X̂0, gc, g, geq)
606- update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X0i , X̂0, gc, g, geq, mpc, Z̃)
605+ function Jfunc! (Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0 , X̂0, gc, g, geq)
606+ update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0 , X̂0, gc, g, geq, mpc, Z̃)
607607 return obj_nonlinprog! (Ŷ0, U0, mpc, model, Ue, Ŷe, ΔŨ)
608608 end
609609 Z̃_∇J = fill (myNaN, nZ̃)
610610 ∇J_context = (
611611 Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
612- Cache (Û0), Cache (X0i ), Cache (X̂0),
612+ Cache (Û0), Cache (K0 ), Cache (X̂0),
613613 Cache (gc), Cache (g), Cache (geq),
614614 )
615615 ∇J_prep = prepare_gradient (Jfunc!, mpc. gradient, Z̃_∇J, ∇J_context... ; strict)
@@ -634,22 +634,22 @@ function get_optim_functions(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JNT
634634 if isdifferent (Z̃arg, Z̃)
635635 Z̃ .= Z̃arg
636636 update_predictions! (
637- ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X0i , X̂0, gc, g, geq, mpc, Z̃
637+ ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0 , X̂0, gc, g, geq, mpc, Z̃
638638 )
639639 end
640640 return g[i]:: T
641641 end
642642 gfuncs[i] = gfunc_i
643643 end
644- function gfunc! (g, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X0i , X̂0, gc, geq)
644+ function gfunc! (g, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0 , X̂0, gc, geq)
645645 return update_predictions! (
646- ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X0i , X̂0, gc, g, geq, mpc, Z̃
646+ ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0 , X̂0, gc, g, geq, mpc, Z̃
647647 )
648648 end
649649 Z̃_∇g = fill (myNaN, nZ̃)
650650 ∇g_context = (
651651 Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
652- Cache (Û0), Cache (X0i ), Cache (X̂0),
652+ Cache (Û0), Cache (K0 ), Cache (X̂0),
653653 Cache (gc), Cache (geq),
654654 )
655655 # temporarily enable all the inequality constraints for sparsity detection:
@@ -685,22 +685,22 @@ function get_optim_functions(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JNT
685685 if isdifferent (Z̃arg, Z̃)
686686 Z̃ .= Z̃arg
687687 update_predictions! (
688- ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X0i , X̂0, gc, g, geq, mpc, Z̃
688+ ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0 , X̂0, gc, g, geq, mpc, Z̃
689689 )
690690 end
691691 return geq[i]:: T
692692 end
693693 geqfuncs[i] = geqfunc_i
694694 end
695- function geqfunc! (geq, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X0i , X̂0, gc, g)
695+ function geqfunc! (geq, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0 , X̂0, gc, g)
696696 return update_predictions! (
697- ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X0i , X̂0, gc, g, geq, mpc, Z̃
697+ ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0 , X̂0, gc, g, geq, mpc, Z̃
698698 )
699699 end
700700 Z̃_∇geq = fill (myNaN, nZ̃)
701701 ∇geq_context = (
702702 Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
703- Cache (Û0), Cache (X0i ), Cache (X̂0),
703+ Cache (Û0), Cache (K0 ), Cache (X̂0),
704704 Cache (gc), Cache (g)
705705 )
706706 ∇geq_prep = prepare_jacobian (geqfunc!, geq, mpc. jacobian, Z̃_∇geq, ∇geq_context... ; strict)
726726
727727"""
728728 update_predictions!(
729- ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X0i , X̂0, gc, g, geq,
729+ ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0 , X̂0, gc, g, geq,
730730 mpc::PredictiveController, Z̃
731731 ) -> nothing
732732
@@ -735,17 +735,17 @@ Update in-place all vectors for the predictions of `mpc` controller at decision
735735The method mutates all the arguments before the `mpc` argument.
736736"""
737737function update_predictions! (
738- ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X0i , X̂0, gc, g, geq, mpc:: PredictiveController , Z̃
738+ ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0 , X̂0, gc, g, geq, mpc:: PredictiveController , Z̃
739739)
740740 model, transcription = mpc. estim. model, mpc. transcription
741741 U0 = getU0! (U0, mpc, Z̃)
742742 ΔŨ = getΔŨ! (ΔŨ, mpc, transcription, Z̃)
743- Ŷ0, x̂0end = predict! (Ŷ0, x̂0end, X̂0, Û0, X0i , mpc, model, transcription, U0, Z̃)
743+ Ŷ0, x̂0end = predict! (Ŷ0, x̂0end, X̂0, Û0, K0 , mpc, model, transcription, U0, Z̃)
744744 Ue, Ŷe = extended_vectors! (Ue, Ŷe, mpc, U0, Ŷ0)
745745 ϵ = getϵ (mpc, Z̃)
746746 gc = con_custom! (gc, mpc, Ue, Ŷe, ϵ)
747747 g = con_nonlinprog! (g, mpc, model, transcription, x̂0end, Ŷ0, gc, ϵ)
748- geq = con_nonlinprogeq! (geq, X̂0, Û0, X0i , mpc, model, transcription, U0, Z̃)
748+ geq = con_nonlinprogeq! (geq, X̂0, Û0, K0 , mpc, model, transcription, U0, Z̃)
749749 return nothing
750750end
751751
0 commit comments