[...] a carefully designed application-program interface for Internet optimization services would do much to encourage development of client applications- Fourer, Goux

Optimization.Framework 0.2 released

by Lars on April 7, 2011

We just released our Optimization.Framework, which lets you formulate mathematical models in C# and use a number (in the current release we have interfaces to Gurobi and Cplex) of solvers to solve them.
In the next weeks we will post a few “Howto” screencasts in which we will demonstrate how we think our framework is used best and explain the main features we think are important to know.
Until then you can play around with the latest bits yourself. I will quickly show you how you can get the framework and what you need to be aware of in order to use it.

1. Prerequisites

In order to use a solver you will need to download the solver software and install it. Also you will need a license for the solver in order to use it. We assume that you have installed and configured the solvers you want to use.
In order to use Gurobi you will need the ‘Gurobi40.NET.dll’ and in order to use Cplex you will need the ‘ILOG.CPLEX.dll’ and the ‘ILOG.CONCERT.dll’. These libraries can be found in the installation directories of the corresponding products.

2. Downloading Optimization.Framework

Option 1) – Nuget Package Manager

Using NuGet Package Manager has one advantage over getting the framework via a simple zip-file download (which is option 2). Once you have the package manager installed it is very simple for you to always have the latest version of the framework because from within Visual Studio you will see when there is a new version available so that with one click you will always be up-to-date.
First you need to get the NuGet Package Manager if you do not have it installed already. And here is how you do that:
Click on Tools->Extension Manager

Click on ‘Online Gallery’ on the left

Click on ‘Search Online Gallery’ on the top right and type ‘nuget’

Download NuGet Package Manager and follow the installation procedure.

After the installation reboot Visual Studio.
Create a new project and right click on ‘References’ where you find a new item called ‘Add Library Package Reference’, which you click.

In this dialog click on ‘Online’ and in the same manner as before now search for ‘Optimization.Framework’

Install ‘Optimization.Framework’

NuGet now installs the assemblies you need and also adds the Documentation.chm as well as an XSD file which we will cover in a later screencast. For now you can ignore this file.

You can now go on and read section “Using the Optimization.Framework”.

Option 2) – Zip-File

As you are reading this post you are already on www.optimizationzen.com. On the right side you will find a link named ‘Optimization.Framework.zip’, which is the direct download link to the latest version of the framework. You can simply download this file and unzip it to your harddrive. When you reference the framework make sure to reference all included libraries except the ‘Optimization.Framework.Contracts.dll’.

You can now go on and read section “Using the Optimization.Framework”.

3. Using the Optimization.Framework

Now that you have a new project with the Optimization.Framework referenced you can start modelling. Try inserting the following code:

var model=new Model();
var x1=new Variable();
var x2=new Variable();

When you hover over the class 'Model' you should see a little helper tooltip that allows you to add the missing using-statement to the namespace 'Optimization'.
When you now try to build the solution you might be presented with an error message like the one in the screenshot below:

If you see this build error that is because you have targeted a different version of the .NET framework than '.NET 4.0', for example '.NET 4.0 Client profile'. To resolve this, simply change the targeted framework version in the project settings:

The project should now build without errors. Now try adding the following line:

var solver=new GurobiSolver();

and let Visual Studio add the using statement for the namespace 'Optimization.Solver.Gurobi'.
When you now run this, you will see an error message saying that the assembly 'Gurobi40.NET,...' could not be found. That is because you haven't referenced it yet in the project. Note that when you try to use Cplex as a solver (the class is 'CplexSolver') you will get the same error messages only for the assemblies 'ILOG.Concert' and 'ILOG.CPLEX'.

Simply go and add the reference to the missing assembly which can be found in the installation folder (more precisely in the bin directory) of Gurobi:

Since Gurobi every now and then releases a new version of their solver you might find that Visual Studio tells you that there is a conflict between different versions of the same dependent assembly. You can just double click this warning and let Visual Studio resolve this issue for you:

When you now run the project you might come accross three more issues. The first one is a 'DllNotFoundException', which simply tells you that the native gurobi40.dll could not be found, which is due to the fact that the path to this library is not in you environments path variable, so you should go and add it.

The second issue you might get is an 'BadImageFormatException', which tells you that the native 'gurobi40.dll' was compiled for a different platform than your project is targeting (x86 vs. x64). You can simply change your targeted platform to 'AnyCPU'. To do so, go to 'Build->Configuration Manager' and under 'Platform' choose 'AnyCPU' or if it doesn't show this option, create a new target platform which then should be 'AnyCPU'.

The third issue can occur when you don't have a license installed or it is not in the right place. Then you will get this error:

You should be able to solve this by copying your license file to the gurobi installation folder or setting the 'GUROBI_LICENSE' environment variable so that it points to the license file (not the directory, but the file itself!).

When you now run the project, you should see the Gurobi console output, like so:

As you see, installing the framework itself is fairly easy. When it comes to installing the solver it can get tricky. Therefore we are working on a solution that will make this process as smooth as installing a package so that you don't need to deal with any solver specific configuration tasks.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • FriendFeed
  • LinkedIn
  • Live
  • MisterWong
  • MySpace
  • Netvibes
  • PDF
  • Twitter

{ 2 comments… read them below or add one }

JUAN ESTEBAN CALLE SALAZAR January 28, 2013 at 3:17 pm

Hi Lars,

I would like to find more information about optimization.framework,

Where could I find?

How can I contact you?

JUAN ESTEBAN CALLE SALAZAR January 28, 2013 at 3:18 pm

Hi Lars,

I hope everything is great.

I wonder if we can talk a little bit more about Optimization.Framework.

Thanks in advance.

Leave a Comment

Previous post:

Next post: