[Ipopt] Redirecting the IPOPT output to mexPrintf

Joel Andersson j.a.e.andersson at gmail.com
Thu Jun 25 14:26:57 EDT 2015

Hi Stefan,

That worked - thanks a lot! In the end I used the StreamJournal class as

ipopt = new Ipopt::IpoptApplication(false);
SmartPtr<StreamJournal> jrnl = new StreamJournal("console", J_ITERSUMMARY);
jrnl->SetPrintLevel(J_DBG, J_NONE);

where casadi::csout is a CasADi abstraction to std::cout.

I hope that's legit usage.

Best regards,

2015-06-25 13:04 GMT+02:00 Stefan Vigerske <stefan at math.hu-berlin.de>:

> Hi,
> you can pass your own output handler (called a Journal) to Ipopt and
> disable the default Journal.
> So, for example
> ipopt = new IpoptApplication(false);
> SmartPtr<Journal> jrnl = new MyJournal();
> jrnl->SetPrintLevel(J_DBG, J_NONE);
> ipopt->Jnlst()->AddJournal(jrnl);
> And the MyJournal should be derived from the Ipopt::Journal class. In
> there, you can redirect to mexPrintf.
> Hope that helps,
> Stefan
> On 06/25/2015 11:39 AM, Joel Andersson wrote:
>> Hi,
>> I'm working on completing the addition of a MATLAB interface to CasADi,
>> but
>> I'm struggling finding a way to send the text output from IPOPT to
>> mexPrintf. Is it possible to somehow set a user-defined function for
>> printing log messages? Or, alternatively, to have IPOPT write output to
>> C++'s iostream (i.e. std::cout and std::cerr) instead of C's printf (i.e.
>> stdout and stderr)? The former is much easier to redirect to a custom
>> function.
>> In general, since Ipopt is a C++ code, I would expect iostream to be used
>> for printing, but I guess it uses printf because of the linear solvers
>> underneath.
>> If anyone is interested, you can find an example of how to solve an NLP
>> using IPOPT with CasADi-MATLAB here:
>> https://github.com/casadi/casadi/blob/develop/test/matlab/rosenbrock.m.
>> This is complete with efficient calculation of sparse Hessians and
>> Jacobians but unless you start MATLAB from the command line without the
>> GUI, you'll lose the IPOPT text output due to the above issue. I'll get
>> back to this mailing list as soon as we make a stable release.
>> Best regards,
>> Joel
>> _______________________________________________
>> Ipopt mailing list
>> Ipopt at list.coin-or.org
>> http://list.coin-or.org/mailman/listinfo/ipopt

Joel Andersson, PhD
Ptge. Busquets 11-13, atico 3
E-08940 Cornella de Llobregat (Barcelona), Spain
Home: +34-93-6034011
Mobile: +34-63-4408800 (in Sweden also +46-707-360512)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/ipopt/attachments/20150625/bc2d58a0/attachment.html>

More information about the Ipopt mailing list