darnstrom / daqp Goto Github PK
View Code? Open in Web Editor NEWA dual active-set algorithm for convex quadratic programming
License: MIT License
A dual active-set algorithm for convex quadratic programming
License: MIT License
See Section 3.1 in BnBDAQP paper
if I want to use daqp to solve integer qp, must I transfer integer variable into binary variable?
how to set x to be integer
Your example only features a quadratic program with inequality constraints, the problem I want to solve is :
minimize $0.5 x^THx$
with
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
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)
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.
In the API, correctly use const for some of the arguments
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,
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!
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
For example, use an example that that highlight that matrices are row major.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.