Skip to content

Commit 04b1692

Browse files
committed
added: nb argument to init_predmat
1 parent 0cc2589 commit 04b1692

5 files changed

Lines changed: 23 additions & 18 deletions

File tree

src/controller/execute.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,11 @@ end
624624
function setmodel_controller!(mpc::PredictiveController, uop_old, x̂op_old)
625625
model, estim, transcription = mpc.estim.model, mpc.estim, mpc.transcription
626626
weights = mpc.weights
627-
nu, ny, nd, Hp, Hc = model.nu, model.ny, model.nd, mpc.Hp, mpc.Hc
627+
nu, ny, nd, Hp, Hc, nb = model.nu, model.ny, model.nd, mpc.Hp, mpc.Hc, mpc.nb
628628
optim, con = mpc.optim, mpc.con
629629
# --- prediction matrices ---
630630
E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂ = init_predmat(
631-
model, estim, transcription, Hp, Hc
631+
model, estim, transcription, Hp, Hc, nb
632632
)
633633
A_Ymin, A_Ymax, Ẽ = relaxŶ(E, con.C_ymin, con.C_ymax, mpc.nϵ)
634634
A_x̂min, A_x̂max, ẽx̂ = relaxterminal(ex̂, con.c_x̂min, con.c_x̂max, mpc.nϵ)

