简体   繁体   中英

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

my code snippet is the following(I'm using scipy package for the first time)

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

1.Can someone explain the parameters of the linprog function in detail, especially how the bound will be calculated?

2.Have I written the parameters right?

I am naive with LPP basics, I think I am understanding the parameters wrong.

linprog expects A to have one row per inequation and one column per variable, and not the other way around. 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. It is currently a 3x2 matrix which cannot left-multiply your 3x1 optimization variable x . You need to write:

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

which is a 2x3 matrix and can left multiply x .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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