![]() |
VOOZH | about |
Requires NuGet 2.5 or higher.
dotnet add package LpSolveDotNet --version 4.1.2
NuGet\Install-Package LpSolveDotNet -Version 4.1.2
<PackageReference Include="LpSolveDotNet" Version="4.1.2" />
<PackageVersion Include="LpSolveDotNet" Version="4.1.2" />Directory.Packages.props
<PackageReference Include="LpSolveDotNet" />Project file
paket add LpSolveDotNet --version 4.1.2
#r "nuget: LpSolveDotNet, 4.1.2"
#:package LpSolveDotNet@4.1.2
#addin nuget:?package=LpSolveDotNet&version=4.1.2Install as a Cake Addin
#tool nuget:?package=LpSolveDotNet&version=4.1.2Install as a Cake Tool
LpSolveDotNet is a .NET wrapper for the Mixed Integer Linear Programming (MILP) solver lp_solve which is itself written in C.
LpSolveDotNet works on a wide variety of .NET implementations and platforms:
| Supported | |
|---|---|
| .NET | Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10, future |
| .NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1, future |
| .NET Standard | 1.5, 1.6, 2.0, 2.1 |
| OS / Architecture | Windows x86 and x64, Unix x86 and x64, OSX x86 and others (for others you need to build lp_solve yourself) |
IMPORTANT: For osx-x86, the native package will not be provided starting with LpSolveDotNet 5.0 and you will need to fallback to the Other Platforms procedure instead of using the native package.
Here is the short version, see long version below for more details.
In your project file, add platform-specific package for your platform to your project:
<PackageReference Include="LpSolveDotNet.Native.win-x64" Version="4.x.x"/>
In your code (error-handling ommitted for brevity):
// Call once per process, before any other usage of LpSolve
LpSolve.Init();
// We build a model with 3 constraints and 2 variables
const int Ncol = 2;
using var lp = LpSolve.make_lp(3, Ncol);
// NOTE: set_obj_fnex/add_constraintex should be preferred on set_obj_fn/add_constraint
// as they can specify only non-zero elements when working with big model.
// The methods without _ex_ suffix will ignore the first array element so
// let's use a constant for this for clarity.
const double Ignored = 0;
// set the objective function: maximize (143 x + 60 y)
lp.set_maxim();
lp.set_obj_fn(new double[] { Ignored, 143, 60 });
// add constraints to the model
// 120 x + 210 y <= 15000
// 110 x + 30 y <= 4000
// x + y <= 75
lp.set_add_rowmode(true);
lp.add_constraint( new double[] { Ignored, 120, 210 }, lpsolve_constr_types.LE, 15000);
lp.add_constraint( new double[] { Ignored, 110, 30 }, lpsolve_constr_types.LE, 4000);
lp.add_constraint( new double[] { Ignored, 1, 1 }, lpsolve_constr_types.LE, 75);
lp.set_add_rowmode(false);
// We only want to see important messages on screen while solving
lp.set_verbose(lpsolve_verbosity.IMPORTANT);
// Now let lp_solve calculate a solution
lpsolve_return s = lp.solve();
if (s == lpsolve_return.OPTIMAL)
{
Console.WriteLine("Objective value: " + lp.get_objective());
var results = new double[Ncol];
lp.get_variables(results);
for (int j = 0; j < Ncol; j++)
{
Console.WriteLine(lp.get_col_name(j + 1) + ": " + results[j]);
}
}
Before LpSolveDotNet can be used, it needs to be initialized properly so it loads the native library of lp_solve for your platform.
Find the package name for your target platform(s) in the table below and add it (them) to your project. The LpSolveDotNet.Native.??? packages, which reference the LpSolveDotNet package, will not only add the .NET wrapper of the lp_solve library, it will also take care of copying the native library to your build output.
| 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 | This is likely the last version of this osx-x86 package. More recent versions of the lp_solve libraries were not built in that platform so we cannot bundle it anymore. You can still use a more recent version of LpSolveDotNet on that platform by following Other OS / Architectures below |
| Others | Others | LpSolveDotNet | See Other OS / Architectures below |
If your application runs on an OS / Architecture that is not listed above, you need to do the following:
LpSolveDotNet.LpSolve.Init() when you call it to match your case.If building 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):
LpSolveDotNet.LpSolve.CustomLoadNativeLibrary
LpSolveDotNet.LpSolve.CustomLoadNativeLibraryLpSolveDotNet.LpSolve.CustomLoadNativeLibrary is doing.LpSolveDotNet.LpSolve.Init() when you call it to match your case.To complete the initialization from previous steps, your code must call once the LpSolveDotNet.LpSolve.Init() method. This will ensure that the right native library is loaded and called.
LpSolve class to create an LpSolve instance:
LpSolve instance into a using statement so it is properly disposed of when done with it.lprec *lp which is passed implicitly instead.In a future version, the API will be more idiomatic to .NET instead of looking like C. Don't worry, we'll keep backwards compatibility so your existing code will continue to compile as-is.
You can see examples in the Demo project translated from lpsolve's original C# samples.
LpSolve is released as open source under the LGPL-2.1 license. Bug reports and contributions are welcome at the GitHub repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp1.0 netcoreapp1.0 was computed. netcoreapp1.1 netcoreapp1.1 was computed. netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 is compatible. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard1.5 netstandard1.5 is compatible. netstandard1.6 netstandard1.6 was computed. netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net20 net20 is compatible. net35 net35 was computed. net40 net40 was computed. net403 net403 was computed. net45 net45 was computed. net451 net451 was computed. net452 net452 was computed. net46 net46 was computed. net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 is compatible. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen30 tizen30 was computed. tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on LpSolveDotNet:
| Package | Downloads |
|---|---|
|
LpSolveDotNet.Native.win-x64
'LpSolveDotNet.Native.win-x64' and its dependency 'LpSolveDotNet' allow running the Mixed Integer Linear Programming (MILP) solver 'lp_solve' in .NET. That can solve pure linear, (mixed) integer/binary, semi-continuous and special ordered sets (SOS) models. This package specifically targets platform 'win-x64'. You can find other 'LpSolveDotNet.Native.*' packages to run on other platforms (you can target multiple platforms at the same time). Another option would be to bring your own native library and allow 'LpSolveDotNet' to find it at runtime. |
|
|
LpSolveDotNet.Native.linux-x64
'LpSolveDotNet.Native.linux-x64' and its dependency 'LpSolveDotNet' allow running the Mixed Integer Linear Programming (MILP) solver 'lp_solve' in .NET. That can solve pure linear, (mixed) integer/binary, semi-continuous and special ordered sets (SOS) models. This package specifically targets platform 'linux-x64'. You can find other 'LpSolveDotNet.Native.*' packages to run on other platforms (you can target multiple platforms at the same time). Another option would be to bring your own native library and allow 'LpSolveDotNet' to find it at runtime. |
|
|
LpSolveDotNet.Native.win-x86
'LpSolveDotNet.Native.win-x86' and its dependency 'LpSolveDotNet' allow running the Mixed Integer Linear Programming (MILP) solver 'lp_solve' in .NET. That can solve pure linear, (mixed) integer/binary, semi-continuous and special ordered sets (SOS) models. This package specifically targets platform 'win-x86'. You can find other 'LpSolveDotNet.Native.*' packages to run on other platforms (you can target multiple platforms at the same time). Another option would be to bring your own native library and allow 'LpSolveDotNet' to find it at runtime. |
|
|
LpSolveDotNet.Native.osx-x86
'LpSolveDotNet.Native.osx-x86' and its dependency 'LpSolveDotNet' allow running the Mixed Integer Linear Programming (MILP) solver 'lp_solve' in .NET. That can solve pure linear, (mixed) integer/binary, semi-continuous and special ordered sets (SOS) models. This package specifically targets platform 'osx-x86'. You can find other 'LpSolveDotNet.Native.*' packages to run on other platforms (you can target multiple platforms at the same time). Another option would be to bring your own native library and allow 'LpSolveDotNet' to find it at runtime. |
|
|
LpSolveDotNet.Native.linux-x86
'LpSolveDotNet.Native.linux-x86' and its dependency 'LpSolveDotNet' allow running the Mixed Integer Linear Programming (MILP) solver 'lp_solve' in .NET. That can solve pure linear, (mixed) integer/binary, semi-continuous and special ordered sets (SOS) models. This package specifically targets platform 'linux-x86'. You can find other 'LpSolveDotNet.Native.*' packages to run on other platforms (you can target multiple platforms at the same time). Another option would be to bring your own native library and allow 'LpSolveDotNet' to find it at runtime. |
This package is not used by any popular GitHub repositories.
Complete release notes can be found at https://github.com/MarcelGosselin/LpSolveDotNet/blob/main/docs/release-notes/index.md
This release contains:
- Issue #26: LpSolveDotNet.Native.* packages should not force unconditional copy of native binaries on every build.