Skip to content

Commit 92558cb

Browse files
committed
debug setconstraint! (thanks to unit tests!)
1 parent a861719 commit 92558cb

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/predictive_control.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function setconstraint!(
143143
size(c_umin) == (nu,) || error("c_umin size must be $((nu,))")
144144
any(c_umin .< 0) && error("c_umin weights should be non-negative")
145145
c_Umin = repeat(c_umin, Hc)
146-
con.A_Umin[:, end] = +c_Umin
146+
con.A_Umin[:, end] = -c_Umin
147147
end
148148
if !isnothing(c_umax)
149149
!isinf(C) || error("Slack variable Cwt must be finite to set softness parameters")
@@ -157,14 +157,14 @@ function setconstraint!(
157157
size(c_Δumin) == (nu,) || error("c_Δumin size must be $((nu,))")
158158
any(c_Δumin .< 0) && error("c_Δumin weights should be non-negative")
159159
c_ΔUmin = repeat(c_Δumin, Hc)
160-
con.A_ΔUmin[1:end-1, end] = +c_ΔUmin
160+
con.A_ΔŨmin[1:end-1, end] = -c_ΔUmin
161161
end
162162
if !isnothing(c_Δumax)
163163
!isinf(C) || error("Slack variable Cwt must be finite to set softness parameters")
164164
size(c_Δumax) == (nu,) || error("c_Δumax size must be $((nu,))")
165165
any(c_Δumax .< 0) && error("c_Δumax weights should be non-negative")
166166
c_ΔUmax = repeat(c_Δumax, Hc)
167-
con.A_ΔUmax[1:end-1, end] = -c_ΔUmax
167+
con.A_ΔŨmax[1:end-1, end] = -c_ΔUmax
168168
end
169169
if !isnothing(c_ŷmin)
170170
!isinf(C) || error("Slack variable Cwt must be finite to set softness parameters")

test/test_predictive_control.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ setconstraint!(mpc, Δumin=[-5,-10], Δumax=[6,11])
4646
setconstraint!(mpc, ŷmin=[5,10],ŷmax=[55, 35])
4747
@test all((mpc.con.Ŷmin, mpc.con.Ŷmax) .≈ ([5,10], [55,35]))
4848
setconstraint!(mpc, c_umin=[0.1,0.2], c_umax=[0.3,0.4])
49-
@test all((mpc.con.c_Umin, mpc.con.c_Umax) .≈ ([0.1,0.2], [0.3,0.4]))
49+
@test all((-mpc.con.A_Umin[:, end], -mpc.con.A_Umax[:, end]) .≈ ([0.1,0.2], [0.3,0.4]))
5050
setconstraint!(mpc, c_Δumin=[0.05,0.15], c_Δumax=[0.25,0.35])
51-
@test all((mpc.con.c_ΔUmin, mpc.con.c_ΔUmax) .≈ ([0.05,0.15], [0.25,0.35]))
51+
@test all((-mpc.con.A_ΔŨmin[1:end-1, end], -mpc.con.A_ΔŨmax[1:end-1, end]) .≈ ([0.05,0.15], [0.25,0.35]))
5252
setconstraint!(mpc, c_ŷmin=[1.0,1.1], c_ŷmax=[1.2,1.3])
53-
@test all((mpc.con.c_Ŷmin, mpc.con.c_Ŷmax) .≈ ([1.0,1.1], [1.2,1.3]))
53+
@test all((-mpc.con.A_Ŷmin[:, end], -mpc.con.A_Ŷmax[:, end]) .≈ ([1.0,1.1], [1.2,1.3]))
5454

5555
end
5656

0 commit comments

Comments
 (0)