Skip to content

Commit d81f920

Browse files
committed
improved type stability by forcing tge type of JuMP decision variable in optim_objective!
1 parent 160376c commit d81f920

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

example/juMPC.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function test_mpc(model, mpc)
118118
y = model(d)
119119
if k 180
120120
y[1] += 15
121-
end
121+
end
122122
u = moveinput!(mpc, r, d)
123123
u_data[:,k+1] = u
124124
y_data[:,k+1] = y
@@ -131,7 +131,7 @@ function test_mpc(model, mpc)
131131
end
132132

133133
u_data, y_data, r_data, d_data = test_mpc(linModel4, mpc)
134-
#@profview u_data, y_data, r_data, d_data = test_mpc(linModel4, mpc)
134+
@profview u_data, y_data, r_data, d_data = test_mpc(linModel4, mpc)
135135
#=
136136
using PlotThemes, Plots
137137
#theme(:default)

src/predictive_control.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ Predict the current `ŷs` and future `Ŷs` stochastic model outputs over `Hp`.
726726
727727
See [`init_stochpred`](@ref) for details on `Ŷs` and `Ks` matrices.
728728
"""
729-
predict_stoch(mpc, estim::StateEstimator, x̂s, d, _ ) = (estim.Cs*x̂s, mpc.Ks*x̂s)
729+
predict_stoch(mpc, estim::StateEstimator, x̂s, _ , _ ) = (estim.Cs*x̂s, mpc.Ks*x̂s)
730730

731731
"""
732732
predict_stoch(mpc, estim::InternalModel, x̂s, d, ym )
@@ -809,7 +809,7 @@ Optimize the `mpc` quadratic objective function for [`LinMPC`](@ref) type.
809809
function optim_objective!(mpc::LinMPC, b, q̃, p)
810810
optim = mpc.optim
811811
model = mpc.estim.model
812-
ΔŨ = optim[:ΔŨ]
812+
ΔŨ::Vector{VariableRef} = optim[:ΔŨ]
813813
lastΔŨ = mpc.info.ΔŨ
814814
set_objective_function(optim, obj_quadprog(ΔŨ, mpc.P̃, q̃))
815815
set_normalized_rhs.(optim[:linconstraint], b)
@@ -834,9 +834,9 @@ function optim_objective!(mpc::LinMPC, b, q̃, p)
834834
@warn "MPC termination status not OPTIMAL or LOCALLY_SOLVED ($status)"
835835
@debug solution_summary(optim)
836836
end
837-
ΔŨ = isfatal(status) ? ΔŨ0 : value.(ΔŨ) # fatal status : use last value
838-
J = objective_value(optim) + p # optimal objective value by adding constant p
839-
return ΔŨ, J
837+
ΔŨ_val = isfatal(status) ? ΔŨ0 : value.(ΔŨ) # fatal status : use last value
838+
J_val = objective_value(optim) + p # optimal objective value by adding constant p
839+
return ΔŨ_val, J_val
840840
end
841841

842842
"""

0 commit comments

Comments
 (0)