Skip to content

Commit 128922f

Browse files
committed
changed: warm-start called Z̃s in the code (like in doc)
1 parent 239b4fd commit 128922f

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

src/controller/execute.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ function optim_objective!(mpc::PredictiveController{NT}) where {NT<:Real}
395395
model, optim = mpc.estim.model, mpc.optim
396396
nu, Hc = model.nu, mpc.Hc
397397
Z̃var::Vector{JuMP.VariableRef} = optim[:Z̃var]
398-
Z̃0 = set_warmstart!(mpc, mpc.transcription, Z̃var)
398+
Z̃s = set_warmstart!(mpc, mpc.transcription, Z̃var)
399399
set_objective_linear_coef!(mpc, Z̃var)
400400
try
401401
JuMP.optimize!(optim)
@@ -426,7 +426,7 @@ function optim_objective!(mpc::PredictiveController{NT}) where {NT<:Real}
426426
@debug info2debugstr(getinfo(mpc))
427427
end
428428
if iserror(optim)
429-
mpc.Z̃ .= Z̃0
429+
mpc.Z̃ .= Z̃s
430430
else
431431
mpc.Z̃ .= JuMP.value.(Z̃var)
432432
end

src/controller/transcription.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -972,14 +972,14 @@ where ``\mathbf{Δu}(k+j|k-1)`` is the input increment for time ``k+j`` computed
972972
last control period ``k-1``, and ``ϵ(k-1)``, the slack variable of the last control period.
973973
"""
974974
function set_warmstart!(mpc::PredictiveController, transcription::SingleShooting, Z̃var)
975-
nu, Hc, Z̃0 = mpc.estim.model.nu, mpc.Hc, mpc.buffer.
975+
nu, Hc, Z̃s = mpc.estim.model.nu, mpc.Hc, mpc.buffer.
976976
# --- input increments ΔU ---
977-
Z̃0[1:(Hc*nu-nu)] .= @views mpc.Z̃[nu+1:Hc*nu]
978-
Z̃0[(Hc*nu-nu+1):(Hc*nu)] .= 0
977+
Z̃s[1:(Hc*nu-nu)] .= @views mpc.Z̃[nu+1:Hc*nu]
978+
Z̃s[(Hc*nu-nu+1):(Hc*nu)] .= 0
979979
# --- slack variable ϵ ---
980-
mpc.== 1 && (Z̃0[end] = mpc.Z̃[end])
981-
JuMP.set_start_value.(Z̃var, Z̃0)
982-
return Z̃0
980+
mpc.== 1 && (Z̃s[end] = mpc.Z̃[end])
981+
JuMP.set_start_value.(Z̃var, Z̃s)
982+
return Z̃s
983983
end
984984

985985
@doc raw"""
@@ -1009,17 +1009,17 @@ last control period ``k-1``, expressed as a deviation from the operating point
10091009
``\mathbf{x̂_{op}}``.
10101010
"""
10111011
function set_warmstart!(mpc::PredictiveController, transcription::MultipleShooting, Z̃var)
1012-
nu, nx̂, Hp, Hc, Z̃0 = mpc.estim.model.nu, mpc.estim.nx̂, mpc.Hp, mpc.Hc, mpc.buffer.
1012+
nu, nx̂, Hp, Hc, Z̃s = mpc.estim.model.nu, mpc.estim.nx̂, mpc.Hp, mpc.Hc, mpc.buffer.
10131013
# --- input increments ΔU ---
1014-
Z̃0[1:(Hc*nu-nu)] .= @views mpc.Z̃[nu+1:Hc*nu]
1015-
Z̃0[(Hc*nu-nu+1):(Hc*nu)] .= 0
1014+
Z̃s[1:(Hc*nu-nu)] .= @views mpc.Z̃[nu+1:Hc*nu]
1015+
Z̃s[(Hc*nu-nu+1):(Hc*nu)] .= 0
10161016
# --- predicted states X̂0 ---
1017-
Z̃0[(Hc*nu+1):(Hc*nu+Hp*nx̂-nx̂)] .= @views mpc.Z̃[(Hc*nu+nx̂+1):(Hc*nu+Hp*nx̂)]
1018-
Z̃0[(Hc*nu+Hp*nx̂-nx̂+1):(Hc*nu+Hp*nx̂)] .= @views mpc.Z̃[(Hc*nu+Hp*nx̂-nx̂+1):(Hc*nu+Hp*nx̂)]
1017+
Z̃s[(Hc*nu+1):(Hc*nu+Hp*nx̂-nx̂)] .= @views mpc.Z̃[(Hc*nu+nx̂+1):(Hc*nu+Hp*nx̂)]
1018+
Z̃s[(Hc*nu+Hp*nx̂-nx̂+1):(Hc*nu+Hp*nx̂)] .= @views mpc.Z̃[(Hc*nu+Hp*nx̂-nx̂+1):(Hc*nu+Hp*nx̂)]
10191019
# --- slack variable ϵ ---
1020-
mpc.== 1 && (Z̃0[end] = mpc.Z̃[end])
1021-
JuMP.set_start_value.(Z̃var, Z̃0)
1022-
return Z̃0
1020+
mpc.== 1 && (Z̃s[end] = mpc.Z̃[end])
1021+
JuMP.set_start_value.(Z̃var, Z̃s)
1022+
return Z̃s
10231023
end
10241024

10251025
getΔŨ!(ΔŨ, mpc::PredictiveController, ::SingleShooting, Z̃) = (ΔŨ .= Z̃) # since mpc.P̃Δu = I

src/estimator/mhe/execute.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ Optimize objective of `estim` [`MovingHorizonEstimator`](@ref) and return the so
364364
365365
If supported by `estim.optim`, it warm-starts the solver at:
366366
```math
367-
\mathbf{} =
367+
\mathbf{Z̃_s} =
368368
\begin{bmatrix}
369369
ϵ_{k-1} \\
370370
\mathbf{x̂}_{k-1}(k-N_k+p) \\
@@ -391,12 +391,12 @@ function optim_objective!(estim::MovingHorizonEstimator{NT}) where NT<:Real
391391
X̂0 = Vector{NT}(undef, nx̂*Nk)
392392
û0, ŷ0, x̄, k0 = buffer.û, buffer.ŷ, buffer.x̂, buffer.k
393393
ϵ_0 = estim. 0 ? estim.Z̃[begin] : empty(estim.Z̃)
394-
Z̃_0 = [ϵ_0; estim.x̂0arr_old; estim.Ŵ]
395-
V̂, X̂0 = predict!(V̂, X̂0, û0, k0, ŷ0, estim, model, Z̃_0)
396-
J_0 = obj_nonlinprog!(x̄, estim, model, V̂, Z̃_0)
397-
# initial Z̃0 with Ŵ=0 if objective or constraint function not finite :
398-
isfinite(J_0) || (Z̃_0 = [ϵ_0; estim.x̂0arr_old; zeros(NT, nŵ*estim.He)])
399-
JuMP.set_start_value.(Z̃var, Z̃_0)
394+
Z̃s = [ϵ_0; estim.x̂0arr_old; estim.Ŵ]
395+
V̂, X̂0 = predict!(V̂, X̂0, û0, k0, ŷ0, estim, model, Z̃s)
396+
J_0 = obj_nonlinprog!(x̄, estim, model, V̂, Z̃s)
397+
# warm-start Z̃s with Ŵ=0 if objective or constraint function not finite :
398+
isfinite(J_0) || (Z̃s = [ϵ_0; estim.x̂0arr_old; zeros(NT, nŵ*estim.He)])
399+
JuMP.set_start_value.(Z̃var, Z̃s)
400400
# ------- solve optimization problem --------------
401401
try
402402
JuMP.optimize!(optim)
@@ -428,7 +428,7 @@ function optim_objective!(estim::MovingHorizonEstimator{NT}) where NT<:Real
428428
@debug info2debugstr(getinfo(estim))
429429
end
430430
if iserror(optim)
431-
estim.Z̃ .= Z̃_0
431+
estim.Z̃ .= Z̃s
432432
else
433433
estim.Z̃ .= JuMP.value.(Z̃var)
434434
end

0 commit comments

Comments
 (0)