diff --git a/Project.toml b/Project.toml index 7c2b7a18b..8987dada6 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ModelPredictiveControl" uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c" -version = "2.4.4" +version = "2.5.0" authors = ["Francis Gagnon"] [deps] diff --git a/src/controller/construct.jl b/src/controller/construct.jl index 67e50d986..b1a661995 100644 --- a/src/controller/construct.jl +++ b/src/controller/construct.jl @@ -454,58 +454,58 @@ function setconstraint!( if !isnothing(C_umin) size(C_umin) == (nu*Hp,) || throw(DimensionMismatch("C_umin size must be $((nu*Hp,))")) any(<(0), C_umin) && error("C_umin weights should be non-negative") - con.A_Umin[:, end] .= -C_umin + con.A_Umin[:, end] .= @. -C_umin end if !isnothing(C_umax) size(C_umax) == (nu*Hp,) || throw(DimensionMismatch("C_umax size must be $((nu*Hp,))")) any(<(0), C_umax) && error("C_umax weights should be non-negative") - con.A_Umax[:, end] .= -C_umax + con.A_Umax[:, end] .= @. -C_umax end if !isnothing(C_Δumin) size(C_Δumin) == (nu*Hc,) || throw(DimensionMismatch("C_Δumin size must be $((nu*Hc,))")) any(<(0), C_Δumin) && error("C_Δumin weights should be non-negative") - con.A_ΔUmin[:, end] .= -C_Δumin + con.A_ΔUmin[:, end] .= @. -C_Δumin end if !isnothing(C_Δumax) size(C_Δumax) == (nu*Hc,) || throw(DimensionMismatch("C_Δumax size must be $((nu*Hc,))")) any(<(0), C_Δumax) && error("C_Δumax weights should be non-negative") - con.A_ΔUmax[:, end] .= -C_Δumax + con.A_ΔUmax[:, end] .= @. -C_Δumax end if !isnothing(C_ymin) size(C_ymin) == (ny*Hp,) || throw(DimensionMismatch("C_ymin size must be $((ny*Hp,))")) any(<(0), C_ymin) && error("C_ymin weights should be non-negative") con.C_ymin .= C_ymin - size(con.A_Ymin, 1) ≠ 0 && (con.A_Ymin[:, end] .= -con.C_ymin) # for LinModel + size(con.A_Ymin, 1) ≠ 0 && (con.A_Ymin[:, end] .= @. -con.C_ymin) # for LinModel end if !isnothing(C_ymax) size(C_ymax) == (ny*Hp,) || throw(DimensionMismatch("C_ymax size must be $((ny*Hp,))")) any(<(0), C_ymax) && error("C_ymax weights should be non-negative") con.C_ymax .= C_ymax - size(con.A_Ymax, 1) ≠ 0 && (con.A_Ymax[:, end] .= -con.C_ymax) # for LinModel + size(con.A_Ymax, 1) ≠ 0 && (con.A_Ymax[:, end] .= @. -con.C_ymax) # for LinModel end if !isnothing(C_wmin) size(C_wmin) == (nw*(Hp+1),) || throw(DimensionMismatch("C_wmin size must be $((nw*(Hp+1),))")) any(<(0), C_wmin) && error("C_wmin weights should be non-negative") con.C_wmin .= C_wmin - con.A_Wmin[:, end] .= -C_wmin + con.A_Wmin[:, end] .= @. -C_wmin end if !isnothing(C_wmax) size(C_wmax) == (nw*(Hp+1),) || throw(DimensionMismatch("C_wmax size must be $((nw*(Hp+1),))")) any(<(0), C_wmax) && error("C_wmax weights should be non-negative") con.C_wmax .= C_wmax - con.A_Wmax[:, end] .= -C_wmax + con.A_Wmax[:, end] .= @. -C_wmax end if !isnothing(c_x̂min) size(c_x̂min) == (nx̂,) || throw(DimensionMismatch("c_x̂min size must be $((nx̂,))")) any(<(0), c_x̂min) && error("c_x̂min weights should be non-negative") con.c_x̂min .= c_x̂min - size(con.A_x̂min, 1) ≠ 0 && (con.A_x̂min[:, end] .= -con.c_x̂min) # for LinModel + size(con.A_x̂min, 1) ≠ 0 && (con.A_x̂min[:, end] .= @. -con.c_x̂min) # for LinModel end if !isnothing(c_x̂max) size(c_x̂max) == (nx̂,) || throw(DimensionMismatch("c_x̂max size must be $((nx̂,))")) any(<(0), c_x̂max) && error("c_x̂max weights should be non-negative") con.c_x̂max .= c_x̂max - size(con.A_x̂max, 1) ≠ 0 && (con.A_x̂max[:, end] .= -con.c_x̂max) # for LinModel + size(con.A_x̂max, 1) ≠ 0 && (con.A_x̂max[:, end] .= @. -con.c_x̂max) # for LinModel end end Z̃min, Z̃max = init_boxconstraint_mpc( diff --git a/src/estimator/mhe/construct.jl b/src/estimator/mhe/construct.jl index 31fba8354..07b13ab7c 100644 --- a/src/estimator/mhe/construct.jl +++ b/src/estimator/mhe/construct.jl @@ -922,15 +922,15 @@ function setconstraint!( if !isnothing(C_x̂min) size(C_x̂min) == (nX̂con,) || throw(DimensionMismatch("C_x̂min size must be $((nX̂con,))")) any(C_x̂min .< 0) && error("C_x̂min weights should be non-negative") - con.A_x̂min[:, begin] .= @views -C_x̂min[1:nx̂] - con.C_x̂min .= @views C_x̂min[nx̂+1:end] + con.A_x̂min[:, begin] .= @. @views -C_x̂min[1:nx̂] + con.C_x̂min .= @. @views C_x̂min[nx̂+1:end] size(con.A_X̂min, 1) ≠ 0 && (con.A_X̂min[:, begin] = -con.C_x̂min) # for LinModel end if !isnothing(C_x̂max) size(C_x̂max) == (nX̂con,) || throw(DimensionMismatch("C_x̂max size must be $((nX̂con,))")) any(C_x̂max .< 0) && error("C_x̂max weights should be non-negative") - con.A_x̂max[:, begin] .= @views -C_x̂max[1:nx̂] - con.C_x̂max .= @views C_x̂max[nx̂+1:end] + con.A_x̂max[:, begin] .= @. @views -C_x̂max[1:nx̂] + con.C_x̂max .= @. @views C_x̂max[nx̂+1:end] size(con.A_X̂max, 1) ≠ 0 && (con.A_X̂max[:, begin] = -con.C_x̂max) # for LinModel end if !isnothing(C_ŵmin)