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.
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.