For quadratic programming with Python, I use qp -solver from cvxopt ( source ). Using this, it is easy to translate the LCP problem into the QP problem (see Wikipedia ). Example:
from cvxopt import matrix, spmatrix from cvxopt.blas import gemv from cvxopt.solvers import qp def append_matrix_at_bottom(A, B): l = [] for x in xrange(A.size[1]): for i in xrange(A.size[0]): l.append(A[i+x*A.size[0]]) for i in xrange(B.size[0]): l.append(B[i+x*B.size[0]]) return matrix(l,(A.size[0]+B.size[0],A.size[1])) M = matrix([[ 4.0, 6, -4, 1.0 ], [ 6, 1, 1.0 2.0 ], [-4, 1.0, 2.5, -2.0 ], [ 1.0, 2.0, -2.0, 1.0 ]]) q = matrix([12, -10, -7.0, 3]) I = spmatrix(1.0, range(M.size[0]), range(M.size[1])) G = append_matrix_at_bottom(-M, -I)
Note:
- the code is not fully verified, please check carefully;
- there are certainly better solution methods than converting LCP to QP.
stephan
source share