Anexia.MathematicalProgram 2.0.0

dotnet add package Anexia.MathematicalProgram --version 2.0.0                
NuGet\Install-Package Anexia.MathematicalProgram -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Anexia.MathematicalProgram" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Anexia.MathematicalProgram --version 2.0.0                
#r "nuget: Anexia.MathematicalProgram, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Anexia.MathematicalProgram as a Cake Addin
#addin nuget:?package=Anexia.MathematicalProgram&version=2.0.0

// Install Anexia.MathematicalProgram as a Cake Tool
#tool nuget:?package=Anexia.MathematicalProgram&version=2.0.0                

dotnet-mathematical-program

alternate text is missing from this package README image alternate text is missing from this package README image codecov.io This library allows you to build and solve linear programs and integer linear programs in a very handy way. For linear programs, either SCIP or Google's GLOP solver can be used. For integer linear programs, SCIP, Gurobi and the Coin-OR CBC branch and cut solver can be chosen. When the desired solver is not available, i.e., no licence for Gurobi could be found, SCIP is used as fallback. CBC Solver is marked deprecated, SCIP should be used instead.

Installation

  • Install the latest version of Anexia.MathematicalProgram package via nuget

Description

This library works for any linear program (LP), integer linear program (ILP) or constraint program (CP).

Anexia.MathematicalProgram.Result

After solving the LP/ILP you get a SolverResult according to the Google.OrTools.LinearSolver.Solver.ResultStatus. The SolverResult containts following information:

  • SolutionValues: You can read out the actual values of the variables to transform the result correctly.
  • ObjectiveValue: Actual objective value. This value can be either the optimum, a deviation of the optimum if the LP/ILP was not entirely solved, or null if the LP/ILP is infeasible.
  • IsFeasible: Information whether the LP/ILP is generally feasible.
  • IsOptimal: Information whether the LP/ILP was solved to optimality.
  • OptimalityGap: The deviation to the optimum calculated by Math.Abs(bestObjectiveBound - objectiveValue) / objectiveValue). If the objective value and the best bound are zero, the gap is also set to zero. If the objective value is zero but the best bound is not, the gap is defined to be +/- infinity.

Examples for using this library

Example (Build and solve ILP)

  • Feasible model: min 2x + y, s.t. x >= y, integer variables x in [1,3], y binary
  • Result: x = 1, objective value = 2
var model = new OptimizationModel<IIntegerVariable<IRealScalar>, RealScalar, IRealScalar>();

var x = model.NewVariable<IntegerVariable<IRealScalar>>(new IntegralInterval(1, 3), "x");

var y = model.NewVariable<IntegerVariable<IRealScalar>>(new IntegralInterval(0, 1), "y");

var constraint = model.ConstraintBuilder()
                      .AddWeightedSum([x, y], [1, -1])
                      .Build(new RealInterval(0, double.PositiveInfinity));

model.AddConstraint(constraint);

var objFunction = model.TermsBuilder()
                       .AddTerm(2, x)
                       .AddTerm(2, y).Build()
                       .ToObjectiveFunction(false);
var optimizationModel = model.SetObjective(objFunction);

var result = SolverFactory.SolverFor(IlpSolverType.Scip).Solve(optimizationModel,
            new SolverParameter(new EnableSolverOutput(true)),
            out _);

Further detailed examples can be found in the examples folder.

Contributing

Contributions are welcomed! Read the Contributing Guide for more information.

Licensing

This project is licensed under MIT License. See LICENSE for more information.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 67 2/26/2025
1.0.3 152 1/22/2025
1.0.2 100 12/5/2024
1.0.1 91 12/5/2024
1.0.0 95 12/5/2024