Status | Coverage |
---|---|
This package is an interface to CasADi, a powerful symbolic framework for automatic differentiation and optimal control. More information are available on the official website. Although Julia has excellent libraries for optimization, they have not reached the maturity of CasADi for nonlinear optimization and optimal control yet. This library aims to give easy access to its powerful capabilities.
Please note:
- This repo is unofficial, not maintained by the original CasADi authors, and not affiliated with the CasADi project.
- There is no plan to include interfaces to all of CasADi capabilities. It has grown out of my own research needs and I am sharing it in case other people find it useful. Since PyCall.jl is used, any aspect of CasADi not implemented in this interface can be easily accessed directly via PyCall.
- I am more than happy to accept contributions and discuss potential changes that could improve this package.
This is not a registered package and there is no plan to register it soon.
You can easily install it by activating the package manager ]
and running
add git@github.com:ichatzinikolaidis/CasADi.jl.git
We will use CasADi to find the minimum of the Rosenbrock function. This can be done as follows
using CasADi
x = SX("x")
y = SX("y")
α = 1
b = 100
f = (α - x)^2 + b*(y - x^2)^2
nlp = Dict("x" => vcat([x ; y]), "f" => f);
S = casadi.nlpsol("S", "ipopt", nlp);
sol = S(x0 = [0, 0]);
println("Optimal solution: x = ", sol["x"].toarray()[1], ", y = ", sol["x"].toarray()[2])
We will use Opti stack to solve the example problem in CasADi's documentation
using CasADi
opti = casadi.Opti();
x = opti._variable()
y = opti._variable()
opti.minimize( (y - x^2)^2 )
opti._subject_to(x^2 + y^2 == 1)
opti._subject_to(x + y >= 1)
opti.solver("ipopt");
sol = opti.solve();
println( "Optimal solution: x = ", sol.value(x), ", y = ", sol.value(y) )