Skip to content

Commit 2f227f7

Browse files
committed
test: replicate tests but with oracle=false
1 parent 7c2a8c9 commit 2f227f7

File tree

2 files changed

+154
-0
lines changed

2 files changed

+154
-0
lines changed

test/2_test_state_estim.jl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,13 @@ end
11901190
setconstraint!(mhe3, C_v̂min=0.03(11:18), C_v̂max=0.04(11:18))
11911191
@test all((mhe3.con.C_v̂min, mhe3.con.C_v̂max) .≈ (0.03(11:18), 0.04(11:18)))
11921192

1193+
# TODO: delete these tests when the deprecated legacy splatting syntax will be.
1194+
mhe4 = MovingHorizonEstimator(nonlinmodel, He=4, nint_ym=0, Cwt=1e3, oracle=false)
1195+
setconstraint!(mhe3, C_x̂min=0.01(1:10), C_x̂max=0.02(1:10))
1196+
@test all((mhe3.con.C_x̂min, mhe3.con.C_x̂max) .≈ (0.01(3:10), 0.02(3:10)))
1197+
setconstraint!(mhe3, C_v̂min=0.03(11:18), C_v̂max=0.04(11:18))
1198+
@test all((mhe3.con.C_v̂min, mhe3.con.C_v̂max) .≈ (0.03(11:18), 0.04(11:18)))
1199+
11931200
@test_throws ArgumentError setconstraint!(mhe2, x̂min=[-1])
11941201
@test_throws ArgumentError setconstraint!(mhe2, x̂max=[+1])
11951202
@test_throws ArgumentError setconstraint!(mhe2, ŵmin=[-1])
@@ -1325,6 +1332,54 @@ end
13251332
= updatestate!(mhe2, [10, 50], [50, 30])
13261333
info = getinfo(mhe2)
13271334
@test info[:V̂] [-1,-1] atol=5e-2
1335+
1336+
# TODO: delete these tests when the deprecated legacy splatting syntax will be.
1337+
mhe3 = MovingHorizonEstimator(nonlinmodel, He=1, nint_ym=0, oracle=false)
1338+
1339+
setconstraint!(mhe3, x̂min=[-100,-100], x̂max=[100,100])
1340+
setconstraint!(mhe3, ŵmin=[-100,-100], ŵmax=[100,100])
1341+
setconstraint!(mhe3, v̂min=[-100,-100], v̂max=[100,100])
1342+
1343+
setconstraint!(mhe3, x̂min=[1,1], x̂max=[100,100])
1344+
preparestate!(mhe3, [50, 30])
1345+
= updatestate!(mhe3, [10, 50], [50, 30])
1346+
@test [1, 1] atol=5e-2
1347+
1348+
setconstraint!(mhe3, x̂min=[-100,-100], x̂max=[-1,-1])
1349+
preparestate!(mhe3, [50, 30])
1350+
= updatestate!(mhe3, [10, 50], [50, 30])
1351+
@test [-1, -1] atol=5e-2
1352+
1353+
setconstraint!(mhe3, x̂min=[-100,-100], x̂max=[100,100])
1354+
setconstraint!(mhe3, ŵmin=[-100,-100], ŵmax=[100,100])
1355+
setconstraint!(mhe3, v̂min=[-100,-100], v̂max=[100,100])
1356+
1357+
setconstraint!(mhe3, ŵmin=[1,1], ŵmax=[100,100])
1358+
preparestate!(mhe3, [50, 30])
1359+
= updatestate!(mhe3, [10, 50], [50, 30])
1360+
@test mhe3. [1,1] atol=5e-2
1361+
1362+
setconstraint!(mhe3, ŵmin=[-100,-100], ŵmax=[-1,-1])
1363+
preparestate!(mhe3, [50, 30])
1364+
= updatestate!(mhe3, [10, 50], [50, 30])
1365+
@test mhe3. [-1,-1] atol=5e-2
1366+
1367+
setconstraint!(mhe3, x̂min=[-100,-100], x̂max=[100,100])
1368+
setconstraint!(mhe3, ŵmin=[-100,-100], ŵmax=[100,100])
1369+
setconstraint!(mhe3, v̂min=[-100,-100], v̂max=[100,100])
1370+
1371+
setconstraint!(mhe3, v̂min=[1,1], v̂max=[100,100])
1372+
preparestate!(mhe3, [50, 30])
1373+
= updatestate!(mhe3, [10, 50], [50, 30])
1374+
info = getinfo(mhe3)
1375+
@test info[:V̂] [1,1] atol=5e-2
1376+
1377+
setconstraint!(mhe3, v̂min=[-100,-100], v̂max=[-1,-1])
1378+
preparestate!(mhe3, [50, 30])
1379+
= updatestate!(mhe3, [10, 50], [50, 30])
1380+
info = getinfo(mhe3)
1381+
@test info[:V̂] [-1,-1] atol=5e-2
1382+
13281383
end
13291384

