この単純な最適化問題を解決するために 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 です)
print 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