@@ -78,12 +78,18 @@ equality constraint function and by using the implicit trapezoidal rule. It can
7878moderately stiff systems and is A-stable. However, it may not be as efficient as more
7979advanced collocation methods for highly stiff systems. Note that the stochastic model of the
8080unmeasured disturbances is strictly discrete-time, it is thus transcribed separately using
81- [`MultipleShooting`](@ref).
81+ [`MultipleShooting`](@ref). Also note that the state
8282
8383Sparse optimizers like `Ipopt` and sparse Jacobian computations are recommended for this
8484transcription method.
8585"""
86- struct TrapezoidalCollocation <: CollocationMethod end
86+ struct TrapezoidalCollocation <: CollocationMethod
87+ nc:: Int
88+ function TrapezoidalCollocation ()
89+ nc = 2 # 2 collocation points per interval for trapezoidal rule
90+ return new (nc)
91+ end
92+ end
8793
8894function validate_transcription (:: LinModel , :: CollocationMethod )
8995 throw (ArgumentError (" Collocation methods are not supported for LinModel." ))
@@ -103,6 +109,10 @@ function get_nZ(estim::StateEstimator, ::TranscriptionMethod, Hp, Hc)
103109 return estim. model. nu* Hc + estim. nx̂* Hp
104110end
105111
112+ " Get length of the `k` vector with all the solver intermediate steps or all the collocation pts."
113+ get_nk (model:: SimModel , :: ShootingMethod ) = model. nk
114+ get_nk (model:: SimModel , transcription:: CollocationMethod ) = model. nx* transcription. nc
115+
106116@doc raw """
107117 init_ZtoΔU(estim::StateEstimator, transcription::TranscriptionMethod, Hp, Hc) -> PΔu
108118
@@ -1271,7 +1281,8 @@ end
12711281"""
12721282 con_nonlinprogeq!(
12731283 geq, X̂0, Û0, K0
1274- mpc::PredictiveController, model::NonLinModel, ::MultipleShooting, U0, Z̃
1284+ mpc::PredictiveController, model::NonLinModel, transcription::MultipleShooting,
1285+ U0, Z̃
12751286 )
12761287
12771288Nonlinear equality constrains for [`NonLinModel`](@ref) and [`MultipleShooting`](@ref).
@@ -1311,7 +1322,8 @@ end
13111322@doc raw """
13121323 con_nonlinprogeq!(
13131324 geq, X̂0, Û0, K0
1314- mpc::PredictiveController, model::NonLinModel, ::TrapezoidalCollocation, U0, Z̃
1325+ mpc::PredictiveController, model::NonLinModel, transcription::TrapezoidalCollocation,
1326+ U0, Z̃
13151327 )
13161328
13171329Nonlinear equality constrains for [`NonLinModel`](@ref) and [`TrapezoidalCollocation`](@ref).
@@ -1334,16 +1346,15 @@ hence no need to add `model.fop` and subtract `model.xop` in the collocation equ
13341346"""
13351347function con_nonlinprogeq! (
13361348 geq, X̂0, Û0, K0,
1337- mpc:: PredictiveController , model:: NonLinModel , :: TrapezoidalCollocation , U0, Z̃
1349+ mpc:: PredictiveController , model:: NonLinModel , transcription:: TrapezoidalCollocation ,
1350+ U0, Z̃
13381351)
13391352 nu, nx̂, nd, nx = model. nu, mpc. estim. nx̂, model. nd, model. nx
13401353 Hp, Hc = mpc. Hp, mpc. Hc
13411354 nΔU, nX̂ = nu* Hc, nx̂* Hp
1342-
13431355 Ts, p = model. Ts, model. p
13441356 As, Cs_u = mpc. estim. As, mpc. estim. Cs_u
1345- # K0 stores the state derivatives at each collocation point for all intervals
1346- nk = model. nk # TODO : initialize K0 to the adequate size for a given collocation method
1357+ nk = get_nk (model, transcription)
13471358 D̂0 = mpc. D̂0
13481359 X̂0_Z̃ = @views Z̃[(nΔU+ 1 ): (nΔU+ nX̂)]
13491360 x̂0 = @views mpc. estim. x̂0[1 : nx̂]
0 commit comments