13301385
@testitem "MovingHorizonEstimator set model" setup=[SetupMPCtests] begin

test/3_test_predictive_control.jl

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,35 @@ end
10331033
)
10341034
@test all((nmpc.con.c_x̂min, nmpc.con.c_x̂max) .≈
10351035
([0.21,0.22,0.23,0.24,0.25,0.26], [0.31,0.32,0.33,0.34,0.35,0.36]))
1036+
1037+
# TODO: delete these tests when the deprecated legacy splatting syntax will be.
1038+
nmpc_leg = NonLinMPC(nonlinmodel, Hp=1, Hc=1, oracle=false)
1039+
1040+
setconstraint!(nmpc_leg, umin=[-5, -9.9], umax=[100,99])
1041+
@test all((nmpc_leg.con.U0min, nmpc_leg.con.U0max) .≈ ([-5, -9.9], [100,99]))
1042+
setconstraint!(nmpc_leg, Δumin=[-5,-10], Δumax=[6,11])
1043+
@test all((nmpc_leg.con.ΔŨmin, nmpc_leg.con.ΔŨmax) .≈ ([-5,-10,0], [6,11,Inf]))
1044+
setconstraint!(nmpc_leg, ymin=[-6, -11],ymax=[55, 35])
1045+
@test all((nmpc_leg.con.Y0min, nmpc_leg.con.Y0max) .≈ ([-6,-11], [55,35]))
1046+
setconstraint!(nmpc_leg, x̂min=[-21,-22,-23,-24,-25,-26], x̂max=[21,22,23,24,25,26])
1047+
@test all((nmpc_leg.con.x̂0min, nmpc_leg.con.x̂0max) .≈
1048+
([-21,-22,-23,-24,-25,-26], [21,22,23,24,25,26]))
1049+
1050+
setconstraint!(nmpc_leg, c_umin=[0.01,0.02], c_umax=[0.03,0.04])
1051+
@test all((-nmpc_leg.con.A_Umin[:, end], -nmpc_leg.con.A_Umax[:, end]) .≈
1052+
([0.01,0.02], [0.03,0.04]))
1053+
setconstraint!(nmpc_leg, c_Δumin=[0.05,0.06], c_Δumax=[0.07,0.08])
1054+
@test all((-nmpc_leg.con.A_ΔŨmin[1:end-1, end], -nmpc_leg.con.A_ΔŨmax[1:end-1, end]) .≈
1055+
([0.05,0.06], [0.07,0.08]))
1056+
setconstraint!(nmpc_leg, c_ymin=[1.00,1.01], c_ymax=[1.02,1.03])
1057+
@test all((-nmpc_leg.con.A_Ymin, -nmpc_leg.con.A_Ymax) .≈ (zeros(0,3), zeros(0,3)))
1058+
@test all((nmpc_leg.con.C_ymin, nmpc_leg.con.C_ymax) .≈ ([1.00,1.01], [1.02,1.03]))
1059+
setconstraint!(nmpc_leg,
1060+
c_x̂min=[0.21,0.22,0.23,0.24,0.25,0.26],
1061+
c_x̂max=[0.31,0.32,0.33,0.34,0.35,0.36]
1062+
)
1063+
@test all((nmpc_leg.con.c_x̂min, nmpc_leg.con.c_x̂max) .≈
1064+
([0.21,0.22,0.23,0.24,0.25,0.26], [0.31,0.32,0.33,0.34,0.35,0.36]))
10361065

10371066
nmpc_ms = NonLinMPC(nonlinmodel, Hp=1, Hc=1, transcription=MultipleShooting())
10381067

@@ -1201,6 +1230,76 @@ end
12011230
@test all(isapprox.(info[:Ŷ], 3.14; atol=1e-1))
12021231
@test all(isapprox.(info[:gc][Hp+1:end], 0.0; atol=1e-1))
12031232

