[Ipopt] Optimal control problem (discretize and c++ inerface)

Joel Andersson j.a.e.andersson at gmail.com
Wed Sep 14 13:08:16 EDT 2016


Hi Pablo!

Since you're interested in optimal control, you might want to have a look
at our tool CasADi (http://casadi.org), which is an optimization modeling
environment with focus on optimal control.

Here is an example that shows how to do more or less exactly what you're
describing:

https://github.com/casadi/casadi/blob/master/docs/examples/cplusplus/rocket_mx_and_sx.cpp

That is an Euler method discretization for time and then solved with IPOPT
via the CasADi interface (which takes care of all derivative calculations).

There are other more efficient ways of solving this problem, however.
Especially if you're using IPOPT, it's better to use a "simultaneous
approach" and include the entire state trajectory as decision variables
instead of the "sequential approach" in the linked example. You should also
consider replacing your Euler scheme with something of higher order - that
will allow you to get the same accuracy with a more crude time
discretization. I would recommend a collocation type integrator scheme (a
type of implicit Runge-Kutta methods popular in optimal control) or if
you're system is non-stiff, you can also consider the the classical
(explicit) Runge-Kutta 4 scheme. Biegler's "Nonlinear Programming:
Concepts, Algorithms, and Applications to Chemical Processes" is an
excellent reference: http://epubs.siam.org/doi/book/10.1137/1.9780898719383.
You'll find implementations of these methods in CasADi.

Also note that you don't necessarily need to do the modeling in C++ even if
you're planning to do solve it online in an environment that only has C++.
If you're using AMPL, you can can use the AMPL executable to simply to
parse the problem and generate a ".nl" file. This file would then be read
by the open-source AMPL Solver Library, which is pure C and easy to embed.
If you're using CasADi as a modeling environment, you can do the modeling
in Python or MATLAB and have CasADi generate C code for the function calls,
including first and second order derivative information. It can then be run
on an embedded system in a minimalistic CasADi-IPOPT environment.

Best regards,
Joel


2016-09-14 8:35 GMT-05:00 Pablo Perez <pabloperez555 at hotmail.com>:

> Dear all,
>
> after having discovered Ipopt last month, I have thought using it in my
> academic research for optimizing the power use of a dynamic of a point mass
> train.
>
> Due to the optimal control nature of the problem, I understand that the
> problem must be discretized (by an Euler method, pe). The problem has the
> next structure:
>
> min J(x, u) = Integral[0, T](f(x, u)·dt);
> dx/dt = y(x, u);
> g(x, u) >= K;
> x_min <= x <= x_max;
> u_min <= u <= u_max;
> x(0) = x0;
>
> I have test and understand the examples provided with Ipopt and other
> users, but all of them are about continuos time problems. The only discrete
> systems problems I have found are used throught AMPL interface mostly, but
> I would like using Ipopt throught the C++ interface because it should be
> embeded within a standalone application.
>
> Please, does anyone knows of some link where there aer an example of how
> to use Ipopt with a discretized system using c++ interface? Might anybody
> provide me with any source code example?
>
> Best regards,
> Pablo
>
> _______________________________________________
> Ipopt mailing list
> Ipopt at list.coin-or.org
> https://urldefense.proofpoint.com/v2/url?u=http-3A__list.
> coin-2Dor.org_mailman_listinfo_ipopt&d=CwICAg&c=Ngd-
> ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=OtjwlDFa50ew9RXNsKUjcDYXBipGc0
> uQDVH_0daPLFk&m=EVZY3slpC56CA2pzk9y1rGYqC9FTWeGeR0vY6pONZAA&s=
> 19a6i0ofgIF1oDAvpq3MaUg30PUmRSLFdgJjL7B-kEw&e=
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/ipopt/attachments/20160914/75017fed/attachment.html>


More information about the Ipopt mailing list