QP: constructor for Quadratic Problem assignment

1/2 x' H x + f' x -> min

subjected to

A x <= b Aeq x = beq lb <= x <= ub Alternatively to A/Aeq you can use Awhole matrix as it's descriebed in LP documentation (or both A, Aeq, Awhole) examples of valid calls: p = QP(H, f, params)

p = QP(numpy.ones((3,3)), f=numpy.array([1,2,4]), params)

p = QP(f=range(8)+15, H = numpy.diag(numpy.ones(8)), params)

p = QP(H, f, A=A, Aeq=Aeq, b=b, beq=beq, lb=lb, ub=ub, params)

INPUT:

H: size n x n matrix, symmetric, positive-definite

f: size n x 1 vector

A: size m1 x n matrix, subjected to A * x <= b Aeq: size m2 x n matrix, subjected to Aeq * x = beq OUTPUT: OpenOpt QP class instance Solving of QPs is performed via r = p.solve(string_name_of_solver) Currently string_name_of_solver can be: cvxopt_qp (GPL) - requires CVXOPT (http://abel.ee.ucla.edu/cvxopt) (unfortunately, I can't suppress cvxopt text output, its solvers don't have appropriate params) Let's concider the problem x1^2 + 2x2^2 + 3x3^2 + 15x1 + 8x2 + 80x3 -> min (1)

subjected to

x1 + 2x2 + 3x3 <= 150 (2)

8x1 + 15x2 + 80x3 <= 800 (3)

x2 - x3 = 25 (4)

x1 <= 15 (5)

from numpy import diag, matrix

from scikits.openopt import QP

p = QP(diag([1,2,3]), [15,8,80], A = matrix('1 2 3; 8 15 80'), b = [150, 800], Aeq = [0, 1, -1], beq = 25, ub = [15,inf,inf])

# or p = QP(H=diag([1,2,3]), f=[15,8,80], A = matrix('1 2 3; 8 15 80'), b = [150, 800], Aeq = [0, 1, -1], beq = 25, ub = [15,inf,inf])

r = p.solve('cvxopt_qp')

f_opt, x_opt = r.ff, r.xf

# x_opt = array([-14.99999995, -2.59999996, -27.59999991])

# f_opt = -2453.7999916

Subscribe to:
Post Comments (Atom)

## No comments:

Post a Comment