所有的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])发布于 2020-07-07 19:06:43
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.])https://stackoverflow.com/questions/62669305
复制相似问题