python - 在 CVXOPT CVXOPT中,简单的优化 无优化

  显示原文与译文双语对照的内容
0 0

我使用CVXOPT来解决这个简单的优化问题:

maximize X1 + X2 
s.t:
 X2 + X6 = 2
 X1 + X2 + X5 = 2
 X1 + X4 = 2
 X1> =0
 X2> =0 

显然这是一个非常简单的解决方案

 X1 = 1 
 X2 = 1 

( 剩下的都是 0 )

但是,cvxopt完全错误。 这就是我所做的:

>>> print A
 [ 0.00e+00 1.00e+00 0.00e+00 0.00e+00 0.00e+00 1.00e+00]
 [ 1.00e+00 1.00e+00 0.00e+00 0.00e+00 1.00e+00 0.00e+00]
 [ 1.00e+00 0.00e+00 0.00e+00 1.00e+00 0.00e+00 0.00e+00]
>>> print b
[ 2.00e+00]
[ 2.00e+00]
[ 2.00e+00]
>>> print G
[-1.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00]
[ 0.00e+00 -1.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00]
>>> print h
 [ 0.00e+00]
 [ 0.00e+00]
>>> print c
[-1.00e+00]
[-1.00e+00]
[ 0.00e+00]
[ 0.00e+00]
[ 0.00e+00]
[ 0.00e+00]

( 上所有都是"矩阵"类型的cvxopt )

打印 glpk.ilp(c,G,h,A,b,I=set( [0,1,2,3,4,5] )) [1 ]

GLPK Integer Optimizer, v4.43
5 rows, 6 columns, 9 non-zeros
6 integer variables, none of which are binary
Preprocessing...
3 rows, 5 columns, 7 non-zeros
5 integer variables, none of which are binary
Scaling...
 A: min|aij| = 1.000e+00 max|aij| = 1.000e+00 ratio = 1.000e+00
Problem data seem to be well scaled
Constructing initial basis...
Size of triangular part = 3
Solving LP relaxation...
GLPK Simplex Optimizer, v4.43
3 rows, 5 columns, 7 non-zeros
* 0: obj = 0.000000000e+00 infeas = 0.000e+00 (0)
PROBLEM HAS UNBOUNDED SOLUTION
None
时间:原作者:6个回答

0 0

下面是实现上述代码的代码:

import cvxopt.glpk
import cvxopt
c=cvxopt.matrix([1,1,0,0,0,0])
G=cvxopt.matrix([[1.0,0,0,0,0,0], [0,1,0,0,0,0]])
h=cvxopt.matrix([0.0,0.0])
A=cvxopt.matrix([[0.0,1,0,0,0,6], [1,1,0,0,1,0], [1,0,0,1,0,0]])
b=cvxopt.matrix([2.0, 2, 2])
(status, c)=cvxopt.glpk.ilp(-c,-(G.T),-h,A.T,b,I=set([0,1,2,3,4,5]))
print(status, c)

结果是:

optimal [ 0.00e+00]
[ 2.00e+00]
[ 0.00e+00]
[ 2.00e+00]
[ 0.00e+00]
[ 0.00e+00]

我不确定如何获得所有的解决方案。

原作者:
0 0

根据你提供的LP,GLPK是正确的。

( 0,5,0,1,5,1,1,5 ) 是可行

还有一个极端射线。

原作者:
...