【问题标题】:I can not solve integer linear programming minimization [closed]我无法解决整数线性规划最小化[关闭]
【发布时间】: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


    【解决方案1】:

    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 &gt;= 4,它永远不可能是&lt;= 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 ])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-24
      • 2023-03-22
      • 1970-01-01
      • 2015-05-31
      • 1970-01-01
      • 2019-10-02
      • 1970-01-01
      相关资源
      最近更新 更多