Skip to content

Commit d24318f

Browse files
authored
Merge pull request #284 from JuliaControl/bench_custom_con_hess
bench: add custom constraint tests with `hessian=true`
2 parents 0bc9ebf + 7a6923a commit d24318f

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

benchmark/3_bench_predictive_control.jl

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ nmpc_ipopt_tc = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription)
308308
nmpc_ipopt_tc = setconstraint!(nmpc_ipopt_tc; umin, umax)
309309
JuMP.unset_time_limit_sec(nmpc_ipopt_tc.optim)
310310

311+
optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false)
312+
transcription, hessian = TrapezoidalCollocation(), true
313+
nmpc_ipopt_tc_hess = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription, hessian)
314+
nmpc_ipopt_tc_hess = setconstraint!(nmpc_ipopt_tc_hess; umin, umax)
315+
JuMP.unset_time_limit_sec(nmpc_ipopt_tc_hess.optim)
316+
311317
optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false)
312318
transcription = TrapezoidalCollocation(f_threads=true)
313319
nmpc_ipopt_tct = NonLinMPC(estim; Hp, Hc, Mwt, Nwt, Cwt, optim, transcription)
@@ -371,6 +377,11 @@ CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["TrapezoidalCollocatio
371377
sim!($nmpc_ipopt_tc, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
372378
samples=samples, evals=evals, seconds=seconds
373379
)
380+
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["TrapezoidalCollocation (Hessian)"] =
381+
@benchmarkable(
382+
sim!($nmpc_ipopt_tc_hess, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
383+
samples=samples, evals=evals, seconds=seconds
384+
)
374385
CASE_MPC["Pendulum"]["NonLinMPC"]["Noneconomic"]["Ipopt"]["TrapezoidalCollocation (threaded)"] =
375386
@benchmarkable(
376387
sim!($nmpc_ipopt_tct, $N, $ry; plant=$plant, x_0=$x_0, x̂_0=$x̂_0, progress=false),
@@ -480,6 +491,14 @@ nmpc2_ipopt_ms = NonLinMPC(estim2;
480491
nmpc2_ipopt_ms = setconstraint!(nmpc2_ipopt_ms; umin, umax)
481492
JuMP.unset_time_limit_sec(nmpc2_ipopt_ms.optim)
482493

494+
optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false)
495+
transcription, hessian = MultipleShooting(), true
496+
nmpc2_ipopt_ms_hess = NonLinMPC(estim2;
497+
Hp, Hc, Nwt=Nwt, Mwt=[0.5, 0], Cwt, gc!, nc, p=Pmax, optim, transcription, hessian
498+
)
499+
nmpc2_ipopt_ms_hess = setconstraint!(nmpc2_ipopt_ms_hess; umin, umax)
500+
JuMP.unset_time_limit_sec(nmpc2_ipopt_ms_hess.optim)
501+
483502
optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false)
484503
transcription = TrapezoidalCollocation()
485504
nmpc2_ipopt_tc = NonLinMPC(estim2;
@@ -488,9 +507,13 @@ nmpc2_ipopt_tc = NonLinMPC(estim2;
488507
nmpc2_ipopt_tc = setconstraint!(nmpc2_ipopt_tc; umin, umax)
489508
JuMP.unset_time_limit_sec(nmpc2_ipopt_tc.optim)
490509

491-
# TODO: test custom constraints with MadNLP and SingleShooting, see comment above.
492-
# TODO: test custom constraints with MadNLP and MultipleShooting, see comment above.
493-
# TODO: test custom constraints with MadNLP and TrapezoidalCollocation, see comment above.
510+
optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false)
511+
transcription, hessian = TrapezoidalCollocation(), true
512+
nmpc2_ipopt_tc_hess = NonLinMPC(estim2;
513+
Hp, Hc, Nwt=Nwt, Mwt=[0.5, 0], Cwt, gc!, nc, p=Pmax, optim, transcription, hessian
514+
)
515+
nmpc2_ipopt_tc = setconstraint!(nmpc2_ipopt_tc_hess; umin, umax)
516+
JuMP.unset_time_limit_sec(nmpc2_ipopt_tc_hess.optim)
494517

495518
samples, evals, seconds = 100, 1, 15*60
496519
CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["SingleShooting"] =
@@ -503,11 +526,21 @@ CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["MultipleShooti
503526
sim!($nmpc2_ipopt_ms, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
504527
samples=samples, evals=evals, seconds=seconds
505528
)
529+
CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["MultipleShooting (Hessian)"] =
530+
@benchmarkable(
531+
sim!($nmpc2_ipopt_ms_hess, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
532+
samples=samples, evals=evals, seconds=seconds
533+
)
506534
CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["TrapezoidalCollocation"] =
507535
@benchmarkable(
508536
sim!($nmpc2_ipopt_tc, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
509537
samples=samples, evals=evals, seconds=seconds
510538
)
539+
CASE_MPC["Pendulum"]["NonLinMPC"]["Custom constraints"]["Ipopt"]["TrapezoidalCollocation (Hessian)"] =
540+
@benchmarkable(
541+
sim!($nmpc2_ipopt_tc_hess, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
542+
samples=samples, evals=evals, seconds=seconds
543+
)
511544

512545
# ----------------- Case study: Pendulum successive linearization -------------------------
513546
linmodel = linearize(model, x=[0, 0], u=[0])

0 commit comments

Comments
 (0)