1233+
# TODO: delete these tests when the deprecated legacy splatting syntax will be.
1234+
1235+
nmpc_leg = NonLinMPC(nonlinmodel; Hp, Hc=5, gc, nc=2Hp, p=[0; 0], oracle=false)
1236+
JuMP.set_attribute(nmpc_leg.optim, "constr_viol_tol", 1e-3)
1237+
1238+
setconstraint!(nmpc_leg, x̂min=[-1e6,-Inf], x̂max=[+1e6,+Inf])
1239+
setconstraint!(nmpc_leg, umin=[-1e6], umax=[+1e6])
1240+
setconstraint!(nmpc_leg, Δumin=[-15], Δumax=[15])
1241+
setconstraint!(nmpc_leg, ymin=[-100], ymax=[100])
1242+
preparestate!(nmpc_leg, [0])
1243+
1244+
setconstraint!(nmpc_leg, umin=[-3], umax=[4])
1245+
moveinput!(nmpc_leg, [-100])
1246+
info = getinfo(nmpc_leg)
1247+
@test all(isapprox.(info[:U], -3; atol=1e-1))
1248+
moveinput!(nmpc_leg, [100])
1249+
info = getinfo(nmpc_leg)
1250+
@test all(isapprox.(info[:U], 4; atol=1e-1))
1251+
setconstraint!(nmpc_leg, umin=[-1e6], umax=[+1e6])
1252+
1253+
setconstraint!(nmpc_leg, Δumin=[-1.5], Δumax=[1.25])
1254+
moveinput!(nmpc_leg, [-100])
1255+
info = getinfo(nmpc_leg)
1256+
@test all(isapprox.(info[:ΔU], -1.5; atol=1e-1))
1257+
moveinput!(nmpc_leg, [100])
1258+
info = getinfo(nmpc_leg)
1259+
@test all(isapprox.(info[:ΔU], 1.25; atol=1e-1))
1260+
setconstraint!(nmpc_leg, Δumin=[-1e6], Δumax=[+1e6])
1261+
1262+
setconstraint!(nmpc_leg, ymin=[-0.5], ymax=[0.9])
1263+
moveinput!(nmpc_leg, [-100])
1264+
info = getinfo(nmpc_leg)
1265+
@test all(isapprox.(info[:Ŷ], -0.5; atol=1e-1))
1266+
moveinput!(nmpc_leg, [100])
1267+
info = getinfo(nmpc_leg)
1268+
@test all(isapprox.(info[:Ŷ], 0.9; atol=1e-1))
1269+
setconstraint!(nmpc_leg, ymin=[-100], ymax=[100])
1270+
1271+
setconstraint!(nmpc_leg, Ymin=[-0.5; fill(-100, Hp-1)], Ymax=[0.9; fill(+100, Hp-1)])
1272+
moveinput!(nmpc_leg, [-200])
1273+
info = getinfo(nmpc_leg)
1274+
@test info[:Ŷ][end] -100 atol=1e-1
1275+
@test info[:Ŷ][begin] -0.5 atol=1e-1
1276+
moveinput!(nmpc_leg, [200])
1277+
info = getinfo(nmpc_leg)
1278+
@test info[:Ŷ][end] 100 atol=1e-1
1279+
@test info[:Ŷ][begin] 0.9 atol=1e-1
1280+
setconstraint!(nmpc_leg, ymin=[-100], ymax=[100])
1281+
1282+
setconstraint!(nmpc_leg, x̂min=[-1e-6,-Inf], x̂max=[+1e-6,+Inf])
1283+
moveinput!(nmpc_leg, [-10])
1284+
info = getinfo(nmpc_leg)
1285+
@test info[:x̂end][1] 0 atol=1e-1
1286+
moveinput!(nmpc_leg, [10])
1287+
info = getinfo(nmpc_leg)
1288+
@test info[:x̂end][1] 0 atol=1e-1
1289+
setconstraint!(nmpc_leg, x̂min=[-1e6,-Inf], x̂max=[1e6,+Inf])
1290+
1291+
nmpc_leg.p .= [1; 0]
1292+
moveinput!(nmpc_leg, [100])
1293+
info = getinfo(nmpc_leg)
1294+
@test all(isapprox.(info[:U], 4.2; atol=1e-1))
1295+
@test all(isapprox.(info[:gc][1:Hp], 0.0; atol=1e-1))
1296+
1297+
nmpc_leg.p .= [0; 1]
1298+
moveinput!(nmpc_leg, [100])
1299+
info = getinfo(nmpc_leg)
1300+
@test all(isapprox.(info[:Ŷ], 3.14; atol=1e-1))
1301+
@test all(isapprox.(info[:gc][Hp+1:end], 0.0; atol=1e-1))
1302+
12041303
nmpc_ms = NonLinMPC(
12051304
nonlinmodel; Hp, Hc=5, transcription=MultipleShooting(), gc, nc=2Hp, p=[0; 0]
12061305
)

0 commit comments

Comments
 (0)