@@ -67,6 +67,7 @@ struct ControllerConstraint
6767 c_Ymax :: Vector{Float64}
6868 c_x̂min :: Vector{Float64}
6969 c_x̂max :: Vector{Float64}
70+ i_C :: BitVector
7071end
7172
7273@doc raw """
@@ -306,9 +307,11 @@ function setconstraint!(
306307 i_Ymin, i_Ymax = .! isinf .(con. Ymin), .! isinf .(con. Ymax)
307308 i_x̂min, i_x̂max = .! isinf .(con. x̂min), .! isinf .(con. x̂max)
308309 if notSolvedYet
309- con. i_b[:], con. A[:] = init_linconstraint (model,
310- i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max,
311- con. A_Umin, con. A_Umax, con. A_ΔŨmin, con. A_ΔŨmax, con. A_Ymin, con. A_Ymax, con. A_x̂min, con. A_x̂max
310+ con. i_b[:], con. i_C[:], con. A[:] = init_matconstraint (model,
311+ i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax,
312+ i_Ymin, i_Ymax, i_x̂min, i_x̂max,
313+ con. A_Umin, con. A_Umax, con. A_ΔŨmin, con. A_ΔŨmax,
314+ con. A_Ymin, con. A_Ymax, con. A_x̂min, con. A_x̂max
312315 )
313316 A = con. A[con. i_b, :]
314317 b = con. b[con. i_b]
@@ -318,8 +321,13 @@ function setconstraint!(
318321 @constraint (mpc. optim, linconstraint, A* ΔŨvar .≤ b)
319322 setnonlincon! (mpc, model)
320323 else
321- i_b, _ = init_linconstraint (model, i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max)
322- i_b == con. i_b || error (" Cannot modify ±Inf constraints after calling moveinput!" )
324+ i_b, i_C = init_matconstraint (model,
325+ i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax,
326+ i_Ymin, i_Ymax, i_x̂min, i_x̂max
327+ )
328+ if i_b ≠ con. i_b || i_C ≠ con. i_C
329+ error (" Cannot modify ±Inf constraints after calling moveinput!" )
330+ end
323331 end
324332 return mpc
325333end
@@ -998,7 +1006,7 @@ function init_defaultcon(estim, Hp, Hc, C, S, N_Hc, E, ex̂, fx̂, gx̂, jx̂, k
9981006 i_ΔŨmin, i_ΔŨmax = .! isinf .(ΔŨmin), .! isinf .(ΔŨmax)
9991007 i_Ymin, i_Ymax = .! isinf .(Ymin), .! isinf .(Ymax)
10001008 i_x̂min, i_x̂max = .! isinf .(x̂min), .! isinf .(x̂max)
1001- i_b, A = init_linconstraint (
1009+ i_b, i_C, A = init_matconstraint (
10021010 model,
10031011 i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max,
10041012 A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂max, A_x̂min
@@ -1008,7 +1016,7 @@ function init_defaultcon(estim, Hp, Hc, C, S, N_Hc, E, ex̂, fx̂, gx̂, jx̂, k
10081016 ẽx̂ , fx̂ , gx̂ , jx̂ , kx̂ , vx̂ ,
10091017 Umin , Umax , ΔŨmin , ΔŨmax , Ymin , Ymax , x̂min , x̂max,
10101018 A_Umin , A_Umax, A_ΔŨmin, A_ΔŨmax , A_Ymin , A_Ymax , A_x̂min , A_x̂max,
1011- A , b , i_b , c_Ymin , c_Ymax , c_x̂min , c_x̂max ,
1019+ A , b , i_b , c_Ymin , c_Ymax , c_x̂min , c_x̂max , i_C
10121020 )
10131021 return con, S̃, Ñ_Hc, Ẽ
10141022end
@@ -1214,42 +1222,52 @@ init_stochpred(estim::StateEstimator, _ ) = zeros(0, estim.nxs), zeros(0, estim.
12141222
12151223
12161224@doc raw """
1217- init_linconstraint( ::LinModel,
1218- i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, args...
1219- ) -> i_b, A
1225+ init_matconstraint(model ::LinModel,
1226+ i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max, args...
1227+ ) -> i_b, i_C, A
12201228
1221- Init `i_b` and `A` for the linear inequality constraints (`` \m athbf{A ΔŨ ≤ b}``) .
1229+ Init `i_b`, `i_C` and `A` matrices for the linear and nonlinear inequality constraints .
12221230
1223- If provided, the arguments in `args` should be all the inequality constraint matrices:
1224- `A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax`. If not provided, it returns an empty `A`
1225- matrix. `i_b` is a `BitVector` including the indices of ``\m athbf{b}`` that are finite
1226- numbers.
1231+ The linear and nonlinear inequality constraints are respectively defined as:
1232+ ```math
1233+ \b egin{aligned}
1234+ \m athbf{A ΔŨ } &≤ \m athbf{b} \\
1235+ \m athbf{C(ΔŨ)} &≤ \m athbf{0}
1236+ \e nd{aligned}
1237+ ```
1238+ `i_b` is a `BitVector` including the indices of ``\m athbf{b}`` that are finite numbers.
1239+ `i_C` is a similar vector but for the indices of ``\m athbf{C}`` (empty if `model` is a
1240+ [`LinModel`](@ref)). The method also returns the ``\m athbf{A}`` matrix if `args` is
1241+ provided. In such a case, `args` needs to contain all the inequality constraint matrices:
1242+ `A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂min, A_x̂max`.
12271243"""
1228- function init_linconstraint (:: LinModel ,
1244+ function init_matconstraint (:: LinModel ,
12291245 i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max, args...
12301246)
12311247 i_b = [i_Umin; i_Umax; i_ΔŨmin; i_ΔŨmax; i_Ymin; i_Ymax; i_x̂min; i_x̂max]
1248+ i_C = BitVector ()
12321249 if isempty (args)
12331250 A = zeros (length (i_b), 0 )
12341251 else
12351252 A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂min, A_x̂max = args
12361253 A = [A_Umin; A_Umax; A_ΔŨmin; A_ΔŨmax; A_Ymin; A_Ymax; A_x̂min; A_x̂max]
12371254 end
1238- return i_b, A
1255+ return i_b, i_C, A
12391256end
12401257
1241- " Init values without predicted output and terminal constraints if `model` is not a [`LinModel`](@ref)."
1242- function init_linconstraint (:: SimModel ,
1243- i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, _ , _ , _ , _ , args...
1258+ " Init `i_b` and `A` without predicted output and terminal constraints if `model` is not a [`LinModel`](@ref)."
1259+ function init_matconstraint (:: SimModel ,
1260+ i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max , args...
12441261)
12451262 i_b = [i_Umin; i_Umax; i_ΔŨmin; i_ΔŨmax]
1263+ i_C = [i_Ymin; i_Ymax; i_x̂min; i_x̂max]
12461264 if isempty (args)
12471265 A = zeros (length (i_b), 0 )
12481266 else
12491267 A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, _ , _ , _ , _ = args
12501268 A = [A_Umin; A_Umax; A_ΔŨmin; A_ΔŨmax]
12511269 end
1252- return i_b, A
1270+ return i_b, i_C, A
12531271end
12541272
12551273" Validate predictive controller weight and horizon specified values."
0 commit comments