484484@doc raw """
485485 init_defectmat(
486486 model::SimModel, estim::StateEstimator, transcription::OrthogonalCollocation,
487- Hp, Hc, nb , Co=nothing , λo=nothing
487+ Hp, Hc, _ , Co, λo
488488 ) -> ES, GS, JS, KS, VS, BS
489489
490490Init the matrices for computing the continuity constraints and stochastic state defects.
@@ -533,8 +533,9 @@ The matrices ``\mathbf{E_S}`` and ``\mathbf{K_S}`` are defined in the Extended H
533533 \mathbf{0} & \mathbf{0} \end{bmatrix}
534534 \end{aligned}
535535 ```
536- Note that if `estim` is an [`InternalModel`](@ref), the state vector is not augmented so
537- the rows of ``\mathbf{E_S}`` and ``\mathbf{K_S}`` with an even index are removed.
536+ Note that if `estim` is an [`InternalModel`](@ref), the state vector is not augmented
537+ hence the rows of ``\mathbf{E_S}`` and ``\mathbf{K_S}`` related to the stochastic states
538+ are removed (2nd row of blocks, 4th row of blocks, and so on).
538539"""
539540function init_defectmat (
540541 model:: NonLinModel , estim:: StateEstimator , transcription:: OrthogonalCollocation ,
@@ -1009,7 +1010,7 @@ end
10091010@doc raw """
10101011 set_warmstart_mpc!(mpc::PredictiveController, ::OrthogonalCollocation, Z̃var) -> Z̃s
10111012
1012- Set and return the warm-start value of `Z̃var` for [`OrthogonalCollocation`](@ref).
1013+ Do the same but for [`OrthogonalCollocation`](@ref).
10131014
10141015It warm-starts the solver at:
10151016```math
@@ -1065,7 +1066,7 @@ end
10651066@doc raw """
10661067 set_warmstart_mpc!(mpc::PredictiveController, ::TranscriptionMethod, Z̃var) -> Z̃s
10671068
1068- Set and return the warm-start value of `Z̃var` for other [`TranscriptionMethod`](@ref).
1069+ Do the same but for other [`TranscriptionMethod`](@ref).
10691070
10701071It warm-starts the solver at:
10711072```math
@@ -1356,9 +1357,9 @@ function con_nonlinprogeq!(
13561357 k = @views K[(1 + nk* (j- 1 )): (nk* j)]
13571358 x̂dnext = @views X̂0[(1 + nx̂* (j- 1 )): (nx̂* (j- 1 ) + nx)]
13581359 x̂dnext_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 1 )): (nx̂* (j- 1 ) + nx)]
1359- sdnext = @views geq[(1 + nx* (j- 1 )): (nx* j)]
1360+ ŝdnext = @views geq[(1 + nx* (j- 1 )): (nx* j)]
13601361 f! (x̂dnext, k, model, x̂d_Z̃, û0, d̂0, model. p)
1361- sdnext .= @. x̂dnext - x̂dnext_Z̃
1362+ ŝdnext .= @. x̂dnext - x̂dnext_Z̃
13621363 end
13631364 return geq
13641365end
@@ -1378,8 +1379,8 @@ The deterministic state defects are computed with:
13781379 - \mathbf{x̂_d}(k+j+1)
13791380```
13801381for ``j = 0, 1, ... , H_p-1``, and in which ``\mathbf{x̂_d}`` are the deterministic states
1381- extracted from the decision variable `Z̃`. The ``\mathbf{k̇}`` coefficients are evaluated
1382- from the continuous-time function `model.f!` and:
1382+ extracted from the decision variable `Z̃`. The ``\mathbf{k̇}`` coefficients are evaluated from
1383+ the continuous-time function `model.f!` and:
13831384```math
13841385\begin{aligned}
13851386\mathbf{k̇}_1(k+j) &= \mathbf{f}\Big(\mathbf{x̂_d}(k+j), \mathbf{û_0}(k+j), \mathbf{d̂_0}(k+j), \mathbf{p}\Big) \\
@@ -1398,7 +1399,7 @@ function con_nonlinprogeq!(
13981399 Hp, Hc = mpc. Hp, mpc. Hc
13991400 nΔU, nX̂ = nu* Hc, nx̂* Hp
14001401 f_threads = transcription. f_threads
1401- Ts, p = model. Ts, model . p
1402+ Ts = model. Ts
14021403 nk = get_nk (model, transcription)
14031404 D̂0 = mpc. D̂0
14041405 X̂0_Z̃ = @views Z̃[(nΔU+ 1 ): (nΔU+ nX̂)]
@@ -1411,27 +1412,27 @@ function con_nonlinprogeq!(
14111412 x̂d_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 2 )): (nx̂* (j- 2 ) + nx)]
14121413 d̂0 = @views D̂0[(1 + nd* (j- 2 )): (nd* (j- 1 ))]
14131414 end
1415+ û0 = @views Û0[(1 + nu* (j- 1 )): (nu* j)]
14141416 k̇ = @views K̇[(1 + nk* (j- 1 )): (nk* j)]
14151417 d̂0next = @views D̂0[(1 + nd* (j- 1 )): (nd* j)]
14161418 x̂dnext_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 1 )): (nx̂* (j- 1 ) + nx)]
1417- sdnext = @views geq[(1 + nx* (j- 1 )): (nx* (j- 1 ) + nx)]
1419+ ŝdnext = @views geq[(1 + nx* (j- 1 )): (nx* (j- 1 ) + nx)]
14181420 k̇1, k̇2 = @views k̇[1 : nx], k̇[nx+ 1 : 2 * nx]
1419- û0 = @views Û0[(1 + nu* (j- 1 )): (nu* j)]
14201421 if f_threads || h < 1 || j < 2
14211422 # we need to recompute k1 with multi-threading, even with h==1, since the
14221423 # last iteration (j-1) may not be executed (iterations are re-orderable)
1423- model. f! (k̇1, x̂d_Z̃, û0, d̂0, p)
1424+ model. f! (k̇1, x̂d_Z̃, û0, d̂0, model . p)
14241425 else
14251426 k̇1 .= @views K̇[(1 + nk* (j- 1 )- nx): (nk* (j- 1 ))] # k2 of of the last iter. j-1
14261427 end
14271428 if h < 1
1428- model. f! (k̇2, x̂dnext_Z̃, û0, d̂0next, p)
1429+ model. f! (k̇2, x̂dnext_Z̃, û0, d̂0next, model . p)
14291430 else
14301431 # j = Hp special case: u(k+Hp-1) = u(k+Hp) since Hc≤Hp implies Δu(k+Hp) = 0:
14311432 û0next = @views j ≥ Hp ? û0 : Û0[(1 + nu* j): (nu* (j+ 1 ))]
1432- model. f! (k̇2, x̂dnext_Z̃, û0next, d̂0next, p)
1433+ model. f! (k̇2, x̂dnext_Z̃, û0next, d̂0next, model . p)
14331434 end
1434- sdnext .= @. x̂d_Z̃ - x̂dnext_Z̃ + 0.5 * Ts* (k̇1 + k̇2)
1435+ ŝdnext .= @. x̂d_Z̃ - x̂dnext_Z̃ + 0.5 * Ts* (k̇1 + k̇2)
14351436 end
14361437 return geq
14371438end
@@ -1449,7 +1450,7 @@ Nonlinear equality constrains for [`NonLinModel`](@ref) and [`OrthogonalCollocat
14491450The defects between the deterministic state derivative at the ``n_o`` collocation points and
14501451the model dynamics are computed by:
14511452```math
1452- \mathbf{s_k }(k+j)
1453+ \mathbf{ŝ_k }(k+j)
14531454 = \mathbf{M_o} \begin{bmatrix}
14541455 \mathbf{k}_1(k+j) - \mathbf{x̂_d}(k+j) \\
14551456 \mathbf{k}_2(k+j) - \mathbf{x̂_d}(k+j) \\
@@ -1461,27 +1462,11 @@ the model dynamics are computed by:
14611462 \vdots \\
14621463 \mathbf{k̇}_{n_o}(k+j) \end{bmatrix}
14631464```
1464- for ``j = 0, 1, ... , H_p-1``, and knowing that the ``\mathbf{k}_i(k+j)`` vectors are
1465- extracted from the decision variable `Z̃`. The ``\mathbf{x̂_d}`` vectors are the
1466- deterministic states extracted from ``\mathbf{X̂_0}`` also in `Z̃`, and they correspond to the
1467- states at the beginning of the interval ``τ_0=0``. The ``\mathbf{k̇}_i`` derivative for the
1468- ``i``th collocation point is computed from the continuous-time function `model.f!` and:
1469- ```math
1470- \mathbf{k̇}_i(k+j) = \mathbf{f}\Big(\mathbf{k}_i(k+j), \mathbf{û}_i(k+j), \mathbf{d̂}_i(k+j), \mathbf{p}\Big)
1471- ```
1472- Based on the normalized time ``τ_i ∈ [0, 1]`` and hold order `transcription.h`, the inputs
1473- and disturbances are piecewise constant or linear:
1474- ```math
1475- \begin{aligned}
1476- \mathbf{û}_i(k+j) &= \begin{cases}
1477- \mathbf{û_0}(k+j) & h = 0 \\
1478- (1-τ_i)\mathbf{û_0}(k+j) + τ_i\mathbf{û_0}(k+j+1) & h = 1 \end{cases} \\
1479- \mathbf{d̂}_i(k+j) &= (1-τ_i)\mathbf{d̂_0}(k+j) + τ_i\mathbf{d̂_0}(k+j+1)
1480- \end{aligned}
1481- ```
1482- The disturbed input ``\mathbf{û_0}`` is defined in [`f̂!`](@ref). The defects for the
1483- continuity constraints and stochastic states are linear equality constraints (see
1484- [`init_defectmat`](@ref)).
1465+ for ``j = 0, 1, ... , H_p-1``, and knowing that the ``\mathbf{k}_i(k+j)`` and
1466+ ``\mathbf{x̂_d}(k+j)`` vectors are extracted from the decision variables in `Z̃`. The
1467+ ``\mathbf{k̇}_i`` vectors are evaluated from the continuous-time function `model.f`, as
1468+ described in [`init_orthocolloc`](@ref). The defects for the continuity constraints and the
1469+ stochastic states are linear equality constraints (see [`init_defectmat`](@ref)).
14851470"""
14861471function con_nonlinprogeq! (
14871472 geq, _ , Û0, K̇,
@@ -1492,7 +1477,6 @@ function con_nonlinprogeq!(
14921477 Hp, Hc = mpc. Hp, mpc. Hc
14931478 nΔU, nX̂ = nu* Hc, nx̂* Hp
14941479 f_threads = transcription. f_threads
1495- p = model. p
14961480 Mo, no, τ = mpc. Mo, transcription. no, transcription. τ
14971481 nk = get_nk (model, transcription)
14981482 D̂0 = mpc. D̂0
@@ -1507,17 +1491,17 @@ function con_nonlinprogeq!(
15071491 x̂d_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 2 )): (nx̂* (j- 2 ) + nx)]
15081492 d̂0 = @views D̂0[(1 + nd* (j- 2 )): (nd* (j- 1 ))]
15091493 end
1494+ û0 = @views Û0[(1 + nu* (j- 1 )): (nu* j)]
15101495 k̇ = @views K̇[(1 + nk* (j- 1 )): (nk* j)]
15111496 k_Z̃ = @views K_Z̃[(1 + nk* (j- 1 )): (nk* j)]
15121497 d̂0next = @views D̂0[(1 + nd* (j- 1 )): (nd* j)]
1513- sk = @views geq[(1 + nk* (j- 1 )): (nk* j)]
1498+ ŝk = @views geq[(1 + nk* (j- 1 )): (nk* j)]
15141499 # ----------------- collocation constraint defects -----------------------------
1515- û0 = @views Û0[(1 + nu* (j- 1 )): (nu* j)]
15161500 Δk = k̇
15171501 for i= 1 : no
15181502 Δk[(1 + (i- 1 )* nx): (i* nx)] = @views k_Z̃[(1 + (i- 1 )* nx): (i* nx)] .- x̂d_Z̃
15191503 end
1520- mul! (sk , Mo, Δk)
1504+ mul! (ŝk , Mo, Δk)
15211505 d̂i = @views D̂temp[(1 + nd* (j- 1 )): (nd* j)]
15221506 if h > 0
15231507 ûi = similar (û0) # TODO : remove this allocation
@@ -1527,15 +1511,15 @@ function con_nonlinprogeq!(
15271511 ki_Z̃ = @views k_Z̃[(1 + (i- 1 )* nx): (i* nx)]
15281512 d̂i .= (1 - τ[i]). * d̂0 .+ τ[i]. * d̂0next
15291513 if h < 1
1530- model. f! (k̇i, ki_Z̃, û0, d̂i, p)
1514+ model. f! (k̇i, ki_Z̃, û0, d̂i, model . p)
15311515 else
15321516 # j = Hp special case: u(k+Hp-1) = u(k+Hp) since Hc≤Hp implies Δu(k+Hp) = 0:
15331517 û0next = @views j ≥ Hp ? û0 : Û0[(1 + nu* j): (nu* (j+ 1 ))]
15341518 ûi .= (1 - τ[i]). * û0 .+ τ[i]. * û0next
1535- model. f! (k̇i, ki_Z̃, ûi, d̂i, p)
1519+ model. f! (k̇i, ki_Z̃, ûi, d̂i, model . p)
15361520 end
15371521 end
1538- sk .- = k̇
1522+ ŝk .- = k̇
15391523 end
15401524 return geq
15411525end
0 commit comments