@@ -1406,14 +1406,14 @@ Nonlinear equality constrains for [`NonLinModel`](@ref) and [`MultipleShooting`]
14061406The method mutates the `geq`, `X̂0`, `Û0` and `K` vectors in argument. The defects of the
14071407stochastic states are linear equality constraints (see [`init_defectmat`](@ref)). The
14081408defects of the deterministic states are computed with:
1409- with:
14101409```math
1411- \m athbf{ŝ_d}(k+j+1) = \m athbf{f}\B ig(\m athbf{x_0 }(k+j), \m athbf{û_0}(k+j), \m athbf{d̂_0}(k+j)\B ig)
1412- - \m athbf{x_0 }(k+j+1)
1410+ \m athbf{ŝ_d}(k+j+1) = \m athbf{f}\B ig(\m athbf{x̂_d }(k+j), \m athbf{û_0}(k+j), \m athbf{d̂_0}(k+j)\B ig)
1411+ - \m athbf{x̂_d }(k+j+1)
14131412```
1414- for ``j = 0, 1, ... , H_p-1``, and in which the deterministic state ``\m athbf{x_0}`` are
1415- extracted from the decision variables `Z̃`, ``\m athbf{f}`` is the deterministic state update
1416- function [`f!`](@ref), the disturbed input ``\m athbf{û_0}`` is defined in [`f̂!`](@ref)
1413+ for ``j = 0, 1, ... , H_p-1`` and in which the deterministic state ``\m athbf{x̂_d}`` are the
1414+ first `model.nx` elements of the augmented states ``\m athbf{x̂_0}, and they extracted from
1415+ the decision variables `Z̃`. The function ``\m athbf{f}`` is the deterministic state update
1416+ function [`f!`](@ref). The disturbed input ``\m athbf{û_0}`` is defined in [`f̂!`](@ref)
14171417documentation. The defects of the stochastic states are linear equality constraints (see
14181418[`init_defectmat`](@ref)).
14191419"""
@@ -1431,19 +1431,19 @@ function con_nonlinprogeq!(
14311431 disturbedinput! (Û0, mpc, mpc. estim, U0, X̂0_Z̃)
14321432 @threadsif f_threads for j= 1 : Hp
14331433 if j < 2
1434- x0_Z̃ = @views mpc. estim. x̂0[1 : nx]
1434+ x̂d_Z̃ = @views mpc. estim. x̂0[1 : nx]
14351435 d̂0 = @views mpc. d0[1 : nd]
14361436 else
1437- x0_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 2 )): (nx + nx̂* (j- 2 ))]
1437+ x̂d_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 2 )): (nx̂* (j- 2 ) + nx )]
14381438 d̂0 = @views D̂0[(1 + nd* (j- 2 )): (nd* (j- 1 ))]
14391439 end
14401440 û0 = @views Û0[(1 + nu* (j- 1 )): (nu* j)]
14411441 k = @views K[(1 + nk* (j- 1 )): (nk* j)]
1442- x0next = @views X̂0[(1 + nx̂* (j- 1 )): (nx + nx̂* (j- 1 ))]
1443- x0next_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 1 )): (nx + nx̂* (j- 1 ))]
1442+ x̂dnext = @views X̂0[(1 + nx̂* (j- 1 )): (nx̂* (j- 1 ) + nx )]
1443+ x̂dnext_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 1 )): (nx̂* (j- 1 ) + nx )]
14441444 sdnext = @views geq[(1 + nx* (j- 1 )): (nx* j)]
1445- f! (x0next , k, model, x0_Z̃ , û0, d̂0, model. p)
1446- sdnext .= @. x0next - x0next_Z̃
1445+ f! (x̂dnext , k, model, x̂d_Z̃ , û0, d̂0, model. p)
1446+ sdnext .= @. x̂dnext - x̂dnext_Z̃
14471447 end
14481448 return geq
14491449end
@@ -1459,23 +1459,23 @@ Nonlinear equality constrains for [`NonLinModel`](@ref) and [`TrapezoidalColloca
14591459
14601460The deterministic state defects are computed with:
14611461```math
1462- \m athbf{s_d }(k+j+1) = \m athbf{x_0 }(k+j) + 0.5 T_s [\m athbf{k̇}_1(k+j) + \m athbf{k̇}_2(k+j)]
1463- - \m athbf{x_0 }(k+j+1)
1462+ \m athbf{ŝ_d }(k+j+1) = \m athbf{x̂_d }(k+j) + 0.5 T_s [\m athbf{k̇}_1(k+j) + \m athbf{k̇}_2(k+j)]
1463+ - \m athbf{x̂_d }(k+j+1)
14641464```
1465- for ``j = 0, 1, ... , H_p-1``, and in which ``\m athbf{x_0 }`` is the deterministic state
1465+ for ``j = 0, 1, ... , H_p-1``, and in which ``\m athbf{x̂_d }`` are the deterministic states
14661466extracted from the decision variables `Z̃`. The ``\m athbf{k̇}`` coefficients are evaluated
14671467from the continuous-time function `model.f!` and:
14681468```math
14691469\b egin{aligned}
1470- \m athbf{k̇}_1(k+j) &= \m athbf{f}\B ig(\m athbf{x_0 }(k+j), \m athbf{û_0}(k+j), \m athbf{d̂_0}(k+j), \m athbf{p}\B ig) \\
1471- \m athbf{k̇}_2(k+j) &= \m athbf{f}\B ig(\m athbf{x_0 }(k+j+1), \m athbf{û_0}(k+j+h), \m athbf{d̂_0}(k+j+1), \m athbf{p}\B ig)
1470+ \m athbf{k̇}_1(k+j) &= \m athbf{f}\B ig(\m athbf{x̂_d }(k+j), \m athbf{û_0}(k+j), \m athbf{d̂_0}(k+j), \m athbf{p}\B ig) \\
1471+ \m athbf{k̇}_2(k+j) &= \m athbf{f}\B ig(\m athbf{x̂_d }(k+j+1), \m athbf{û_0}(k+j+h), \m athbf{d̂_0}(k+j+1), \m athbf{p}\B ig)
14721472\e nd{aligned}
14731473```
14741474in which ``h`` is the hold order `transcription.h` and the disturbed input ``\m athbf{û_0}``
14751475is defined in [`f̂!`](@ref) documentation.
14761476"""
14771477function con_nonlinprogeq! (
1478- geq, X̂0 , Û0, K̇,
1478+ geq, _ , Û0, K̇,
14791479 mpc:: PredictiveController , model:: NonLinModel , transcription:: TrapezoidalCollocation ,
14801480 U0, Z̃
14811481)
@@ -1490,35 +1490,33 @@ function con_nonlinprogeq!(
14901490 disturbedinput! (Û0, mpc, mpc. estim, U0, X̂0_Z̃)
14911491 @threadsif f_threads for j= 1 : Hp
14921492 if j < 2
1493- x̂0_Z̃ = @views mpc. estim. x̂0[1 : nx̂ ]
1493+ x̂d_Z̃ = @views mpc. estim. x̂0[1 : nx ]
14941494 d̂0 = @views mpc. d0[1 : nd]
14951495 else
1496- x̂0_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 2 )): (nx̂* (j- 1 ))]
1496+ x̂d_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 2 )): (nx̂* (j- 2 ) + nx)]
14971497 d̂0 = @views D̂0[(1 + nd* (j- 2 )): (nd* (j- 1 ))]
14981498 end
14991499 k̇ = @views K̇[(1 + nk* (j- 1 )): (nk* j)]
15001500 d̂0next = @views D̂0[(1 + nd* (j- 1 )): (nd* j)]
1501- x̂0next_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 1 )): (nx̂* j)]
1502- sdnext = @views geq[(1 + nx* (j- 1 ) ): (nx* (j- 1 ) + nx)]
1503- x0_Z̃ = @views x̂0_Z̃[1 : nx]
1504- x0next_Z̃ = @views x̂0next_Z̃[1 : nx]
1501+ x̂dnext_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 1 )): (nx̂* (j- 1 ) + nx)]
1502+ sdnext = @views geq[(1 + nx* (j- 1 )): (nx* (j- 1 ) + nx)]
15051503 k̇1, k̇2 = @views k̇[1 : nx], k̇[nx+ 1 : 2 * nx]
15061504 û0 = @views Û0[(1 + nu* (j- 1 )): (nu* j)]
15071505 if f_threads || h < 1 || j < 2
15081506 # we need to recompute k1 with multi-threading, even with h==1, since the
15091507 # last iteration (j-1) may not be executed (iterations are re-orderable)
1510- model. f! (k̇1, x0_Z̃ , û0, d̂0, p)
1508+ model. f! (k̇1, x̂d_Z̃ , û0, d̂0, p)
15111509 else
15121510 k̇1 .= @views K̇[(1 + nk* (j- 1 )- nx): (nk* (j- 1 ))] # k2 of of the last iter. j-1
15131511 end
15141512 if h < 1
1515- model. f! (k̇2, x0next_Z̃ , û0, d̂0next, p)
1513+ model. f! (k̇2, x̂dnext_Z̃ , û0, d̂0next, p)
15161514 else
15171515 # j = Hp special case: u(k+Hp-1) = u(k+Hp) since Hc≤Hp implies Δu(k+Hp) = 0:
15181516 û0next = @views j ≥ Hp ? û0 : Û0[(1 + nu* j): (nu* (j+ 1 ))]
1519- model. f! (k̇2, x0next_Z̃ , û0next, d̂0next, p)
1517+ model. f! (k̇2, x̂dnext_Z̃ , û0next, d̂0next, p)
15201518 end
1521- sdnext .= @. x0_Z̃ - x0next_Z̃ + 0.5 * Ts* (k̇1 + k̇2)
1519+ sdnext .= @. x̂d_Z̃ - x̂dnext_Z̃ + 0.5 * Ts* (k̇1 + k̇2)
15221520 end
15231521 return geq
15241522end
@@ -1538,20 +1536,21 @@ the model dynamics are computed by:
15381536```math
15391537\m athbf{s_k}(k+j)
15401538 = \m athbf{M_o} \b egin{bmatrix}
1541- \m athbf{k}_1(k+j) - \m athbf{x_0 }(k+j) \\
1542- \m athbf{k}_2(k+j) - \m athbf{x_0 }(k+j) \\
1539+ \m athbf{k}_1(k+j) - \m athbf{x̂_d }(k+j) \\
1540+ \m athbf{k}_2(k+j) - \m athbf{x̂_d }(k+j) \\
15431541 \v dots \\
1544- \m athbf{k}_{n_o}(k+j) - \m athbf{x_0 }(k+j) \\ \e nd{bmatrix}
1542+ \m athbf{k}_{n_o}(k+j) - \m athbf{x̂_d }(k+j) \e nd{bmatrix}
15451543 - \b egin{bmatrix}
15461544 \m athbf{k̇}_1(k+j) \\
15471545 \m athbf{k̇}_2(k+j) \\
15481546 \v dots \\
15491547 \m athbf{k̇}_{n_o}(k+j) \e nd{bmatrix}
15501548```
15511549for ``j = 0, 1, ... , H_p-1``, and knowing that the ``\m athbf{k}_i(k+j)`` vectors are
1552- extracted from the decision variable `Z̃`. The ``\m athbf{x_0}`` vectors are the
1553- deterministic state extracted from `Z̃`. The ``\m athbf{k̇}_i`` derivative for the ``i``th
1554- collocation point is computed from the continuous-time function `model.f!` and:
1550+ extracted from the decision variable `Z̃`. The ``\m athbf{x̂_d}`` vectors are the
1551+ deterministic states extracted from ``\m athbf{X̂_̂0}`` in the decision vector `Z̃`. The
1552+ ``\m athbf{k̇}_i`` derivative for the ``i``th collocation point is computed from the
1553+ continuous-time function `model.f!` and:
15551554```math
15561555\m athbf{k̇}_i(k+j) = \m athbf{f}\B ig(\m athbf{k}_i(k+j), \m athbf{û_i}(k+j), \m athbf{d̂}_i(k+j), \m athbf{p}\B ig)
15571556```
@@ -1575,10 +1574,10 @@ ones for the continuity constraint of the deterministic states are:
15751574 \m athbf{k}_2(k+j) \\
15761575 \v dots \\
15771576 \m athbf{k}_{n_o}(k+j) \e nd{bmatrix}
1578- + λ_o \m athbf{x_0 }(k+j) - \m athbf{x_0 }(k+j+1)
1577+ + λ_o \m athbf{x̂_d }(k+j) - \m athbf{x̂_d }(k+j+1)
15791578```
15801579for ``j = 0, 1, ... , H_p-1``. The differentiation matrix ``\m athbf{M_o}``, the continuity
1581- matrix ``\m athbf{C_o}`` and the coefficient ``λ_o`` are introduced in [`init_orthocolloc`](@ref).
1580+ matrix ``\m athbf{C_o}`` and the coefficient ``λ_o`` are introduced in [`init_orthocolloc`](@ref).
15821581"""
15831582function con_nonlinprogeq! (
15841583 geq, _ , Û0, K̇,
@@ -1600,25 +1599,23 @@ function con_nonlinprogeq!(
16001599 disturbedinput! (Û0, mpc, mpc. estim, U0, X̂0_Z̃)
16011600 @threadsif f_threads for j= 1 : Hp
16021601 if j < 2
1603- x̂0_Z̃ = @views mpc. estim. x̂0[1 : nx̂ ]
1602+ x̂d_Z̃ = @views mpc. estim. x̂0[1 : nx ]
16041603 d̂0 = @views mpc. d0[1 : nd]
16051604 else
1606- x̂0_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 2 )): (nx̂* (j- 1 ))]
1605+ x̂d_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 2 )): (nx̂* (j- 2 ) + nx)]
16071606 d̂0 = @views D̂0[(1 + nd* (j- 2 )): (nd* (j- 1 ))]
16081607 end
16091608 k̇ = @views K̇[(1 + nk* (j- 1 )): (nk* j)]
16101609 k_Z̃ = @views K_Z̃[(1 + nk* (j- 1 )): (nk* j)]
16111610 d̂0next = @views D̂0[(1 + nd* (j- 1 )): (nd* j)]
1612- x̂0next_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 1 )): (nx̂* j)]
1611+ x̂dnext_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 1 )): (nx̂* (j - 1 ) + nx)]
16131612 scnext = @views geq[(1 + nx_nk* (j- 1 ) ): (nx_nk* (j- 1 ) + nx)]
16141613 sk = @views geq[(1 + nx_nk* (j- 1 ) + nx): (nx_nk* j )]
1615- x0_Z̃ = @views x̂0_Z̃[1 : nx]
1616- x0next_Z̃ = @views x̂0next_Z̃[1 : nx]
16171614 # ----------------- collocation constraint defects -----------------------------
16181615 û0 = @views Û0[(1 + nu* (j- 1 )): (nu* j)]
16191616 Δk = k̇
16201617 for i= 1 : no
1621- Δk[(1 + (i- 1 )* nx): (i* nx)] = @views k_Z̃[(1 + (i- 1 )* nx): (i* nx)] .- x0_Z̃
1618+ Δk[(1 + (i- 1 )* nx): (i* nx)] = @views k_Z̃[(1 + (i- 1 )* nx): (i* nx)] .- x̂d_Z̃
16221619 end
16231620 mul! (sk, Mo, Δk)
16241621 d̂i = @views D̂temp[(1 + nd* (j- 1 )): (nd* j)]
@@ -1640,7 +1637,7 @@ function con_nonlinprogeq!(
16401637 end
16411638 sk .- = k̇
16421639 # ----------------- continuity constraint defects ------------------------------
1643- scnext .= mul! (scnext, Co, k_Z̃) .+ (λo.* x0_Z̃ ) .- x0next_Z̃
1640+ scnext .= mul! (scnext, Co, k_Z̃) .+ (λo.* x̂d_Z̃ ) .- x̂dnext_Z̃
16441641 end
16451642 return geq
16461643end
0 commit comments