src/controller/explicitmpc.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct ExplicitMPC{
5353
validate_transcription(model, transcription)
5454
PΔu = init_ZtoΔU(estim, transcription, Hp, Hc)
5555
Pu, Tu = init_ZtoU(estim, transcription, Hp, Hc, nb)
56-
E, G, J, K, V, B = init_predmat(model, estim, transcription, Hp, Hc)
56+
E, G, J, K, V, B = init_predmat(model, estim, transcription, Hp, Hc, nb)
5757
# dummy val (updated just before optimization):
5858
F = zeros(NT, ny*Hp)
5959
P̃Δu, P̃u, Ẽ = PΔu, Pu, E # no slack variable ϵ for ExplicitMPC
@@ -226,9 +226,9 @@ addinfo!(info, mpc::ExplicitMPC) = info
226226
function setmodel_controller!(mpc::ExplicitMPC, uop_old, _ )
227227
model, estim, transcription = mpc.estim.model, mpc.estim, mpc.transcription
228228
weights = mpc.weights
229-
nu, ny, nd, Hp, Hc = model.nu, model.ny, model.nd, mpc.Hp, mpc.Hc
229+
nu, ny, nd, Hp, Hc, nb = model.nu, model.ny, model.nd, mpc.Hp, mpc.Hc, mpc.nb
230230
# --- predictions matrices ---
231-
E, G, J, K, V, B = init_predmat(model, estim, transcription, Hp, Hc)
231+
E, G, J, K, V, B = init_predmat(model, estim, transcription, Hp, Hc, nb)
232232
= E # no slack variable ϵ for ExplicitMPC
233233
mpc.Ẽ .=
234234
mpc.G .= G

src/controller/linmpc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct LinMPC{
6767
PΔu = init_ZtoΔU(estim, transcription, Hp, Hc)
6868
Pu, Tu = init_ZtoU(estim, transcription, Hp, Hc, nb)
6969
E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂ = init_predmat(
70-
model, estim, transcription, Hp, Hc
70+
model, estim, transcription, Hp, Hc, nb
7171
)
7272
Eŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ = init_defectmat(model, estim, transcription, Hp, Hc)
7373
# dummy vals (updated just before optimization):

src/controller/nonlinmpc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct NonLinMPC{
9595
PΔu = init_ZtoΔU(estim, transcription, Hp, Hc)
9696
Pu, Tu = init_ZtoU(estim, transcription, Hp, Hc, nb)
9797
E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂ = init_predmat(
98-
model, estim, transcription, Hp, Hc
98+
model, estim, transcription, Hp, Hc, nb
9999
)
100100
Eŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ = init_defectmat(model, estim, transcription, Hp, Hc)
101101
# dummy vals (updated just before optimization):

src/controller/transcription.jl

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ end
255255

256256
@doc raw"""
257257
init_predmat(
258-
model::LinModel, estim, transcription::SingleShooting, Hp, Hc
258+
model::LinModel, estim, transcription::SingleShooting, Hp, Hc, nb
259259
) -> E, G, J, K, V, ex̂, gx̂, jx̂, kx̂, vx̂
260260
261261
Construct the prediction matrices for [`LinModel`](@ref) and [`SingleShooting`](@ref).
@@ -355,7 +355,7 @@ each control period ``k``, see [`initpred!`](@ref) and [`linconstraint!`](@ref).
355355
```
356356
"""
357357
function init_predmat(
358-
model::LinModel, estim::StateEstimator{NT}, transcription::SingleShooting, Hp, Hc
358+
model::LinModel, estim::StateEstimator{NT}, transcription::SingleShooting, Hp, Hc, nb
359359
) where {NT<:Real}
360360
Â, B̂u, Ĉ, B̂d, D̂d = estim.Â, estim.B̂u, estim.Ĉ, estim.B̂d, estim.D̂d
361361
nu, nx̂, ny, nd = model.nu, estim.nx̂, model.ny, model.nd
@@ -394,10 +394,15 @@ function init_predmat(
394394
ex̂ = Matrix{NT}(undef, nx̂, nZ)
395395
E = zeros(NT, Hp*ny, nZ)
396396
for j=1:Hc # truncated with control horizon
397-
iRow = (ny*(j-1)+1):(ny*Hp)
398397
iCol = (1:nu) .+ nu*(j-1)
399-
E[iRow, iCol] = V[iRow .- ny*(j-1),:]
400-
ex̂[: , iCol] = W(Hp-j)*B̂u
398+
for i=j:Hc
399+
i_Q = i == j ? 0 : nb[i-1]
400+
401+
end
402+
403+
404+
n = j > 1 ? nb[j-1] : 0
405+
ex̂[: , iCol] = W(Hp-n-1)*B̂u
401406
end
402407
# --- current measured disturbances d0 and predictions D̂0 ---
403408
gx̂ = getpower(Âpow, Hp-1)*B̂d
@@ -431,7 +436,7 @@ end
431436

432437
@doc raw"""
433438
init_predmat(
434-
model::LinModel, estim, transcription::MultipleShooting, Hp, Hc
439+
model::LinModel, estim, transcription::MultipleShooting, Hp, Hc, nb
435440
) -> E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂
436441
437442
Construct the prediction matrices for [`LinModel`](@ref) and [`MultipleShooting`](@ref).
@@ -451,7 +456,7 @@ They are defined in the Extended Help section.
451456
```
452457
"""
453458
function init_predmat(
454-
model::LinModel, estim::StateEstimator{NT}, ::MultipleShooting, Hp, Hc
459+
model::LinModel, estim::StateEstimator{NT}, ::MultipleShooting, Hp, Hc, nb
455460
) where {NT<:Real}
456461
Ĉ, D̂d = estim.Ĉ, estim.D̂d
457462
nu, nx̂, ny, nd = model.nu, estim.nx̂, model.ny, model.nd
@@ -476,12 +481,12 @@ function init_predmat(
476481
end
477482

478483
"""
479-
init_predmat(model::NonLinModel, estim, transcription::SingleShooting, Hp, Hc)
484+
init_predmat(model::NonLinModel, estim, transcription::SingleShooting, Hp, Hc, nb)
480485
481486
Return empty matrices for [`SingleShooting`](@ref) of [`NonLinModel`](@ref)
482487
"""
483488
function init_predmat(
484-
model::NonLinModel, estim::StateEstimator{NT}, transcription::SingleShooting, Hp, Hc
489+
model::NonLinModel, estim::StateEstimator{NT}, transcription::SingleShooting, Hp, Hc, _
485490
) where {NT<:Real}
486491
nu, nx̂, nd = model.nu, estim.nx̂, model.nd
487492
nZ = get_nZ(estim, transcription, Hp, Hc)
@@ -496,7 +501,7 @@ function init_predmat(
496501
end
497502

498503
@doc raw"""
499-
init_predmat(model::NonLinModel, estim, transcription::TranscriptionMethod, Hp, Hc)
504+
init_predmat(model::NonLinModel, estim, transcription::TranscriptionMethod, Hp, Hc, nb)
500505
501506
Return the terminal state matrices for [`NonLinModel`](@ref) and other [`TranscriptionMethod`](@ref).
502507
@@ -509,7 +514,7 @@ given in the Extended Help section.
509514
for ``\mathbf{e_x̂} = [\begin{smallmatrix}\mathbf{0} & \mathbf{I}\end{smallmatrix}]``
510515
"""
511516
function init_predmat(
512-
model::NonLinModel, estim::StateEstimator{NT}, transcription::TranscriptionMethod, Hp, Hc
517+
model::NonLinModel, estim::StateEstimator{NT}, transcription::TranscriptionMethod, Hp, Hc, _
513518
) where {NT<:Real}
514519
nu, nx̂, nd = model.nu, estim.nx̂, model.nd
515520
nZ = get_nZ(estim, transcription, Hp, Hc)

0 commit comments

Comments
 (0)