Thursday, May 20, 2010

IPOPT revisited

Why complicate things? In a few recent posts I outlined a way to use IPOPT from C#. To begin with, I created a DLL using MinGW and MSYS (described here), and I then called this DLL from C# using P/Invoke (here and here).

However, there is no need to build your own DLL, the considerate IPOPT maintainers have already done this for us! Pre-compiled DLL libraries (and include files for C/C++ users) are found here.

The binaries of the most recent IPOPT version (3.8.1), have been compiled with Visual Studio 2008 (C/C++) and Intel Fortran 8, if I understand correctly. As a test, I have taken the release version of Ipopt38.dll from the 32-bit distribution instead of the csipopt.dll I recently built, and called it from my C# interface. The new DLL works just fine, only faster...

I have noticed two issues, which I am yet to investigate further:

1. When using the debug DLL, I get an exception regarding the callback delegates. When using the release library, I do not encounter this problem. As far as I have been able to tell, data is consistently maintained throughout the optimization when using the release version.

2. The output file from IPOPT is inaccessible to other C# code, even after I have completed the optimization. I have not yet been able to determine if this is purely a timing issue, or if I am not releasing resources correctly in my C# interface.

Finally, I want to direct a sincere thank you to Ramnadh, who commented upon my first post on this matter, asking whether I had managed to build a corresponding DLL in Visual Studio. This comment lead me to looking at the pre-compiled binaries, which in the end turned out to be so successful. Thanks, Ramnadh!

4 comments:

  1. Hi!

    I'm trying to use csipopt in my c# project.
    First I downloaded csipopt-src-0.8.zip and I created a new project in Visual Studio with your Program.cs and Ipopt.cs archives.
    Then I allow unsafe code in debug properties.
    Then I have tried to execute but it broke because didn't find the dll.
    Now, that's my problem, I try to put "Ipopt38.dll" but Visual Studios doesn't accept this dll, it says "A reference to 'C:\...\Ipopt38.dll' could not be added. Please make sure that the file is accessible, and that it is valid assembly or COM component".
    I'm working with Visual Studio 2005 Team Suite.
    Any suggestions to make it work?¿

    Thk

    ReplyDelete
  2. Dear Muro,

    As Visual Studio correctly reports, the Ipopt38.dll is neither a .NET assembly, nor a COM component, and therefore it cannot be added to the .NET project in Visual Studio.

    Instead, the Ipopt38.dll should preferably be placed in the same directory as the csipopt executable (or in the system path). I normally solve this by adding a post-build step in my VS project where I copy the Ipopt38.dll to the executable directory.

    By the way, are you actually using the 3.8 Ipopt DLL? The 3.9 DLL provides additional functionality, in particular the ability to intermediately report optimization progress. If you want to use the 3.8 DLL, please make sure to edit the IpoptDllName string in the Ipopt C# class.

    Good luck and best regards,
    Anders

    ReplyDelete
  3. Hello,

    I use MSVS 2010 Ultimate and am running into the same issue. I cannot add the dll and VS can't find it during runtime although the dll file is in the same directory as the csIpopt executable.

    ReplyDelete
  4. Hi everyone,
    I'm currently trying to solve a NLP by using JOM which uses IPOPT38.dll, and I need some help or an example of program that is runing.
    Thanks.

    ReplyDelete