osqp

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2025 License: MIT Imports: 3 Imported by: 0

README

osqp.go

Status GitHub Issues GitHub Pull Requests License


The goal of this project is to create a Go interface for OSQP implementation in C. The interface should be easy to use and should allow users to solve optimization problems using OSQP in golang..

📝 Table of Contents

🧐 Problem Statement

Currently, there is no Quadratic Programming implementation on golang. Users who want to use Quadratic Programming in golang have to write their own interface or create the new one for their specific use case. Without a Go interface build from OSQP implementation on C, users who want to use Quadratic Programming in Go will have to spend time and resources writing their own interface or using an create the new one for their specific use case. This can lead to suboptimal performance and increased development time.

  • IDEAL: The goal of this project is to create a Go interface for OSQP implementation in C. The interface should be easy to use and should allow users to solve optimization problems using OSQP in golang.
  • REALITY: Currently, there is no Go interface for OSQP implementation on C. Users who want to use OSQP in Go have to write their own interface or use an create the new one for their specific use case.
  • CONSEQUENCES: Without a Go interface for OSQP implementation on C, users who want to use OSQP in Go will have to spend time and resources writing their own interface or using an alternative such as linear programming for their specific use case. This can lead to suboptimal application.

💡 Idea / Solution

To achieve this goal, we will create a Go package that provides a simple and intuitive interface for OSQP implementation on C. The package will be designed to be easy to use and will provide users with all the functionality they need to solve optimization problems using OSQP in Go.

⛓️ Dependencies / Limitations

  • OSQP implementation on C

🚀 Future Scope

The long-term plan is to cover a lot of features available from osqp and build an easy way to use csc matrix and do some calculation utility.

🏁 Getting Started

These instructions will get you a copy of the project up and running on your local machine.

Prerequisites

  • OSQP Library
    You can find detailed instructions on building an osqp library and many tips about quadratic programming using osqp in its own documentation here.

Installing

To get started you need to compile the OSQP build in C or you can copy from libs directory in the example which not recommended because of the different between machine it's compile, so assuming you are using the same environment like me which is arch linux using wsl 2, you can try to copy them instead.

To install the library you can run the command below.

go get -u github.com/kevinburke/osqp.go

🎈 Usage

See examples/ for a variety of examples.

Simple:

package main
import (
	"fmt"
	"github.com/kevinburke/osqp.go"
)

func main() {
	newOSQP := osqp.NewOSQP()
	p_mat, err := osqp.NewCSCMatrix([][]float64{{4, 1}, {0, 2}})
	if err != nil {
		fmt.Println(err)
		return
	}
	a_mat, err := osqp.NewCSCMatrix([][]float64{{1, 1}, {1, 0}, {0, 1}})
	if err != nil {
		fmt.Println(err)
		return
	}
	q := []float64{1.0, 1.0}
	l := []float64{1.0, 0.0, 0.0}
	u := []float64{1.0, 0.7, 0.7}
	newOSQP.Setup(p_mat, q, a_mat, l, u)
	newOSQP.Solve()
	fmt.Println(newOSQP.Solution())
	newOSQP.CleanUp()
}

⛏️ Built With

  • OSQP - OSQP Library in C

✍️ Authors

See also the list of contributors who participated in this project.

🎉 Acknowledgments

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockDiag

func BlockDiag(blocks []*mat.Dense) *mat.Dense

func DenseEye

func DenseEye(size int, val float64) *mat.Dense

func DenseEyeK

func DenseEyeK(size int, val float64, k int) *mat.Dense

func ToNegative

func ToNegative(matDense mat.Matrix) mat.Matrix

func ToNegativeDense

func ToNegativeDense(vecDense mat.Dense) *mat.Dense

func ToNegativeVecDense

func ToNegativeVecDense(vecDense mat.VecDense) *mat.Dense

func VStack

func VStack(matrix []mat.Matrix) *mat.Dense

func VecZeros

func VecZeros(num int) mat.Matrix

Types

type Data

type Data struct {
	M     int64
	N     int64
	P_mat SparseMatrix
	Q     []float64
	A_mat SparseMatrix
	L     []float64
	U     []float64
}

type OSQPConfig

type OSQPConfig struct {
	// contains filtered or unexported fields
}

func NewOSQP

func NewOSQP() *OSQPConfig

func (OSQPConfig) CleanUp

func (o OSQPConfig) CleanUp()

func (OSQPConfig) PrimalObj added in v0.0.3

func (o OSQPConfig) PrimalObj() float64

func (OSQPConfig) Setup

func (o OSQPConfig) Setup(p SparseMatrix, q []float64, a SparseMatrix, l []float64, u []float64)

func (OSQPConfig) Solution

func (o OSQPConfig) Solution() (float32, float32)

func (OSQPConfig) SolutionSlice added in v0.0.3

func (o OSQPConfig) SolutionSlice() []float64

SolutionSlice returns the entire optimal weight vector as a []float64.

func (OSQPConfig) Solve

func (o OSQPConfig) Solve()

func (OSQPConfig) Status added in v0.0.3

func (o OSQPConfig) Status() string

func (OSQPConfig) UpdateAMat

func (o OSQPConfig) UpdateAMat(aNew []float64)

func (OSQPConfig) UpdateBounds

func (o OSQPConfig) UpdateBounds(lNew, uNew []float64)

func (OSQPConfig) UpdateLinCost

func (o OSQPConfig) UpdateLinCost(qNew []float64)

func (OSQPConfig) UpdatePMat

func (o OSQPConfig) UpdatePMat(pNew []float64)

type SparseMatrix

type SparseMatrix struct {
	// contains filtered or unexported fields
}

func NewCSCDenseMatrix

func NewCSCDenseMatrix(matrix mat.Matrix) (SparseMatrix, error)

func NewCSCMatrix

func NewCSCMatrix(matrix [][]float64) (SparseMatrix, error)

func NewDiagCSCMatrix

func NewDiagCSCMatrix(size int, value float64) (*SparseMatrix, error)

func (SparseMatrix) Data

func (s SparseMatrix) Data() []float64

func (SparseMatrix) Dimension

func (s SparseMatrix) Dimension() (int, int)

func (SparseMatrix) Ind

func (s SparseMatrix) Ind() []int

func (SparseMatrix) IndPtr

func (s SparseMatrix) IndPtr() []int

func (SparseMatrix) NNZ

func (s SparseMatrix) NNZ() int64

func (SparseMatrix) ToDense

func (s SparseMatrix) ToDense() *mat.Dense

func (SparseMatrix) Transpose

func (s SparseMatrix) Transpose(matrix [][]float64) [][]float64

Directories

Path Synopsis
examples
basic command
mpc command
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL