我无法求解整数线性编程最小化



这是我的代码和结果。我使用Spyder解决问题,但行不通。

from scipy.optimize import linprog
c = [2, 3, 4, 6, 7, 5, 7, 8, 9, 9, 8, 9]
A = [[1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0],
     [0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0],
     [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],
     [1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1],
     [1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0],
     [0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1],
     [0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0],
     [0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0],
     [0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1],
     [0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1]]
b = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
x0_bounds = (1, None)
x1_bounds = (1, None)
x2_bounds = (1, None)
x3_bounds = (1, None)
x4_bounds = (1, None)
x5_bounds = (1, None)
x6_bounds = (1, None)
x7_bounds = (1, None)
x8_bounds = (1, None)
x9_bounds = (1, None)
x10_bounds = (1, None)
x11_bounds = (1, None)
res = linprog(c,A,b,bounds=(x0_bounds, x1_bounds, x2_bounds, x3_bounds, x4_bounds, x5_bounds, x6_bounds, x7_bounds, x8_bounds, x9_bounds, x10_bounds, x11_bounds),  method='simplex')
print(res)
runfile('C:/Users/Jo/Desktop/project/project1.py', wdir='C:/Users/Jo/Desktop/project')  

输出:

fun: 9.0
message: 'Optimization failed. Unable to find a feasible starting point.'
nit: 3
status: 2
success: False
x: nan

没有 Integer - scipy中的编程,仅连续线性编程。

您的问题是不可行的(method=simplex并不能使您联系给您(。

(甚至(第一个约束:

[1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0] * x <= 1  # informal algebraic notation

无法使每个变量都限制为range(1,np.inf)

这意味着:row_0 * x >= 4,它永远不可能是<= 1

method="interior-point"(scipy> = 1.0(将给出预期的输出:

con: array([], dtype=float64)
fun: 164.90023152478039
message: 'The algorithm terminated successfully and determined that the problem is infeasible.'
nit: 5
slack: array([ -7.14186342,  -8.35704274,  -8.90930795, -10.95194357,
   -5.89531228,  -7.50250265,  -6.92825952, -11.33686301,
   -4.52268237,  -7.17603881,  -8.66152866])
status: 2
success: False
  x: array([ 1.04386377,  3.83436037,  3.51159834,  4.51186381,  2.09089519,
   2.58762946,  1.20140415,  1.55269982,  1.89974364,  1.38473169,
   1.87908735,  1.9103365 ])

最新更新