osqp-net 1.0.0.1

dotnet add package osqp-net --version 1.0.0.1
                    
NuGet\Install-Package osqp-net -Version 1.0.0.1
                    
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="osqp-net" Version="1.0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="osqp-net" Version="1.0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="osqp-net" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add osqp-net --version 1.0.0.1
                    
#r "nuget: osqp-net, 1.0.0.1"
                    
#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.
#:package osqp-net@1.0.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=osqp-net&version=1.0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=osqp-net&version=1.0.0.1
                    
Install as a Cake Tool

OsqpNet

.NET NuGet

A modern .NET interface for the OSQP (Operator Splitting Quadratic Program) solver. This library provides both a high-level modelling API and a low-level native wrapper using source-generated PInvoke.

Installation

Install the package via NuGet:

dotnet add package osqp-net

The package includes native binaries for:

  • Windows (x64)
  • Linux (x64)

Features

  • Modelling API: Build optimization problems naturally using C# variables, expressions, and operators.
  • Efficient In-place Updates: Uses new .NET 10 void operator overloads (+=, -=, *=) for zero-allocation expression building.
  • Incremental Solving: Automatically detects when data can be updated in-place in the OSQP solver without re-initialization.
  • High-level Wrapper: Clean, disposable OsqpSolver and CscMatrix classes.
  • Native Performance: Uses .NET 10 LibraryImport for efficient C API calls.
  • Type Safety: Strongly typed enums and structs reflecting the OSQP C API.

Quick Start (Modelling API)

The modelling API allows you to define variables and constraints naturally:

using OsqpNet.Modelling;
using OsqpNet.Native;

// Create a model
var model = new Model();

// Add variables
var x = model.AddVariable();
var y = model.AddVariable();

// Set objective: minimize 2*x^2 + y^2 + x*y + x + y
// You can build expressions incrementally
var obj = 2 * x * x + y * y;
obj += x * y; // Efficient in-place update (.NET 10)
obj += x + y;
model.SetObjective(obj);

// Add constraints
model.AddConstraint(x + y == 1);
model.AddConstraint(x >= 0);
model.AddConstraint(y >= 0);

// Solve
var result = model.Solve();

if (result.Status == OsqpStatus.Solved)
{
    Console.WriteLine($"x: {result.Solution[x]}");
    Console.WriteLine($"Objective: {result.ObjectiveValue}");
}

// Incremental Solve: update bounds without recreating the solver
// This is extremely efficient for repeated solves
model.AddConstraint(x <= 0.5); 
var result2 = model.Solve();

Low-level API

If you already have your data in CSC (Compressed Sparse Column) format, you can use the OsqpSolver class directly:

using OsqpNet;
using OsqpNet.Native;

// Define P, q, A, l, u in CSC format
using var P = new CscMatrix(2, 2, new double[] { 4, 1, 2 }, new long[] { 0, 0, 1 }, new long[] { 0, 1, 3 });
var q = new double[] { 1, 1 };
using var A = new CscMatrix(3, 2, new double[] { 1, 1, 1, 1 }, new long[] { 0, 1, 0, 2 }, new long[] { 0, 2, 4 });
var l = new double[] { 1, 0, 0 };
var u = new double[] { 1, 0.7, 0.7 };

using var solver = new OsqpSolver(P, q, A, l, u);
var status = solver.Solve();
var solution = solver.GetPrimalSolution();

References

License

This project is licensed under the same terms as OSQP (Apache 2.0).

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

    • No dependencies.

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
1.0.0.1 25 1/21/2026