【发布时间】:2018-03-24 10:58:34
【问题描述】:
这是我的代码和结果。我使用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
【问题讨论】:
标签: python python-3.x scipy integer linear-programming