@@ -67,6 +67,7 @@ struct ControllerConstraint
67
67
c_Ymax :: Vector{Float64}
68
68
c_x̂min :: Vector{Float64}
69
69
c_x̂max :: Vector{Float64}
70
+ i_C :: BitVector
70
71
end
71
72
72
73
@doc raw """
@@ -306,9 +307,11 @@ function setconstraint!(
306
307
i_Ymin, i_Ymax = .! isinf .(con. Ymin), .! isinf .(con. Ymax)
307
308
i_x̂min, i_x̂max = .! isinf .(con. x̂min), .! isinf .(con. x̂max)
308
309
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
312
315
)
313
316
A = con. A[con. i_b, :]
314
317
b = con. b[con. i_b]
@@ -318,8 +321,13 @@ function setconstraint!(
318
321
@constraint (mpc. optim, linconstraint, A* ΔŨvar .≤ b)
319
322
setnonlincon! (mpc, model)
320
323
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
323
331
end
324
332
return mpc
325
333
end
@@ -998,7 +1006,7 @@ function init_defaultcon(estim, Hp, Hc, C, S, N_Hc, E, ex̂, fx̂, gx̂, jx̂, k
998
1006
i_ΔŨmin, i_ΔŨmax = .! isinf .(ΔŨmin), .! isinf .(ΔŨmax)
999
1007
i_Ymin, i_Ymax = .! isinf .(Ymin), .! isinf .(Ymax)
1000
1008
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 (
1002
1010
model,
1003
1011
i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max,
1004
1012
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
1008
1016
ẽx̂ , fx̂ , gx̂ , jx̂ , kx̂ , vx̂ ,
1009
1017
Umin , Umax , ΔŨmin , ΔŨmax , Ymin , Ymax , x̂min , x̂max,
1010
1018
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
1012
1020
)
1013
1021
return con, S̃, Ñ_Hc, Ẽ
1014
1022
end
@@ -1214,42 +1222,52 @@ init_stochpred(estim::StateEstimator, _ ) = zeros(0, estim.nxs), zeros(0, estim.
1214
1222
1215
1223
1216
1224
@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
1220
1228
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 .
1222
1230
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`.
1227
1243
"""
1228
- function init_linconstraint (:: LinModel ,
1244
+ function init_matconstraint (:: LinModel ,
1229
1245
i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max, args...
1230
1246
)
1231
1247
i_b = [i_Umin; i_Umax; i_ΔŨmin; i_ΔŨmax; i_Ymin; i_Ymax; i_x̂min; i_x̂max]
1248
+ i_C = BitVector ()
1232
1249
if isempty (args)
1233
1250
A = zeros (length (i_b), 0 )
1234
1251
else
1235
1252
A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂min, A_x̂max = args
1236
1253
A = [A_Umin; A_Umax; A_ΔŨmin; A_ΔŨmax; A_Ymin; A_Ymax; A_x̂min; A_x̂max]
1237
1254
end
1238
- return i_b, A
1255
+ return i_b, i_C, A
1239
1256
end
1240
1257
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...
1244
1261
)
1245
1262
i_b = [i_Umin; i_Umax; i_ΔŨmin; i_ΔŨmax]
1263
+ i_C = [i_Ymin; i_Ymax; i_x̂min; i_x̂max]
1246
1264
if isempty (args)
1247
1265
A = zeros (length (i_b), 0 )
1248
1266
else
1249
1267
A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, _ , _ , _ , _ = args
1250
1268
A = [A_Umin; A_Umax; A_ΔŨmin; A_ΔŨmax]
1251
1269
end
1252
- return i_b, A
1270
+ return i_b, i_C, A
1253
1271
end
1254
1272
1255
1273
" Validate predictive controller weight and horizon specified values."
0 commit comments