scipy.optimize.linprog - 难以理解参数
scipy.optimize.linprog - difficulty understanding the parameters
我想最小化以下 LPP:
c=60x+40y+50z
受制于
20x+10y+10z>=350 ,
10x+10y+20z>=400, x,y,z>=0
我的代码片段如下(我是第一次使用 scipy 包)
from scipy.optimize import linprog
c = [60, 40, 50]
A = [[20,10], [10,10],[10,20]]
b = [350,400]
res = linprog(c, A, b)
print(res)
输出为:screenshot of the output in Pycharm
1.Can有人详细解释了linprog函数的参数,特别是bound是怎么计算的?
2.Have我写的参数对吗?
我对 LPP 基础知识很幼稚,我想我对参数的理解有误。
linprog
期望 A
每个不等式一行,每个变量一列,而不是相反。试试这个:
from scipy.optimize import linprog
c = [60, 40, 50]
A = [[20, 10, 10], [10, 10, 20]]
b = [350, 400]
res = linprog(c, A, b)
print(res)
输出:
fun: -0.0
message: 'Optimization terminated successfully.'
nit: 0
slack: array([ 350., 400.])
status: 0
success: True
x: array([ 0., 0., 0.])
该消息告诉您 A_ub
矩阵的维度不正确。它目前是一个 3x2 矩阵,不能 left-multiply 您的 3x1 优化变量 x
。你需要写:
A = [[20,10, 10], [10,10,20]]
这是一个 2x3 矩阵,可以左乘 x
。
我想最小化以下 LPP: c=60x+40y+50z 受制于 20x+10y+10z>=350 , 10x+10y+20z>=400, x,y,z>=0
我的代码片段如下(我是第一次使用 scipy 包)
from scipy.optimize import linprog
c = [60, 40, 50]
A = [[20,10], [10,10],[10,20]]
b = [350,400]
res = linprog(c, A, b)
print(res)
输出为:screenshot of the output in Pycharm
1.Can有人详细解释了linprog函数的参数,特别是bound是怎么计算的?
2.Have我写的参数对吗?
我对 LPP 基础知识很幼稚,我想我对参数的理解有误。
linprog
期望 A
每个不等式一行,每个变量一列,而不是相反。试试这个:
from scipy.optimize import linprog
c = [60, 40, 50]
A = [[20, 10, 10], [10, 10, 20]]
b = [350, 400]
res = linprog(c, A, b)
print(res)
输出:
fun: -0.0
message: 'Optimization terminated successfully.'
nit: 0
slack: array([ 350., 400.])
status: 0
success: True
x: array([ 0., 0., 0.])
该消息告诉您 A_ub
矩阵的维度不正确。它目前是一个 3x2 矩阵,不能 left-multiply 您的 3x1 优化变量 x
。你需要写:
A = [[20,10, 10], [10,10,20]]
这是一个 2x3 矩阵,可以左乘 x
。