@@ -1149,7 +1149,7 @@ end
11491149Compute vectors if `model` is a [`NonLinModel`](@ref) and for [`SingleShooting`](@ref).
11501150
11511151The method mutates `Ŷ0`, `x̂0end`, `X̂0`, `Û0` and `K0` arguments. The augmented model of
1152- [`f̂!`](@ref) and [`ĥ!`](@ref) is called recursively in a `for` loop.
1152+ [`f̂!`](@ref) and [`ĥ!`](@ref) is called recursively in a `for` loop:
11531153"""
11541154function predict! (
11551155 Ŷ0, x̂0end, X̂0, Û0, K0,
@@ -1302,12 +1302,14 @@ end
13021302
13031303Nonlinear equality constrains for [`NonLinModel`](@ref) and [`MultipleShooting`](@ref).
13041304
1305- The method mutates the `geq`, `X̂0`, `Û0` and `K0` vectors in argument. The defects are
1306- updated with:
1305+ The method mutates the `geq`, `X̂0`, `Û0` and `K0` vectors in argument. The nonlinear
1306+ equality constraints `geq` only includes the state defects, computed with:
13071307```math
13081308\m athbf{ŝ}(k+1) = \m athbf{f̂}\B ig(\m athbf{x̂_0}(k), \m athbf{u_0}(k), \m athbf{d_0}(k)\B ig)
1309- + \t ext{TODO}
1309+ - \m athbf{x̂_0^†}(k+1)
13101310```
1311+ in which ``\m athbf{x̂_0^†}`` is the augmented state extracted from the decision variables
1312+ `Z̃`, and ``\m athbf{f̂}``, the augmented state function defined in [`f̂!`](@ref).
13111313"""
13121314function con_nonlinprogeq! (
13131315 geq, X̂0, Û0, K0,
@@ -1346,21 +1348,33 @@ end
13461348
13471349Nonlinear equality constrains for [`NonLinModel`](@ref) and [`TrapezoidalCollocation`](@ref).
13481350
1349- The method mutates the `geq`, `X̂0`, `Û0` and `K0` vectors in argument. The deterministic
1350- and stochastic states are handled separately since collocation methods require
1351- continuous-time state-space models, and the stochastic model of the unmeasured disturbances
1352- is discrete-time. Also note that operating points in `model` are typically zeros for
1353- [`NonLinModel`](@ref), but they are handled rigorously here if it's not the case. It should
1354- be noted that linearization of continuous-time dynamics at non-equilibrium points leads to :
1351+ The method mutates the `geq`, `X̂0`, `Û0` and `K0` vectors in argument.
1352+
1353+ The nonlinear equality constraints `geq` only includes the state defects. The deterministic
1354+ and stochastic states are handled separately since collocation methods require continuous-
1355+ time state-space models, and the stochastic model of the unmeasured disturbances
1356+ is discrete-time. The deterministic and stochastic defects are respectively computed with :
13551357```math
1356- \m athbf{ẋ_0}(t) ≈ \m athbf{A x_0}(t) + \m athbf{B_u u_0}(t) + \m athbf{B_d d_0}(t)
1358+ \b egin{aligned}
1359+ \m athbf{s_d}(k+1) &= \m athbf{x_0}(k) - \m athbf{x_0^†}(k+1)
1360+ + 0.5 T_s (\m athbf{k}_1 + \m athbf{k}_2) \\
1361+ \m athbf{s_s}(k+1) &= \m athbf{A_s x_s}(k) - \m athbf{x_s^†}(k+1)
1362+ \e nd{aligned}
13571363```
1358- as opposed to, for discrete-time models:
1364+ in which ``\m athbf{x_0^†}`` and ``\m athbf{x_s^†}`` are the deterministic and stochastic
1365+ states extracted from the decision variables `Z̃`. The ``\m athbf{k}`` coefficients are
1366+ evaluated from the continuous-time function `model.f!` and:
13591367```math
1360- \m athbf{x_0}(k+1) ≈ \m athbf{A x_0}(k) + \m athbf{B_u u_0}(k) + \m athbf{B_d d_0}(k)
1361- + \m athbf{f_{op}} - \m athbf{x_{op}}
1368+ \b egin{aligned}
1369+ \m athbf{k}_1 &= \m athbf{f}\B ig(\m athbf{x_0}(k), \m athbf{û_0}(k), \m athbf{d_0}(k) \B ig) \\
1370+ \m athbf{k}_2 &= \m athbf{f}\B ig(\m athbf{x_0^†}(k+1), \m athbf{û_0}(k), \m athbf{d_0}(k+1)\B ig)
1371+ \e nd{aligned}
13621372```
1363- hence no need to add `model.fop` and subtract `model.xop` in the collocation equations.
1373+ and the input of the augmented model is:
1374+ ```math
1375+ \m athbf{û_0}(k) = \m athbf{u_0}(k) + \m athbf{C_{s_u} x_s}(k)
1376+ ```
1377+ the ``\m athbf{A_s, C_{s_u}}`` matrices are defined in [`init_estimstoch`](@ref) doc.
13641378"""
13651379function con_nonlinprogeq! (
13661380 geq, X̂0, Û0, K0,
@@ -1391,19 +1405,18 @@ function con_nonlinprogeq!(
13911405 sdnext, ssnext = @views ŝnext[1 : nx], ŝnext[nx+ 1 : end ]
13921406 mul! (û0, Cs_u, xs) # ys_u = Cs_u*xs
13931407 û0 .+ = u0 # û0 = u0 + ys_u
1394- ẋ0, ẋ0next = @views k0[1 : nx], k0[nx+ 1 : 2 * nx]
1395- # no need to handle model.fop and model.xop, see docstring:
1396- model. f! (ẋ0, xd, û0, d0, p)
1397- model. f! (ẋ0next, xdnext_Z̃, û0, d0next, p) # assuming ZOH on manipulated inputs u
1408+ k1, k2 = @views k0[1 : nx], k0[nx+ 1 : 2 * nx]
1409+ model. f! (k1, xd, û0, d0, p)
1410+ model. f! (k2, xdnext_Z̃, û0, d0next, p) # assuming ZOH on manipulated inputs u
13981411 xsnext = @views x̂0next[nx+ 1 : end ]
13991412 mul! (xsnext, As, xs)
1400- sdnext .= @. xd - xdnext_Z̃ + (Ts/ 2 )* (ẋ0 + ẋ0next )
1413+ sdnext .= @. xd - xdnext_Z̃ + (Ts/ 2 )* (k1 + k2 )
14011414 ssnext .= @. xsnext - xsnext_Z̃
14021415 x̂0 = x̂0next_Z̃ # using states in Z̃ for next iteration (allow parallel for)
14031416 d0 = d0next
14041417 end
14051418 return geq
14061419end
14071420
1408- " No equality constraints for other cases e.g. [`SingleShooting`](@ref), returns `geq` unchanged."
1421+ " No eq. constraints for other cases e.g. [`SingleShooting`](@ref), returns `geq` unchanged."
14091422con_nonlinprogeq! (geq,_,_,_,:: PredictiveController ,:: SimModel ,:: TranscriptionMethod ,_,_)= geq
0 commit comments