Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linear programming library for .NET / C# [closed]

I need to solve an under-determined linear system of equations and constraints, then find the particular solution that minimises a cost function. This needs to be done in purely portable managed code that will run in .NET and Mono. What freely available libraries are there that I can use to implement this?

All of the optimisation algorithms provided by free libraries I have found only support interval constraints on single variables, e.g. 0 < x < 1, not constraints like x + 2y < 4. I have also found that often the linear equations solvers only support linear systems with one solution.

The closest I have found so far is DotNumerics, which includes Singular Value Decomposition for solving under-determined linear systems, but its optimisation algorithms only support single-variable constraints (as far as I can tell).

There are several other questions asking about linear programming, but my key requirements are multi-variable constraints and solving under-determined systems. I have yet to find a free library that supports multi-variable constraints.

like image 621
Dylan Avatar asked May 09 '13 13:05

Dylan


2 Answers

If you are developing for .NET (i.e. not Windows Store, Windows Phone or Silverlight), then I would definitely recommend that you take a look at lpsolve, that is suitable for large LP and/or MILP problems. Download the x86 or x64 development archives that contain the respective lpsolve DLL:s, and then download the .NET API archive that contains a C# file with P/Invoke calls to all relevant functions in the lpsolve API.

Another alternative is to use the CLP solver from the COIN-OR projects, via the CoinMP precompiled binaries. There is a C# wrapper DLL available here.

If you do require purely managed code, ALGLIB is probably your best bet (as suggested by Marc Gravell above), but be aware that the ALGLIB open-source license uses GPL. If you want to use ALGLIB in your own code without disclosing it to the open-source community, you would need to purchase a commercial ALGLIB license.

A quick Internet search also reveals a pure C# implementation of the Simplex LP algorithm here. I cannot identify the author, and I have no idea whether this implementation is correct or of any quality. The code does seem highly portable though, even in terms of Windows Store, Windows Phone, Silverlight and Mono contexts.

like image 88
Anders Gustafsson Avatar answered Oct 26 '22 07:10

Anders Gustafsson


ALGLIB is the usual go-to library for things like linear solvers. I would give that a good look before despairing.

like image 43
Marc Gravell Avatar answered Oct 26 '22 08:10

Marc Gravell