@@ -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= 2 Hp, 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= 2 Hp, p= [0 ; 0 ]
12061305 )
0 commit comments