简体   繁体   English

scipy.optimize.linprog-难以理解参数

[英]scipy.optimize.linprog - difficulty understanding the parameters

I want to minimize the following LPP: c=60x+40y+50z subject to 20x+10y+10z>=350 , 10x+10y+20z>=400, x,y,z>=0 我想最小化以下LPP:c = 60x + 40y + 50z服从20x + 10y + 10z> = 350,10x + 10y + 20z> = 400,x,y,z> = 0

my code snippet is the following(I'm using scipy package for the first time) 我的代码段如下(我第一次使用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)

The output is : screenshot of the output in Pycharm 输出为: Pycharm中输出的屏幕截图

1.Can someone explain the parameters of the linprog function in detail, especially how the bound will be calculated? 1.有人可以详细解释linprog函数的参数,尤其是如何计算边界吗?

2.Have I written the parameters right? 2.我写的参数正确吗?

I am naive with LPP basics, I think I am understanding the parameters wrong. 我对LPP基础知识很幼稚,我认为我理解错误的参数。

linprog expects A to have one row per inequation and one column per variable, and not the other way around. linprog期望A每个不等式有一行,每个变量有一列,而不是相反。 Try this: 尝试这个:

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)

Output: 输出:

     fun: -0.0
 message: 'Optimization terminated successfully.'
     nit: 0
   slack: array([ 350.,  400.])
  status: 0
 success: True
       x: array([ 0.,  0.,  0.])

The message is telling you that your A_ub matrix has incorrect dimension. 该消息告诉您A_ub矩阵的尺寸不正确。 It is currently a 3x2 matrix which cannot left-multiply your 3x1 optimization variable x . 当前是3x2矩阵,无法将3x1优化变量x左乘。 You need to write: 您需要写:

A = [[20,10, 10], [10,10,20]]

which is a 2x3 matrix and can left multiply x . 这是一个2x3的矩阵,可以让x相乘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM