Skip to content

Commit 9a7e2e9

Browse files
committed
minor doc correction
1 parent 4e2c0c5 commit 9a7e2e9

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

src/controller/explicitmpc.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ struct ExplicitMPC{NT<:Real, SE<:StateEstimator} <: PredictiveController{NT}
5353
# dummy vals (updated just before optimization):
5454
d0, D̂0, D̂E = zeros(NT, nd), zeros(NT, nd*Hp), zeros(NT, nd + nd*Hp)
5555
Ŷop, Dop = repeat(model.yop, Hp), repeat(model.dop, Hp)
56-
nvar = size(Ẽ, 2)
57-
ΔŨ = zeros(NT, nvar)
56+
nΔŨ = size(Ẽ, 2)
57+
ΔŨ = zeros(NT, nΔŨ)
5858
mpc = new{NT, SE}(
5959
estim,
6060
ΔŨ, ŷ,

src/controller/linmpc.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ struct LinMPC{
6060
# dummy vals (updated just before optimization):
6161
d0, D̂0, D̂E = zeros(NT, nd), zeros(NT, nd*Hp), zeros(NT, nd + nd*Hp)
6262
Ŷop, Dop = repeat(model.yop, Hp), repeat(model.dop, Hp)
63-
nvar = size(Ẽ, 2)
64-
ΔŨ = zeros(NT, nvar)
63+
nΔŨ = size(Ẽ, 2)
64+
ΔŨ = zeros(NT, nΔŨ)
6565
mpc = new{NT, SE, JM}(
6666
estim, optim, con,
6767
ΔŨ, ŷ,
@@ -233,10 +233,10 @@ Init the quadratic optimization for [`LinMPC`](@ref) controllers.
233233
function init_optimization!(mpc::LinMPC, optim::JuMP.GenericModel)
234234
# --- variables and linear constraints ---
235235
con = mpc.con
236-
nvar = length(mpc.ΔŨ)
236+
nΔŨ = length(mpc.ΔŨ)
237237
set_silent(optim)
238238
limit_solve_time(mpc)
239-
@variable(optim, ΔŨvar[1:nvar])
239+
@variable(optim, ΔŨvar[1:nΔŨ])
240240
A = con.A[con.i_b, :]
241241
b = con.b[con.i_b]
242242
@constraint(optim, linconstraint, A*ΔŨvar .≤ b)

src/controller/nonlinmpc.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ struct NonLinMPC{
6161
# dummy vals (updated just before optimization):
6262
d0, D̂0, D̂E = zeros(NT, nd), zeros(NT, nd*Hp), zeros(NT, nd + nd*Hp)
6363
Ŷop, Dop = repeat(model.yop, Hp), repeat(model.dop, Hp)
64-
nvar = size(Ẽ, 2)
65-
ΔŨ = zeros(NT, nvar)
64+
nΔŨ = size(Ẽ, 2)
65+
ΔŨ = zeros(NT, nΔŨ)
6666
mpc = new{NT, SE, JM, JEFunc}(
6767
estim, optim, con,
6868
ΔŨ, ŷ,
@@ -274,22 +274,22 @@ Init the nonlinear optimization for [`NonLinMPC`](@ref) controllers.
274274
function init_optimization!(mpc::NonLinMPC, optim::JuMP.GenericModel{JNT}) where JNT<:Real
275275
# --- variables and linear constraints ---
276276
con = mpc.con
277-
nvar = length(mpc.ΔŨ)
277+
nΔŨ = length(mpc.ΔŨ)
278278
set_silent(optim)
279279
limit_solve_time(mpc)
280-
@variable(optim, ΔŨvar[1:nvar])
280+
@variable(optim, ΔŨvar[1:nΔŨ])
281281
A = con.A[con.i_b, :]
282282
b = con.b[con.i_b]
283283
@constraint(optim, linconstraint, A*ΔŨvar .≤ b)
284284
# --- nonlinear optimization init ---
285285
model = mpc.estim.model
286286
ny, nx̂, Hp, ng = model.ny, mpc.estim.nx̂, mpc.Hp, length(con.i_g)
287287
# inspired from https://jump.dev/JuMP.jl/stable/tutorials/nonlinear/tips_and_tricks/#User-defined-operators-with-vector-outputs
288-
Jfunc, gfunc = let mpc=mpc, model=model, ng=ng, nvar=nvar , nŶ=Hp*ny, nx̂=nx̂
288+
Jfunc, gfunc = let mpc=mpc, model=model, ng=ng, nΔŨ=nΔŨ , nŶ=Hp*ny, nx̂=nx̂
289289
last_ΔŨtup_float, last_ΔŨtup_dual = nothing, nothing
290-
Ŷ_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nŶ), nvar + 3)
291-
g_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, ng), nvar + 3)
292-
x̂_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nx̂), nvar + 3)
290+
Ŷ_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nŶ), nΔŨ + 3)
291+
g_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, ng), nΔŨ + 3)
292+
x̂_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nx̂), nΔŨ + 3)
293293
function Jfunc(ΔŨtup::JNT...)
294294
= get_tmp(Ŷ_cache, ΔŨtup[1])
295295
ΔŨ = collect(ΔŨtup)
@@ -341,27 +341,27 @@ function init_optimization!(mpc::NonLinMPC, optim::JuMP.GenericModel{JNT}) where
341341
gfunc = [(ΔŨ...) -> gfunc_i(i, ΔŨ) for i in 1:ng]
342342
(Jfunc, gfunc)
343343
end
344-
register(optim, :Jfunc, nvar, Jfunc, autodiff=true)
344+
register(optim, :Jfunc, nΔŨ, Jfunc, autodiff=true)
345345
@NLobjective(optim, Min, Jfunc(ΔŨvar...))
346346
if ng 0
347347
for i in eachindex(con.Ymin)
348348
sym = Symbol("g_Ymin_$i")
349-
register(optim, sym, nvar, gfunc[i], autodiff=true)
349+
register(optim, sym, nΔŨ, gfunc[i], autodiff=true)
350350
end
351351
i_end_Ymin = 1Hp*ny
352352
for i in eachindex(con.Ymax)
353353
sym = Symbol("g_Ymax_$i")
354-
register(optim, sym, nvar, gfunc[i_end_Ymin+i], autodiff=true)
354+
register(optim, sym, nΔŨ, gfunc[i_end_Ymin+i], autodiff=true)
355355
end
356356
i_end_Ymax = 2Hp*ny
357357
for i in eachindex(con.x̂min)
358358
sym = Symbol("g_x̂min_$i")
359-
register(optim, sym, nvar, gfunc[i_end_Ymax+i], autodiff=true)
359+
register(optim, sym, nΔŨ, gfunc[i_end_Ymax+i], autodiff=true)
360360
end
361361
i_end_x̂min = 2Hp*ny + nx̂
362362
for i in eachindex(con.x̂max)
363363
sym = Symbol("g_x̂max_$i")
364-
register(optim, sym, nvar, gfunc[i_end_x̂min+i], autodiff=true)
364+
register(optim, sym, nΔŨ, gfunc[i_end_x̂min+i], autodiff=true)
365365
end
366366
end
367367
return nothing

src/estimator/mhe.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ end
145145
@doc raw"""
146146
MovingHorizonEstimator(model::SimModel; <keyword arguments>)
147147
148-
Construct a moving horizon estimator based on `model` ([`LinModel`](@ref) or [`NonLinModel`](@ref)).
148+
Construct a moving horizon estimator (MHE) based on `model` ([`LinModel`](@ref) or [`NonLinModel`](@ref)).
149149
150150
This estimator can handle constraints on the estimates, see [`setconstraint!`](@ref).
151151
Additionally, `model` is not linearized like the [`ExtendedKalmanFilter`](@ref), and the
@@ -519,10 +519,10 @@ function init_optimization!(
519519
He, con = estim.He, estim.con
520520
nŶm, nX̂, ng = He*estim.nym, He*estim.nx̂, length(con.i_g)
521521
# --- variables and linear constraints ---
522-
nvar = length(estim.Z̃)
522+
nZ̃ = length(estim.Z̃)
523523
set_silent(optim)
524524
#limit_solve_time(estim) #TODO: add this feature
525-
@variable(optim, Z̃var[1:nvar])
525+
@variable(optim, Z̃var[1:nZ̃])
526526
A = con.A[con.i_b, :]
527527
b = con.b[con.i_b]
528528
@constraint(optim, linconstraint, A*Z̃var .≤ b)
@@ -541,20 +541,20 @@ function init_optimization!(
541541
He, con = estim.He, estim.con
542542
nV̂, nX̂, ng = He*estim.nym, He*estim.nx̂, length(con.i_g)
543543
# --- variables and linear constraints ---
544-
nvar = length(estim.Z̃)
544+
nZ̃ = length(estim.Z̃)
545545
set_silent(optim)
546546
#limit_solve_time(estim) #TODO: add this feature
547-
@variable(optim, Z̃var[1:nvar])
547+
@variable(optim, Z̃var[1:nZ̃])
548548
A = con.A[con.i_b, :]
549549
b = con.b[con.i_b]
550550
@constraint(optim, linconstraint, A*Z̃var .≤ b)
551551
# --- nonlinear optimization init ---
552552
# see init_optimization!(mpc::NonLinMPC, optim) for details on the inspiration
553-
Jfunc, gfunc = let estim=estim, model=model, nvar=nvar , nV̂=nV̂, nX̂=nX̂, ng=ng
553+
Jfunc, gfunc = let estim=estim, model=model, nZ̃=nZ̃ , nV̂=nV̂, nX̂=nX̂, ng=ng
554554
last_Z̃tup_float, last_Z̃tup_dual = nothing, nothing
555-
V̂_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nV̂), nvar + 3)
556-
g_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, ng), nvar + 3)
557-
X̂_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nX̂), nvar + 3)
555+
V̂_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nV̂), nZ̃ + 3)
556+
g_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, ng), nZ̃ + 3)
557+
X̂_cache::DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache(zeros(JNT, nX̂), nZ̃ + 3)
558558
function Jfunc(Z̃tup::JNT...)
559559
= get_tmp(V̂_cache, Z̃tup[1])
560560
= collect(Z̃tup)
@@ -606,27 +606,27 @@ function init_optimization!(
606606
gfunc = [(Z̃...) -> gfunc_i(i, Z̃) for i in 1:ng]
607607
Jfunc, gfunc
608608
end
609-
register(optim, :Jfunc, nvar, Jfunc, autodiff=true)
609+
register(optim, :Jfunc, nZ̃, Jfunc, autodiff=true)
610610
@NLobjective(optim, Min, Jfunc(Z̃var...))
611611
if ng 0
612612
for i in eachindex(con.X̂min)
613613
sym = Symbol("g_X̂min_$i")
614-
register(optim, sym, nvar, gfunc[i], autodiff=true)
614+
register(optim, sym, nZ̃, gfunc[i], autodiff=true)
615615
end
616616
i_end_X̂min = nX̂
617617
for i in eachindex(con.X̂max)
618618
sym = Symbol("g_X̂max_$i")
619-
register(optim, sym, nvar, gfunc[i_end_X̂min+i], autodiff=true)
619+
register(optim, sym, nZ̃, gfunc[i_end_X̂min+i], autodiff=true)
620620
end
621621
i_end_X̂max = 2*nX̂
622622
for i in eachindex(con.V̂min)
623623
sym = Symbol("g_V̂min_$i")
624-
register(optim, sym, nvar, gfunc[i_end_X̂max+i], autodiff=true)
624+
register(optim, sym, nZ̃, gfunc[i_end_X̂max+i], autodiff=true)
625625
end
626626
i_end_V̂min = 2*nX̂ + nV̂
627627
for i in eachindex(con.V̂max)
628628
sym = Symbol("g_V̂max_$i")
629-
register(optim, sym, nvar, gfunc[i_end_V̂min+i], autodiff=true)
629+
register(optim, sym, nZ̃, gfunc[i_end_V̂min+i], autodiff=true)
630630
end
631631
end
632632
return nothing

0 commit comments

Comments
 (0)