GithubHelp home page GithubHelp logo

darnstrom / daqp Goto Github PK

View Code? Open in Web Editor NEW
53.0 6.0 10.0 364 KB

A dual active-set algorithm for convex quadratic programming

License: MIT License

CMake 2.43% C 64.76% MATLAB 25.32% Python 2.53% Cython 4.96%
quadratic-programming numerical-optimization model-predictive-control optimization control active-set-method

daqp's Introduction

DAQP

License: MIT CI

DAQP is a dual active-set solver that solves convex quadratic programs of the form

minimize        0.5 x' H x + f' x

subject to      l  <=  x  <= u
		bl <=  Ax <= bu.

Binary constraints of the form $A x \in \lbrace b_l, b_u \rbrace$ are also supported, allowing for mixed-integer quadratic programs to be solved.

The code is written in C and is library free. DAQP can be interfaced to C, Julia, MATLAB, and Python.

Quick installation

Julia

] add DAQP

MATLAB

websave('install_daqp','https://raw.githubusercontent.com/darnstrom/daqp/master/interfaces/daqp-matlab/install_daqp.m')
install_daqp

Python

pip install daqp

Details

See the Documentation for more detailed installation instructions and basic use of the interfaces.

Citing DAQP

@article{arnstrom2022dual,
  author={Arnström, Daniel and Bemporad, Alberto and Axehill, Daniel},
  journal={IEEE Transactions on Automatic Control},
  title={A Dual Active-Set Solver for Embedded Quadratic Programming Using Recursive {LDL}$^{T}$ Updates},
  year={2022},
  volume={67},
  number={8},
  pages={4362-4369},
  doi={10.1109/TAC.2022.3176430}
}

daqp's People

Contributors

darnstrom avatar freyjo avatar jgillis avatar pedro-roque avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

daqp's Issues

Add const

In the API, correctly use const for some of the arguments

Warmstart

Dear Darnstrom,

thank you for sharing this wonderful lightweight QP solver. After a few tests, this solver seems to be the perfekt fit for my problem. I am using it for a small QP with 6 variables and 80 unequality constraints und so far it even outperforms my goto solver qpOASES.

The solver runs on an embbeded hardware and solves an inverse kinematic problem with graduallly changing objective function and constraints. In between steps the the parameter changes are therefore small. Could you comment on how to poperly warstart the solver from the previous solution?

So far I am using update_ldp() followed by daqp_solve() because that is what in you do in the Matlab .update() and .solve() method. But I am not sure if update_ldp() is really neccessary.

By the way your Matlab documentation has a typo. The command d.solve(H,f,A,bupper,blower,sense) does not work.

Best wishes

Julian

Cvxpy interface help/suggestions

Hello @darnstrom and thanks for publishing DAQP! I started working on an interface to call it from CVXPY, work is here cvxpy/cvxpy#2312 , I wonder if you have any comments or suggestions about it. Happy to give you write privileges on that branch if you'd like to make any change. Thanks!

Segmentation Fault on Python Example

Hi Daniel,

I'm trying to run your example for Python and I'm getting segfault on the call to the solver. I followed your installation steps on two different machines running Ubuntu 20.04, and the result was the same. In particular, on my personal machine, I tried to install to a ~/.local prefix, to ensure that there were no issues with permissions accessing the library. This is my result:

~ ipython3
Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import daqp
   ...: import numpy as np
   ...: from ctypes import *
   ...: import ctypes.util
   ...: 
   ...: # Define the problem
   ...: H = np.array([[1, 0], [0, 1]],dtype=c_double)
   ...: f = np.array([1, 1],dtype=c_double)
   ...: A = np.array([[1, 1], [1, -1]],dtype=c_double)
   ...: bupper = np.array([1,2,3,4],dtype=c_double)
   ...: blower = np.array([-1,-2,-3,-4],dtype=c_double)
   ...: sense = np.array([0,0,0,0],dtype=c_int)

In [2]: d = daqp.daqp()
   ...: (xstar,fval,exitflag,info) = d.quadprog(H,f,A,bupper,blower,sense)
id cand:  []
double free or corruption (out)
[1]    38052 abort (core dumped)  ipython3

And on pure python3 shell:

~ python3
Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> # Import relevant modules 
>>> import daqp
>>> import numpy as np
>>> from ctypes import * 
>>> import ctypes.util
>>> 
>>> # Define the problem
>>> H = np.array([[1, 0], [0, 1]],dtype=c_double)
>>> f = np.array([1, 1],dtype=c_double)
>>> A = np.array([[1, 1], [1, -1]],dtype=c_double)
>>> bupper = np.array([1,2,3,4],dtype=c_double)
>>> blower = np.array([-1,-2,-3,-4],dtype=c_double)
>>> sense = np.array([0,0,0,0],dtype=c_int)
>>> d = daqp.daqp()
>>> (xstar,fval,exitflag,info) = d.quadprog(H,f,A,bupper,blower,sense)
id cand:  []
free(): invalid next size (fast)
[1]    38371 abort (core dumped)  python3

Can you double check this on your side on a clean Ubuntu install or a CI system? Let me know if I can provide anything to help with this :)

Pedro,

Use DAQP with inequalities constraints and an equality constraint

Your example only features a quadratic program with inequality constraints, the problem I want to solve is :
minimize $0.5 x^THx$
with $\sum_i x_i = 1$ and $\forall i, x_i&gt;0$.

What is the preferred/advised way to implement to solve this problem with your API in Python?

Also the following note in your documentation is not completely clear to me:

Note: When b_lower and b_upper have more elements than the number of rows in A, the first elements of b_lower and b_upper are interpreted as simple bounds.

This means that the additional first elements of b_lower and b_upper are simple bounds for every coordinate of x (eg every $x_i$)?

First attempt (the first row of A gives the sum equals to one constraint):

import numpy as np

import cvxopt
import daqp
import ctypes
import ctypes.util

    # some symmetric matrix
    H = compute_symmetric_matrix(grads)

    n = grads.shape[1]
    f = np.zeros(n,dtype=ctypes.c_double)
    A = np.eye(n+1,dtype=ctypes.c_double)
    # sum = 1 constraint
    A[0, :] = 1.0

    blower = np.zeros(n,dtype=ctypes.c_double)
    bupper = np.ones(n+1,dtype=ctypes.c_double)

    # most are constraints 0<alpha<1
    sense = np.zeros(n,dtype=ctypes.c_double)
    # sum = 1 constraint
    sense[0] = 5

    (xstar,fval,exitflag,info) = daqp.solve(H,f,A,bupper,blower,sense)

Second attempt

    H = compute_symmetric_matrix(grads)

    n = grads.shape[1]
    f = np.zeros(n,dtype=ctypes.c_double)
    # sum = 1 constraint
    A = np.ones((1,n),dtype=ctypes.c_double)
    # x>=0 constraint
    blower = np.zeros(2,dtype=ctypes.c_double)

    # most are constraints 0<alpha<1
    sense = np.zeros(2,dtype=ctypes.c_double)
    # sum = 1 constraint
    sense[1] = 5

    (xstar,fval,exitflag,info) = daqp.solve(H,f,A,bupper,blower,sense)

Best regards.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.