【问题标题】:python scipy linprog simplex example v 1.5python scipy linprog simplex example v 1.5
【发布时间】:2020-07-01 03:38:00
【问题描述】:

所有 scipy 示例都使用旧版本,我正在寻找有关如何使用新版本的示例。

https://docs.scipy.org/doc/scipy/reference/optimize.linprog-simplex.html

我创建了一个超级简单的代码,它显示问题是无限的。任何帮助表示赞赏。

Minimize x - y

with
x >= 2
y <= 3

In standard form
-x - s1 = -2
y + s2 = 3

许多解决方案之一应该是 x = 2, y = 3

c = [1, -1]
A = [[-1, 0, -1, 0],[0, 1, 0, 1]]
b = [-2, 3]
linprog(c, method="simplex", options={'A': A, 'b': b})

result
------------------
     con: array([], dtype=float64)
     fun: -inf
 message: 'The problem is (trivially) unbounded because there are no non-trivial constraints and a) at least one decision variable is unbounded above and its corresponding cost is negative, or b) at least one decision variable is unbounded below and its corresponding cost is positive. '
     nit: 0
   slack: array([], dtype=float64)
  status: 3
 success: False
       x: array([ 0., inf])

【问题讨论】:

    标签: python scipy-optimize


    【解决方案1】:

    scipy.optimize.linprog(c, method='simplex', callback=None, options={'c0': None, 'A': None, 'b': None, 'postsolve_args': None, 'maxiter': 1000, 'tol': 1e-09, 'disp': False, 'bland': False}, x0=None)

    最小化受线性等式非负性约束

    的线性目标函数

    这意味着您在使用此界面时无法解决您的问题。阅读文档中的说明。

    您应该改用顶级linprog 模块。由于您没有等式和不等式约束,您的A_ub, b_ub, A_eq and b_eq 矩阵为None,您只需定义bounds

    c = [1, -1]
    x_bounds = [2, None]
    y_bounds = [None, 3]
    res = linprog(c, bounds=[x_bounds, y_bounds], method='simplex')
    
    res
    Out[]: 
         fun: -1.0
     message: 'Optimization terminated successfully.'
         nit: 2
       slack: array([0., 0., 0., 0.])
      status: 0
     success: True
           x: array([ 2., 3.])
    

    【讨论】:

      猜你喜欢
      • 2020-08-25
      • 2020-03-20
      • 1970-01-01
      • 2017-04-10
      • 1970-01-01
      • 1970-01-01
      • 2020-11-26
      • 2020-11-22
      • 2018-02-03
      相关资源
      最近更新 更多