Sonnet is a modelling API and wrapper for COIN-OR mixed integer linear programming classes for the Microsoft .NET on Windows platforms.
The Sonnet API allows for code like this:
using Sonnet; Model model = new Model(); Variable x = new Variable(); Variable y = new Variable(); model.Add(2 * x + 3 * y <= 10); var expr = new Expression(); // Useful in for-loops expr.Add(3.0, x); expr.Add(y); model.Objective = expr; // 3*x + y Solver solver = new Solver(model); solver.Maximise();
You can find the latest binaries and sources from CI builds on AppVeyor (if available).
In particular, the latest binary release: https://github.com/coin-or/Sonnet/releases
Simply add the x86 or x64 libraries of
SonnetWrapper.dll to your References in Visual Studio.
Requires .NET Framework 4.x or .NET 5.
Sonnet can only be used on Windows platforms. While, in principle, .NET 5 supports cross-platform use, this does not include the mixed C++/CLI of SonnetWrapper, where the native C++ of the COIN-OR C++ is mixed with C++/CLI.
Note: If you use the .NET 5 libraries, then also include
Ijwhost.dll in your project and set this file to Always Copy to Output folder to prevent runtime errors of
Building from source
Getting the source code
Option 1: Get the full src.zip artifact from AppVeyor
The easiest way to get started with Sonnet source code is to use the ..-src.zip artefact (if available) from the latest AppVeyor build artefacts. This zip contains the Sonnet sources as well as all the relevant COIN-OR dependencies from their master branch. Simply unzip to have all the sources in the right place. Unfortunately, AppVeyor only keeps the artefacts for one month after the build.
Option 2: Get sources from GitHub
The latest Sonnet sources can be downloaded from the github repository. If you use "Download ZIP", the downloaded zip file contains the Sonnet source code and MS Visual Studio 2019 solution.
Before you can build Sonnet, the sources of the master branches of all the relevant COIN-OR dependencies are also required. See https://github.com/coin-or/Cbc#source how to get the relevant sources.
The Sonnet solution expects the COIN-OR source code to be in the same root folder. The folder structure should look like this:
Building in Visual Studio
For Visual Studio 2019, the solution and project files can be found in
Simply open the Sonnet solution in
Sonnet\MSVisualStudio\v16\Sonnet.sln, and Build.
The Sonnet projects and solution are provided for Visual Studio 2019 (v16). The Sonnet solution for Visual Studio 2019 refers to the project files of the relevant COIN-OR libraries.
Solution configurations for Debug, Release and ReleaseParallel are defined for the solution, each with x86 and x64 solution platforms.
Older versions of Sonnet projects and solutions files are available for Visual Studio 2010 (v10), but these are not maintained.
Platform target (x64 or Win32/x86)
Separate builds are required for x86 or x64, in particular for
Since the C++/CLI of
SonnetWraper.dll has no "AnyCPU" equivalent, it is NOT possible to use
the x86 and/or x64
SonnetWrapper.dll in an "AnyCPU" project. The project has to target x86 or x64.
Strongly naming / Signing assemblies
To strongly name (sign) the
SonnetWrapper.dll there are two options:
- Build the source code using your own key, or
- Use ILMerge:
ilmerge Weak.dll /keyfile:key.snk /out:Strong.dll
Several parts of the source code have been disabled because they require, e.g., non-standard COIN-OR code.
SONNET_LEANLOADPROBLEM (Solver.cs, see also SonnetWrapper)
Especially for CLP, this functionality loads problems more efficiently but requires
non-standard osiClp code. This is really only interesting for large problems (>100K var/con).
SONNET_LEANLOADPROBLEM is defined, then two additional member functions of SonnetWrapper's OsiClpSolverInterface are defined:
and one extra member function must be added for normal OsiClpSolverInterface
Unfinished code for adding a variable type of
SemiContinuousVariable, and automatically generate
helper variable (binary) and constraint.
Whether or not to include row price information in WarmStart