How to speedup solving NLP?

1,338 views
Skip to first unread message

Changjie GUAN

unread,
Aug 31, 2018, 4:02:35 AM8/31/18
to CasADi
Hi all,

I'd like to use CasAdi to solve a NMPC problem in real time and I have read the user's guide.

To start with, I first tried the example of direct_single_shooting. It took 0.728s to run the single command following:

tic
sol
= solver('x0', w0, 'lbx', lbw, 'ubx', ubw, ...
             
'lbg', lbg, 'ubg', ubg);
toc

This is really slow because my goal is ~10ms per run.

Below is the details of running:

Number of objective function evaluations             = 44
Number of objective gradient evaluations             = 24
Number of equality constraint evaluations            = 0
Number of inequality constraint evaluations          = 44
Number of equality constraint Jacobian evaluations   = 0
Number of inequality constraint Jacobian evaluations = 39
Number of Lagrangian Hessian evaluations             = 37
Total CPU secs in IPOPT (w/o function evaluations)   =      0.363
Total CPU secs in NLP function evaluations           =      0.095

I tried to generate code for the solver but IpoptInterface cannot be code generated.
Is there any examples showing how to generate code to speedup NLP solvers? Any suggestions?

Thanks!

Bruno Martins Lima

unread,
Aug 31, 2018, 2:17:20 PM8/31/18
to CasADi
Hi!

I have some experience with CasADi for NMPC and I hope I can help.

First of all, single shooting is not recommended for optimal control since it does not have a good numerical stability. For instance, the last state of the horizon will depend on all past inputs which is highly nonlinear. Try multiple shooting instead.

Another important aspect is warm starting. Every sampling time, use the result from the last Ts as an initial solution of the solver.

How to evaluate the model is also important. When defining the 'integrator', try the 'expand' option to transform the MX function to SX. It is also possible to use this option in the nlpsol.

Currently, it is not possible to generate code for IPOPT. One option is to use the 'jit' (just-in-time) option which generates and compiles C code to evaluate the objective, constraints and their derivatives.

I believe that the CasADi team is designing an NLP solver which allows code generation. I don't know if it is ready yet but I would keep an eye on that. Also, ACADOS is a project which will implement fast NMPC algorithms using CasADi but it is not ready yet.

Kind Regards,
Bruno
Reply all
Reply to author
Forward
0 new messages