Code Monkey home page Code Monkey logo

casadi.jl's Introduction

CasADi.jl

Introduction

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:

  1. This repo is unofficial, not maintained by the original CasADi authors, and not affiliated with the CasADi project.
  2. 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.
  3. I am more than happy to accept contributions and discuss potential changes that could improve this package.

How to install

This is not a registered package and there is no plan to register it soon.

There are several steps for installing this package.

  1. You first need to have PyCall.jl installed (which in turns requires Conda.jl).
  2. In the same environment that Conda.jl uses (thus PyCall.jl uses), install CasADi. Although this package can install CasADi itself using Conda.jl from conda-forge, I find that the conda-forge version of CasADi often causes problems within Conda / Python. Therefore I would suggest CasADi be installed manually using the official channel, in particular with pip install casadi. I find that this method is more reliable. Furthermore, I find that using the base environment in Conda instead of a dedicated virtual environment for Conda.jl works better. You may want to start Python and test CasADi to make sure that it works well.
  3. Finally, install this package directly from github by activating the package manager ] and running
add https://github.com/nxtruong/CasADi.jl.git

Example: Create NLP solver

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])

Example: Using Opti stack

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) )

casadi.jl's People

Contributors

ichatzinikolaidis avatar github-actions[bot] avatar nxtruong avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.