以下 LP 代码哪里出错了?

Where am I going wrong in the following LP code?

我正在尝试解决一个 LP 问题,其中包含两个变量和两个约束,其中一个是不等式,另一个是 Scipy 中的等式约束。 为了转换约束中的不等式,我在其中添加了另一个名为 A.

的变量
Min(z) = 80x + 60y

约束条件:

0.2x + 0.32y <= 0.25
x + y = 1
x, y <= 0

我通过添加一个额外的变量 A

改变了以下等式的不等式约束
0.2x + 0.32y + A = 0.25
Min(z) = 80x + 60y + 0A
X+ Y + 0A = 1

from scipy.optimize import linprog
import numpy as np

z = np.array([80, 60, 0])
C = np.array([
[0.2, 0.32, 1],
[1, 1, 0]
])
b = np.array([0.25, 1])
x1 = (0, None)
x2 = (0, None)
sol = linprog(-z, A_eq = C, b_eq = b, bounds = (x1, x2), method='simplex')

但是,我收到一条错误消息

Invalid input for linprog with method = 'simplex'. Length of bounds is inconsistent with the length of c

我该如何解决这个问题?

问题是您没有为 A 提供界限。如果你例如运行

linprog(-z, A_eq = C, b_eq = b, bounds = (x1, x2, (0, None)), method='simplex')

您将获得:

     con: array([0., 0.])
     fun: -80.0
 message: 'Optimization terminated successfully.'
     nit: 3
   slack: array([], dtype=float64)
  status: 0
 success: True
       x: array([1.  , 0.  , 0.05])

如您所见,满足了约束条件:

0.2 * 1 + 0.32 * 0.0 + 0.05 = 0.25  # (0.2x + 0.32y + A = 0.25)

还有

1 + 0 + 0 = 1  # (X + Y + 0A = 1)