how to get the maximum result with quadratic programming on CVXOPT ?

the question is posted in follow page as well. https://stackoverflow.com/questions/47119580/how-to-get-the-maximum-result-with-quadratic-programming-on-cvxopt

I want to use CVXOPT to solve a quadratic programming.

'''
                        Value       =2      =3     =5        
                    Value*return    >=9    >=9      no requirement       
                   Value*Duration   <=5    <=9      no requirement
      Value  return  Duration           
        4       5       2           x11      x12   x13    
        6       4       4           x21      x22   x23 

the matrix is like about, I want to get x11, x12,…x23.

the subject is as following:

G*x<=h
-5*x11         -4*x21      <=-9
      -5*x12         -4*x22<=-9
                           <=0
 2*x11         +4*x21      <=5
       2*x12        +4*x22 <=9
                           <=0


A*x=b

x11+x12+x13           =4
           x21+x22+x23=6
x11       +x21        =2
    x12       +x22    =3
        x13       +x23=5

I want get the target Max (x11^2+x12^2+x13^2+x21^2+x22^2+x23^2)

I wrote the following code:

import cvxopt as op
p_tg=op.matrix(0.0,(6,6))
p_tg[::7]=1
P = 2*op.matrix(p_tg)

q = op.matrix( [0.0,0,0,0,0,0])

G=op.matrix([[-5.0,0,0,2,0,0],
             [0,-5,0,0,2,0],
             [0,0,0,0,0,0],
             [-4,0,0,4,0,0],
             [0,-4,0,0,4,0],
             [0,0,0,0,0,0]])

h=op.matrix([-9.0,-9,0,5,9,0])  

A=op.matrix([[1.0,0,1,0,0],
             [1,0,0,1,0],
             [1,0,0,0,1],
             [0,1,1,0,0],
             [0,1,0,1,0],
             [0,1,0,0,1]])              
b=op.matrix([4,6,2.0,3,5])

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

print(sol['x'])

of course, the above code get the minimum, not the maximum.

how to get the max result? I try to p_tg[::7]=-1, while it report error.

raise ValueError(“Rank(A) < p or Rank([P; A; G]) < n”)

ValueError: Rank(A) < p or Rank([P; A; G]) < n

分享到: 微信 新浪微博 更多
Print Friendly, PDF & Email

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注