简体   繁体   中英

How to set up multiple equality constraints in quadratic programming in python?

In the example given in https://cvxopt.org/examples/tutorial/qp.html , they give the syntax for the situation when there is one equality constraint but I am having problems getting it right when I have three equality constraints.

CVXOPT can be easily implemented with several inequality as well as equality constraint and they follow the same logic.

So for the inequality Gx <= h you will have

G = opt.matrix(np.concatenate([G1,Gn])
h = opt.matrix(np.concatenate([h1,hn])

The same logic will apply for multiple equality constraint where Ax == b, hence

A = opt.matrix(np.concatenate([A1,An])
b = opt.matrix(np.concatenate([b1,bn])

then you can set the solver to be

sol = solvers.qp(P, q, G, h, A, b)

The only thing you need to be careful not to have error is to make sure you concatenate matrixes, hence you need to transform value into matrix

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM