LpSolveDotNet
LpSolveDotNet copied to clipboard
Allows the usage in .NET of the Mixed Integer Linear Programming (MILP) solver lp_solve.
LpSolveDotNet
LpSolveDotNet is a .NET wrapper for the Mixed Integer Linear Programming (MILP) solver lp_solve. The solver lp_solve solves pure linear, (mixed) integer/binary, semi-cont and special ordered sets (SOS) models.
The wrapper works with these .NET implementations:
- .NET Framework versions 2.0 and up
- .NET Core 3.0 and up
- .NET Standard 1.5 and up See other platforms usage below
on these platforms:
| OS | Architecture | Package to reference | Notes |
|---|---|---|---|
| Windows | x64 | LpSolveDotNet.Native.win-x64 | |
| Windows | x86 (or 32 bit on x64) | LpSolveDotNet.Native.win-x86 | |
| Linux | x64 | LpSolveDotNet.Native.linux-x64 | |
| Linux | x86 | LpSolveDotNet.Native.linux-x86 | |
| OSX | x86 | LpSolveDotNet.Native.osx-x86 | Not tested |
| Others | Others | LpSolveDotNet | See other platforms usage below |
Standard Usage
To use LpSolveDotNet with one of the supported platforms listed above, follow these steps:
- Find the package name for your target platform(s) in the table above and add it (them) to your project. The
LpSolveDotNet.Native.???packages, which reference theLpSolveDotNetpackage, will not only add the .NET wrapper of thelp_solvelibrary, it will also take care of copying the native library to your build output. - In your project, add a call to the
LpSolveDotNet.LpSolve.Init()method. This will ensure that the right native library is called. If you are - Use one of the factory methods on
LpSolveclass to create anLpSolveinstance:- make_lp
- read_LP
- read_MPS
- read_XLI
- Place the returned
LpSolveinstance into ausingstatement so it is properly disposed of when done with it. - Use methods on that instance. The methods are like the official lpsolve documentation except the first parameter which is passed implicitly by this instance.
In a future version, the API will look more like .NET than C. Don't worry the old syntax will stay there.
Other Platforms Usage
If you need to target a platform not listed above, you need to do extra steps to use LpSolveDotNet.
Other .NET Targets
If your application resolves to use LpSolveDotNet's .NET Stantards targets (with an app targeting .NET Core earlier than 3.0, Xamarin...), the library will not pick up the native library by itself. The different ways to fix this are (pick one):
- Using property
LpSolve.CustomLoadNativeLibrary- Create a method that takes in a file path and enables your .NET implementation to load it
- Assign this method to the property
LpSolve.CustomLoadNativeLibrary - Call method
LpSolve.Init()
- Placing the native library in a folder in the paths searched by the .NET implementation. This could also be what your method
LpSolve.CustomLoadNativeLibraryis doing.
Other OS / Architectures
If your application runs on an OS / Architecture not listed above, you need to do the following:
- Build lp_solve for your OS / Architecture combination.
- Deploy the built native library along your application
- (optional) Depending on your .NET version, you may need to look at previous section
- If you did not put the native library in a folder in the paths searched by the .NET implementation, call
LpSolve.Init()and tweak the arguments to match your case
Examples
You can see examples in the Demo project translated from lpsolve's original C# samples.
- Formulation of an lp model in lpsolve
- demo inside lp_solve_5.5.2.3_cs.net.zip
Releases
You can see the release history.