Skip to content

Commit 7b8c468

Browse files
committed
rename constant scalar QP from p to r
To avoid possible confusion with MHE `p` constant
1 parent 54bee46 commit 7b8c468

File tree

7 files changed

+31
-31
lines changed

7 files changed

+31
-31
lines changed

src/controller/construct.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,15 +603,15 @@ Init the quadratic programming Hessian `H̃` for MPC.
603603
604604
The matrix appear in the quadratic general form:
605605
```math
606-
J = \min_{\mathbf{ΔŨ}} \frac{1}{2}\mathbf{(ΔŨ)'H̃(ΔŨ)} + \mathbf{q̃'(ΔŨ)} + p
606+
J = \min_{\mathbf{ΔŨ}} \frac{1}{2}\mathbf{(ΔŨ)'H̃(ΔŨ)} + \mathbf{q̃'(ΔŨ)} + r
607607
```
608608
The Hessian matrix is constant if the model and weights are linear and time invariant (LTI):
609609
```math
610610
\mathbf{H̃} = 2 ( \mathbf{Ẽ}'\mathbf{M}_{H_p}\mathbf{Ẽ} + \mathbf{Ñ}_{H_c}
611611
+ \mathbf{S̃}'\mathbf{L}_{H_p}\mathbf{S̃} )
612612
```
613-
The vector ``\mathbf{q̃}`` and scalar ``p`` need recalculation each control period ``k``, see
614-
[`initpred!`](@ref). ``p`` does not impact the minima position. It is thus useless at
613+
The vector ``\mathbf{q̃}`` and scalar ``r`` need recalculation each control period ``k``, see
614+
[`initpred!`](@ref). ``r`` does not impact the minima position. It is thus useless at
615615
optimization but required to evaluate the minimal ``J`` value.
616616
"""
617617
function init_quadprog(::LinModel, Ẽ, S̃, M_Hp, Ñ_Hc, L_Hp)

src/controller/execute.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ end
164164
@doc raw"""
165165
initpred!(mpc::PredictiveController, model::LinModel, d, D̂, R̂y, R̂u) -> nothing
166166
167-
Init linear model prediction matrices `F, q̃, p` and current estimated output `ŷ`.
167+
Init linear model prediction matrices `F, q̃, r` and current estimated output `ŷ`.
168168
169169
See [`init_predmat`](@ref) and [`init_quadprog`](@ref) for the definition of the matrices.
170170
They are computed with these equations using in-place operations:
@@ -176,14 +176,14 @@ They are computed with these equations using in-place operations:
176176
\mathbf{C_u} &= \mathbf{T} \mathbf{u_0}(k-1) - (\mathbf{R̂_u - U_{op}}) \\
177177
\mathbf{q̃} &= 2[(\mathbf{M}_{H_p} \mathbf{Ẽ})' \mathbf{C_y}
178178
+ (\mathbf{L}_{H_p} \mathbf{S̃})' \mathbf{C_u}] \\
179-
p &= \mathbf{C_y}' \mathbf{M}_{H_p} \mathbf{C_y}
179+
r &= \mathbf{C_y}' \mathbf{M}_{H_p} \mathbf{C_y}
180180
+ \mathbf{C_u}' \mathbf{L}_{H_p} \mathbf{C_u}
181181
\end{aligned}
182182
```
183183
"""
184184
function initpred!(mpc::PredictiveController, model::LinModel, d, D̂, R̂y, R̂u)
185185
mul!(mpc.T_lastu0, mpc.T, mpc.estim.lastu0)
186-
ŷ, F, q̃, p = mpc.ŷ, mpc.F, mpc.q̃, mpc.p
186+
ŷ, F, q̃, r = mpc.ŷ, mpc.F, mpc.q̃, mpc.r
187187
ŷ .= evalŷ(mpc.estim, d)
188188
predictstoch!(mpc, mpc.estim) # init mpc.F with Ŷs for InternalModel
189189
F .+= mpc.B
@@ -201,13 +201,13 @@ function initpred!(mpc::PredictiveController, model::LinModel, d, D̂, R̂y, R̂
201201
Cy = F .- mpc.R̂y0
202202
M_Hp_Ẽ = mpc.M_Hp*mpc.
203203
mul!(q̃, M_Hp_Ẽ', Cy)
204-
p .= dot(Cy, mpc.M_Hp, Cy)
204+
r .= dot(Cy, mpc.M_Hp, Cy)
205205
if ~mpc.noR̂u
206206
mpc.R̂u0 .= R̂u .- mpc.Uop
207207
Cu = mpc.T_lastu0 .- mpc.R̂u0
208208
L_Hp_S̃ = mpc.L_Hp*mpc.
209209
mul!(q̃, L_Hp_S̃', Cu, 1, 1)
210-
p .+= dot(Cu, mpc.L_Hp, Cu)
210+
r .+= dot(Cu, mpc.L_Hp, Cu)
211211
end
212212
lmul!(2, q̃)
213213
return nothing
@@ -367,9 +367,9 @@ at specific input increments `ΔŨ` and predictions `Ŷ0` values. It mutates t
367367
function obj_nonlinprog!(
368368
U0, Ȳ, _ , mpc::PredictiveController, model::LinModel, Ŷ0, ΔŨ::AbstractVector{NT}
369369
) where NT <: Real
370-
J = obj_quadprog(ΔŨ, mpc.H̃, mpc.q̃) + mpc.p[]
370+
J = obj_quadprog(ΔŨ, mpc.H̃, mpc.q̃) + mpc.r[]
371371
if !iszero(mpc.E)
372-
ny, Hp, ŷ, D̂E = model.ny, mpc.Hp, mpc.ŷ, mpc.D̂E
372+
ŷ, D̂E = mpc.ŷ, mpc.D̂E
373373
U = U0
374374
U .+= mpc.Uop
375375
uend = @views U[(end-model.nu+1):end]

src/controller/explicitmpc.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct ExplicitMPC{NT<:Real, SE<:StateEstimator} <: PredictiveController{NT}
2424
B::Vector{NT}
2525
::Hermitian{NT, Matrix{NT}}
2626
::Vector{NT}
27-
p::Vector{NT}
27+
r::Vector{NT}
2828
H̃_chol::Cholesky{NT, Matrix{NT}}
2929
Ks::Matrix{NT}
3030
Ps::Matrix{NT}
@@ -57,7 +57,7 @@ struct ExplicitMPC{NT<:Real, SE<:StateEstimator} <: PredictiveController{NT}
5757
S̃, Ñ_Hc, Ẽ = S, N_Hc, E # no slack variable ϵ for ExplicitMPC
5858
= init_quadprog(model, Ẽ, S̃, M_Hp, Ñ_Hc, L_Hp)
5959
# dummy vals (updated just before optimization):
60-
q̃, p = zeros(NT, size(H̃, 1)), zeros(NT, 1)
60+
q̃, r = zeros(NT, size(H̃, 1)), zeros(NT, 1)
6161
H̃_chol = cholesky(H̃)
6262
Ks, Ps = init_stochpred(estim, Hp)
6363
# dummy vals (updated just before optimization):
@@ -73,7 +73,7 @@ struct ExplicitMPC{NT<:Real, SE<:StateEstimator} <: PredictiveController{NT}
7373
R̂u0, R̂y0, noR̂u,
7474
S̃, T, T_lastu0,
7575
Ẽ, F, G, J, K, V, B,
76-
H̃, q̃, p,
76+
H̃, q̃, r,
7777
H̃_chol,
7878
Ks, Ps,
7979
d0, D̂0, D̂E,

src/controller/linmpc.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct LinMPC{
3434
B::Vector{NT}
3535
::Hermitian{NT, Matrix{NT}}
3636
::Vector{NT}
37-
p::Vector{NT}
37+
r::Vector{NT}
3838
Ks::Matrix{NT}
3939
Ps::Matrix{NT}
4040
d0::Vector{NT}
@@ -67,7 +67,7 @@ struct LinMPC{
6767
)
6868
= init_quadprog(model, Ẽ, S̃, M_Hp, Ñ_Hc, L_Hp)
6969
# dummy vals (updated just before optimization):
70-
q̃, p = zeros(NT, size(H̃, 1)), zeros(NT, 1)
70+
q̃, r = zeros(NT, size(H̃, 1)), zeros(NT, 1)
7171
Ks, Ps = init_stochpred(estim, Hp)
7272
# dummy vals (updated just before optimization):
7373
d0, D̂0, D̂E = zeros(NT, nd), zeros(NT, nd*Hp), zeros(NT, nd + nd*Hp)
@@ -82,7 +82,7 @@ struct LinMPC{
8282
R̂u0, R̂y0, noR̂u,
8383
S̃, T, T_lastu0,
8484
Ẽ, F, G, J, K, V, B,
85-
H̃, q̃, p,
85+
H̃, q̃, r,
8686
Ks, Ps,
8787
d0, D̂0, D̂E,
8888
Uop, Yop, Dop,

src/controller/nonlinmpc.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct NonLinMPC{
3636
B::Vector{NT}
3737
::Hermitian{NT, Matrix{NT}}
3838
::Vector{NT}
39-
p::Vector{NT}
39+
r::Vector{NT}
4040
Ks::Matrix{NT}
4141
Ps::Matrix{NT}
4242
d0::Vector{NT}
@@ -68,7 +68,7 @@ struct NonLinMPC{
6868
)
6969
= init_quadprog(model, Ẽ, S̃, M_Hp, Ñ_Hc, L_Hp)
7070
# dummy vals (updated just before optimization):
71-
q̃, p = zeros(NT, size(H̃, 1)), zeros(NT, 1)
71+
q̃, r = zeros(NT, size(H̃, 1)), zeros(NT, 1)
7272
Ks, Ps = init_stochpred(estim, Hp)
7373
# dummy vals (updated just before optimization):
7474
d0, D̂0, D̂E = zeros(NT, nd), zeros(NT, nd*Hp), zeros(NT, nd + nd*Hp)
@@ -83,7 +83,7 @@ struct NonLinMPC{
8383
R̂u0, R̂y0, noR̂u,
8484
S̃, T, T_lastu0,
8585
Ẽ, F, G, J, K, V, B,
86-
H̃, q̃, p,
86+
H̃, q̃, r,
8787
Ks, Ps,
8888
d0, D̂0, D̂E,
8989
Uop, Yop, Dop,

src/estimator/mhe/construct.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct MovingHorizonEstimator{
8787
fx̄::Vector{NT}
8888
::Hermitian{NT, Matrix{NT}}
8989
::Vector{NT}
90-
p::Vector{NT}
90+
r::Vector{NT}
9191
P̂_0::Hermitian{NT, Matrix{NT}}
9292
::Hermitian{NT, Matrix{NT}}
9393
::Hermitian{NT, Matrix{NT}}
@@ -128,9 +128,9 @@ struct MovingHorizonEstimator{
128128
invP̄ = Hermitian(inv(P̂_0), :L)
129129
invQ̂_He = Hermitian(repeatdiag(inv(Q̂), He), :L)
130130
invR̂_He = Hermitian(repeatdiag(inv(R̂), He), :L)
131-
p = direct ? 0 : 1
131+
r = direct ? 0 : 1
132132
E, G, J, B, ex̄, Ex̂, Gx̂, Jx̂, Bx̂ = init_predmat_mhe(
133-
model, He, i_ym, Â, B̂u, Ĉm, B̂d, D̂dm, x̂op, f̂op, p
133+
model, He, i_ym, Â, B̂u, Ĉm, B̂d, D̂dm, x̂op, f̂op, r
134134
)
135135
# dummy values (updated just before optimization):
136136
F, fx̄, Fx̂ = zeros(NT, nym*He), zeros(NT, nx̂), zeros(NT, nx̂*He)
@@ -139,7 +139,7 @@ struct MovingHorizonEstimator{
139139
)
140140
nZ̃ = size(Ẽ, 2)
141141
# dummy values, updated before optimization:
142-
H̃, q̃, p = Hermitian(zeros(NT, nZ̃, nZ̃), :L), zeros(NT, nZ̃), zeros(NT, 1)
142+
H̃, q̃, r = Hermitian(zeros(NT, nZ̃, nZ̃), :L), zeros(NT, nZ̃), zeros(NT, 1)
143143
= zeros(NT, nZ̃)
144144
X̂op = repeat(x̂op, He)
145145
X̂0, Y0m = zeros(NT, nx̂*He), zeros(NT, nym*He)
@@ -159,7 +159,7 @@ struct MovingHorizonEstimator{
159159
As, Cs_u, Cs_y, nint_u, nint_ym,
160160
Â, B̂u, Ĉ, B̂d, D̂d, Ĉm, D̂dm,
161161
Ẽ, F, G, J, B, ẽx̄, fx̄,
162-
H̃, q̃, p,
162+
H̃, q̃, r,
163163
P̂_0, Q̂, R̂, invP̄, invQ̂_He, invR̂_He, Cwt,
164164
X̂op, X̂0, Y0m, U0, D0, Ŵ,
165165
x̂0arr_old, P̂arr_old, Nk,

src/estimator/mhe/execute.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function init_estimate_cov!(estim::MovingHorizonEstimator, _ , d0, u0)
99
estim.Nk .= 0
1010
estim.H̃ .= 0
1111
estim.q̃ .= 0
12-
estim.p .= 0
12+
estim.r .= 0
1313
if estim.direct
1414
# add u0(-1) and d0(-1) to the data windows:
1515
estim.U0[1:estim.model.nu] .= u0
@@ -211,15 +211,15 @@ end
211211
@doc raw"""
212212
initpred!(estim::MovingHorizonEstimator, model::LinModel) -> nothing
213213
214-
Init quadratic optimization matrices `F, fx̄, H̃, q̃, p` for [`MovingHorizonEstimator`](@ref).
214+
Init quadratic optimization matrices `F, fx̄, H̃, q̃, r` for [`MovingHorizonEstimator`](@ref).
215215
216216
See [`init_predmat_mhe`](@ref) for the definition of the vectors ``\mathbf{F, f_x̄}``. It
217217
also inits `estim.optim` objective function, expressed as the quadratic general form:
218218
```math
219-
J = \min_{\mathbf{Z̃}} \frac{1}{2}\mathbf{Z̃' H̃ Z̃} + \mathbf{q̃' Z̃} + p
219+
J = \min_{\mathbf{Z̃}} \frac{1}{2}\mathbf{Z̃' H̃ Z̃} + \mathbf{q̃' Z̃} + r
220220
```
221221
in which ``\mathbf{Z̃} = [\begin{smallmatrix} ϵ \\ \mathbf{Z} \end{smallmatrix}]``. Note that
222-
``p`` is useless at optimization but required to evaluate the objective minima ``J``. The
222+
``r`` is useless at optimization but required to evaluate the objective minima ``J``. The
223223
Hessian ``\mathbf{H̃}`` matrix of the quadratic general form is not constant here because
224224
of the time-varying ``\mathbf{P̄}`` covariance . The computed variables are:
225225
```math
@@ -232,7 +232,7 @@ of the time-varying ``\mathbf{P̄}`` covariance . The computed variables are:
232232
\mathbf{Ñ}_{N_k} &= \mathrm{diag}(C, \mathbf{0}, \mathbf{Q̂}_{N_k}^{-1}) \\
233233
\mathbf{H̃} &= 2(\mathbf{Ẽ_Z̃}' \mathbf{M}_{N_k} \mathbf{Ẽ_Z̃} + \mathbf{Ñ}_{N_k}) \\
234234
\mathbf{q̃} &= 2(\mathbf{M}_{N_k} \mathbf{Ẽ_Z̃})' \mathbf{F_Z̃} \\
235-
p &= \mathbf{F_Z̃}' \mathbf{M}_{N_k} \mathbf{F_Z̃}
235+
r &= \mathbf{F_Z̃}' \mathbf{M}_{N_k} \mathbf{F_Z̃}
236236
\end{aligned}
237237
```
238238
"""
@@ -257,7 +257,7 @@ function initpred!(estim::MovingHorizonEstimator, model::LinModel)
257257
M_Nk_ẼZ̃ = M_Nk*ẼZ̃
258258
@views mul!(estim.q̃[1:nZ̃], M_Nk_ẼZ̃', FZ̃)
259259
@views lmul!(2, estim.q̃[1:nZ̃])
260-
estim.p .= dot(FZ̃, M_Nk, FZ̃)
260+
estim.r .= dot(FZ̃, M_Nk, FZ̃)
261261
estim..data[1:nZ̃, 1:nZ̃] .= Ñ_Nk
262262
@views mul!(estim..data[1:nZ̃, 1:nZ̃], ẼZ̃', M_Nk_ẼZ̃, 1, 1)
263263
@views lmul!(2, estim..data[1:nZ̃, 1:nZ̃])
@@ -460,7 +460,7 @@ It can be called on a [`MovingHorizonEstimator`](@ref) object to evaluate the ob
460460
function at specific `Z̃` and `V̂` values.
461461
"""
462462
function obj_nonlinprog!( _ , estim::MovingHorizonEstimator, ::LinModel, _ , Z̃)
463-
return obj_quadprog(Z̃, estim.H̃, estim.q̃) + estim.p[]
463+
return obj_quadprog(Z̃, estim.H̃, estim.q̃) + estim.r[]
464464
end
465465

466466
"""

0 commit comments

Comments
 (0)