[Ipopt] Question: Using IPOPT as an S-function in Simulink

Jonathan Currie jonathan.currie at aut.ac.nz
Tue May 29 21:34:20 EDT 2012

Hi Martijn,
In my experience C-MEX S-Functions can be difficult, and even more so with the need to generate real-time code. You might like to start with one of my other packages (jMPC Toolbox) which implements linear MPC using C-MEX S-Functions:
As with the OPTI Toolbox, all source is provided so you can see how to begin implementing an S Function (and even better, MPC). However you will need a C-MEX function which calls IPOPT. You can dynamically link IPOPT (build a DLL) to a MEX file, or statically link as I have done in OPTI. Compiling IPOPT from source (including all prerequisites) can be tricky on Windows so let me know if you want a static library build, I think I am allowed to distribute it. Just note the MATLAB interface to IPOPT (by Dr. Carbonetto) is reasonbly complex and this will be need to be reimplemented in a S Function (hope you are a good C++ programmer). Also make sure to use the warm-start functionality of IPOPT, something MPC can greatly benefit from.
Regarding the need to generate real time code, I'm not sure exactly how this will work with IPOPT. I doubt that will work with the xPC Target, however It should (although I have not tried) work with the Real Time Windows Target. You are probably best to ask a question in the Matlab User Forum regarding using 3rd party code within it's real time code execution environment.
I would be interested in your progress, so keep me posted on developments!
Jonathan Currie

From: ipopt-bounces at list.coin-or.org [mailto:ipopt-bounces at list.coin-or.org] On Behalf Of Martijn Disse
Sent: Wednesday, 30 May 2012 7:53 a.m.
To: ipopt at list.coin-or.org
Subject: [Ipopt] Question: Using IPOPT as an S-function in Simulink

Dear all,
For my thesis work I am using IPOPT as a solver for a Model Predictive Controller. IPOPT is open source and exist of a large collection of files written in C++. I installed the solver to be used with Matlab via the OPTI-Toolbox (http://www.i2c2.aut.ac.nz/Resources/Software/OptiToolbox.html) which come with a precompiled mex-file that acts as a function to call the solver. This works perfectly. However, since I need to use XPC-target or Windows Real Time Target, I need to implement the solver somehow in a Simulink block.
This is what I've tried so far:
*         Since I already have a mex-file I thought it would be convienent to use that inside a simple 'Matlab Function'-block. This works in Simulink, but the code generator cannot compile the Simulink diagram to a real-time executable code.
*         Creating an S-function in which I call the .mex function. This code cannot be compiled since the .tlc file is missing.
After some search on fora<http://www.mathworks.se/matlabcentral/answers/38962-call-a-mex-function-from-simulink> and Matlab central<http://www.mathworks.com/matlabcentral/answers/36879-calling-mex-function-from-within-simulink>, I found out that I should create a C MEX S-function and compile it. To make life easier, Simulink comes with an S-function builder in which libraries etc. can be added. I failed in constructing one and it is driving me crazy. My question to you therefor  is:
Who has experience in compiling IPOPT (or any other set of C++ files) to act as an S-function in Simulink and is willing to point me in the right direction?
Your help will be greatly appreciated!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/ipopt/attachments/20120530/2c6da9ac/attachment.html>

More information about the Ipopt mailing list