@@ -146,7 +146,7 @@ where ``\mathbf{K}`` encompasses all the intermediate stages of the deterministi
146146 \m athbf{k}_{1}(k+1) \\
147147 \m athbf{k}_{2}(k+1) \\
148148 \v dots \\
149- \m athbf{k}_{n_o}(k+H_p) \e nd{bmatrix}
149+ \m athbf{k}_{n_o}(k+H_p-1) \e nd{bmatrix}
150150```
151151and ``\m athbf{k}_o(k+j)`` is the deterministic state prediction for the ``o``th collocation
152152point at the ``j``th stage/interval/finite element (details in Extended Help). The `roots`
@@ -974,9 +974,10 @@ last control period ``k-1``, and ``ϵ(k-1)``, the slack variable of the last con
974974"""
975975function set_warmstart! (mpc:: PredictiveController , :: SingleShooting , Z̃var)
976976 nu, Hc, Z̃s = mpc. estim. model. nu, mpc. Hc, mpc. buffer. Z̃
977+ nΔU = nu* Hc
977978 # --- input increments ΔU ---
978- Z̃s[1 : (Hc * nu - nu)] .= @views mpc. Z̃[nu+ 1 : Hc * nu ]
979- Z̃s[(Hc * nu - nu+ 1 ): (Hc * nu )] .= 0
979+ Z̃s[1 : (nΔU - nu)] .= @views mpc. Z̃[nu+ 1 : nΔU ]
980+ Z̃s[(nΔU - nu+ 1 ): (nΔU )] .= 0
980981 # --- slack variable ϵ ---
981982 mpc. nϵ == 1 && (Z̃s[end ] = mpc. Z̃[end ])
982983 JuMP. set_start_value .(Z̃var, Z̃s)
@@ -1001,25 +1002,35 @@ It warm-starts the solver at:
10011002 \v dots \\
10021003 \m athbf{x̂_0}(k+H_p-1|k-1) \\
10031004 \m athbf{x̂_0}(k+H_p-1|k-1) \\
1004- \m athbf{k}_{1} (k+1 |k-1) \\
1005- \m athbf{k}_{2} (k+1|k-1) \\
1005+ \m athbf{k}(k+0 |k-1) \\
1006+ \m athbf{k}(k+1|k-1) \\
10061007 \v dots \\
1007- \m athbf{k}_{n_o}(k+1|k-1) \\
1008+ \m athbf{k}(k+H_p-2|k-1) \\
1009+ \m athbf{k}(k+H_p-2|k-1) \\
10081010 ϵ(k-1)
10091011\e nd{bmatrix}
10101012```
10111013where ``\m athbf{x̂_0}(k+j|k-1)`` is the predicted state for time ``k+j`` computed at the
10121014last control period ``k-1``, expressed as a deviation from the operating point
1013- ``\m athbf{x̂_{op}}``.
1015+ ``\m athbf{x̂_{op}}``. The vector ``\m athbf{k}(k+j|k-1) include the ``n_o`` intermediate
1016+ stage predictions for the interval ``k+j``, and is also computed at the last control period.
10141017"""
1015- function set_warmstart! (mpc:: PredictiveController , :: OrthogonalCollocation , Z̃var)
1016- nu, nx̂, Hp, Hc, Z̃s = mpc. estim. model. nu, mpc. estim. nx̂, mpc. Hp, mpc. Hc, mpc. buffer. Z̃
1018+ function set_warmstart! (
1019+ mpc:: PredictiveController , transcription:: OrthogonalCollocation , Z̃var
1020+ )
1021+ nu, nx̂ = mpc. estim. model. nu, mpc. estim. nx̂
1022+ Hp, Hc, Z̃s = mpc. Hp, mpc. Hc, mpc. buffer. Z̃
1023+ nk = get_nk (mpc. estim. model, transcription)
1024+ nΔU, nX̂, nK = nu* Hc, nx̂* Hp, nk* Hp
10171025 # --- input increments ΔU ---
1018- Z̃s[1 : (Hc * nu - nu)] .= @views mpc. Z̃[nu+ 1 : Hc * nu ]
1019- Z̃s[(Hc * nu - nu+ 1 ): (Hc * nu )] .= 0
1026+ Z̃s[1 : (nΔU - nu)] .= @views mpc. Z̃[( nu+ 1 ) : (nΔU) ]
1027+ Z̃s[(nΔU - nu+ 1 ): (nΔU )] .= 0
10201028 # --- predicted states X̂0 ---
1021- Z̃s[(Hc* nu+ 1 ): (Hc* nu+ Hp* nx̂- nx̂)] .= @views mpc. Z̃[(Hc* nu+ nx̂+ 1 ): (Hc* nu+ Hp* nx̂)]
1022- Z̃s[(Hc* nu+ Hp* nx̂- nx̂+ 1 ): (Hc* nu+ Hp* nx̂)] .= @views mpc. Z̃[(Hc* nu+ Hp* nx̂- nx̂+ 1 ): (Hc* nu+ Hp* nx̂)]
1029+ Z̃s[(nΔU+ 1 ): (nΔU+ nX̂- nx̂)] .= @views mpc. Z̃[(nΔU+ nx̂+ 1 ): (nΔU+ nX̂)]
1030+ Z̃s[(nΔU+ nX̂- nx̂+ 1 ): (nΔU+ nX̂)] .= @views mpc. Z̃[(nΔU+ nX̂- nx̂+ 1 ): (nΔU+ nX̂)]
1031+ # --- collocation points K ---
1032+ Z̃s[(nΔU+ nX̂+ 1 ): (nΔU+ nX̂+ nK- nk)] .= @views mpc. Z̃[(nΔU+ nX̂+ nk+ 1 ): (nΔU+ nX̂+ nK)]
1033+ Z̃s[(nΔU+ nX̂+ nK- nk+ 1 ): (nΔU+ nX̂+ nK)] .= @views mpc. Z̃[(nΔU+ nX̂+ nK- nk+ 1 ): (nΔU+ nX̂+ nK)]
10231034 # --- slack variable ϵ ---
10241035 mpc. nϵ == 1 && (Z̃s[end ] = mpc. Z̃[end ])
10251036 JuMP. set_start_value .(Z̃var, Z̃s)
@@ -1053,12 +1064,13 @@ last control period ``k-1``, expressed as a deviation from the operating point
10531064"""
10541065function set_warmstart! (mpc:: PredictiveController , :: TranscriptionMethod , Z̃var)
10551066 nu, nx̂, Hp, Hc, Z̃s = mpc. estim. model. nu, mpc. estim. nx̂, mpc. Hp, mpc. Hc, mpc. buffer. Z̃
1067+ nΔU, nX̂ = nu* Hc, nx̂* Hp
10561068 # --- input increments ΔU ---
1057- Z̃s[1 : (Hc * nu - nu)] .= @views mpc. Z̃[nu+ 1 : Hc * nu ]
1058- Z̃s[(Hc * nu - nu+ 1 ): (Hc * nu )] .= 0
1069+ Z̃s[1 : (nΔU - nu)] .= @views mpc. Z̃[nu+ 1 : nΔU ]
1070+ Z̃s[(nΔU - nu+ 1 ): (nΔU )] .= 0
10591071 # --- predicted states X̂0 ---
1060- Z̃s[(Hc * nu + 1 ): (Hc * nu + Hp * nx̂ - nx̂)] .= @views mpc. Z̃[(Hc * nu + nx̂+ 1 ): (Hc * nu + Hp * nx̂ )]
1061- Z̃s[(Hc * nu + Hp * nx̂ - nx̂+ 1 ): (Hc * nu + Hp * nx̂ )] .= @views mpc. Z̃[(Hc * nu + Hp * nx̂ - nx̂+ 1 ): (Hc * nu + Hp * nx̂ )]
1072+ Z̃s[(nΔU + 1 ): (nΔU + nX̂ - nx̂)] .= @views mpc. Z̃[(nΔU + nx̂+ 1 ): (nΔU + nX̂ )]
1073+ Z̃s[(nΔU + nX̂ - nx̂+ 1 ): (nΔU + nX̂ )] .= @views mpc. Z̃[(nΔU + nX̂ - nx̂+ 1 ): (nΔU + nX̂ )]
10621074 # --- slack variable ϵ ---
10631075 mpc. nϵ == 1 && (Z̃s[end ] = mpc. Z̃[end ])
10641076 JuMP. set_start_value .(Z̃var, Z̃s)
@@ -1427,24 +1439,27 @@ The method mutates the `geq`, `X̂0`, `Û0` and `K̇` vectors in argument. The
14271439the deterministic state derivative at the ``n_o`` collocation points and the model dynamics
14281440are computed by:
14291441```math
1430- \b egin{aligned}
1431- \m athbf{s_k}(k+j) &
1442+ \m athbf{s_k}(k+j)
14321443 = \m athbf{M_o} \b egin{bmatrix}
1433- \m athbf{k}_1(k+j) - \m athbf{x_0}(k+j) \\
1434- \m athbf{k}_2(k+j) - \m athbf{x_0}(k+j) \\
1435- \v dots \\
1436- \m athbf{k}_{n_o}(k+j) - \m athbf{x_0}(k+j) \\ \e nd{bmatrix} \\ & \q uad
1444+ \m athbf{k}_1(k+j) - \m athbf{x_0}(k+j) \\
1445+ \m athbf{k}_2(k+j) - \m athbf{x_0}(k+j) \\
1446+ \v dots \\
1447+ \m athbf{k}_{n_o}(k+j) - \m athbf{x_0}(k+j) \\ \e nd{bmatrix}
14371448 - \b egin{bmatrix}
1438- \m athbf{f}\B ig(\m athbf{k}_1(k+j), \m athbf{û_0}(k+j), \m athbf{d̂_0}(k+j), \m athbf{p}\B ig) \\
1439- \m athbf{f}\B ig(\m athbf{k}_2(k+j), \m athbf{û_0}(k+j), \m athbf{d̂_0}(k+j), \m athbf{p}\B ig) \\
1440- \v dots \\
1441- \m athbf{f}\B ig(\m athbf{k}_{n_o}(k+j), \m athbf{û_0}(k+j), \m athbf{d̂_0}(k+j), \m athbf{p}\B ig) \e nd{bmatrix}
1442- \e nd{aligned}
1449+ \m athbf{k̇}_1(k+j) \\
1450+ \m athbf{k̇}_2(k+j) \\
1451+ \v dots \\
1452+ \m athbf{k̇}_{n_o}(k+j) \e nd{bmatrix}
14431453```
14441454for ``j = 0, 1, ... , H_p-1``, and knowing that the ``\m athbf{k}_o(k+j)`` vectors are
14451455extracted from the decision variable `Z̃`. The ``\m athbf{x_0}`` vectors are the
1446- deterministic state extracted from `Z̃`. The disturbed input ``\m athbf{û_0}(k+j)`` is defined
1447- in [`f̂_input!`](@ref). The defects for the stochastic states ``\m athbf{s_s}`` are computed
1456+ deterministic state extracted from `Z̃`. The ``\m athbf{k̇}_o`` vector for the ``o``th
1457+ collocation point is computed from the continuous-time function `model.f!` and:
1458+ ```math
1459+ \m athbf{k̇}_o(k+j) = \m athbf{f}\B ig(\m athbf{k_o}(k+j), \m athbf{û_0}(k+j), \m athbf{d̂_0}(k+j), \m athbf{p}\B ig)
1460+ ```
1461+ The disturbed input ``\m athbf{û_0}(k+j)`` is defined in [`f̂_input!`](@ref). The defects for
1462+ the stochastic states ``\m athbf{s_s}`` are computed
14481463as in the [`TrapezoidalCollocation`](@ref) method, and the ones for the continuity
14491464constraint of the deterministic state trajectories are given by:
14501465```math
@@ -1500,7 +1515,7 @@ function con_nonlinprogeq!(
15001515 k̇o = @views k̇[(1 + (o- 1 )* nx): (o* nx)]
15011516 ko_Z̃ = @views k_Z̃[(1 + (o- 1 )* nx): (o* nx)]
15021517 Δko = @views Δk[(1 + (o- 1 )* nx): (o* nx)]
1503- Δko .= ko_Z̃ . - x0_Z̃
1518+ Δko .= @. ko_Z̃ - x0_Z̃
15041519 model. f! (k̇o, ko_Z̃, û0, d̂0, p)
15051520 end
15061521 # TODO : remove the following allocations
0 commit comments