标签:
>>> c = [-1, 4] >>> A = [[-3, 1], [1, 2]] >>> b = [6, 4] >>> x0_bounds = (None, None) >>> x1_bounds = (-3, None) >>> from scipy.optimize import linprog >>> res = linprog(c, A_ub=A, b_ub=b, bounds=(x0_bounds, x1_bounds), ... options={"disp": True}) >>> print(res) Optimization terminated successfully. Current function value: -11.428571 Iterations: 2 status: 0 success: True fun: -11.428571428571429 x: array([-1.14285714, 2.57142857]) message: ‘Optimization terminated successfully.‘ nit: 2
In [1]:c = np.array([4,3])
In [1]:a = np.array([[2,1],[1,1]])
In [1]:In [1]:b = np.array([10,8])
In [1]:optimize.linprog(c,a,b,bounds=((0,None),(0,7)))
Out[1]:
fun: -0.0
message: ‘Optimization terminated successfully.‘
nit: 0
slack: array([ 10., 8., 7.])
status: 0
success: True
x: array([ 0., 0.])
In [1]:optimize.linprog(-c,a,b,bounds=((0,None),(0,7)))
Out[1]:
fun: -26.0
message: ‘Optimization terminated successfully.‘
nit: 2
slack: array([ 0., 0., 1.])
status: 0
success: True
x: array([ 2., 6.])
使用Python scipy linprog 线性规划求最大值或最小值(使用Python学习数学建模笔记)
标签:
原文地址:http://www.cnblogs.com/zhilangtaosha/p/5745556.html