Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. from scipy.optimize import linprog
  2.  
  3.  
  4. def linear(M, b, x,bounds, maxi):
  5.  
  6. if maxi:
  7. res = linprog([i * -1 for i in x], A_ub=M, b_ub=b, bounds = bounds ,options={"disp": False}).x
  8. else:
  9. res = linprog(x, A_ub=M, b_ub=b, bounds = bounds ,options={"disp": False}).x
  10.  
  11. return res
  12.  
  13.  
  14. M = [[2, 1, -9000], [1, 1, -5500],
  15. [1, 2.5, -10000], [-1, 0, 100], [0,-1,100],
  16. [36.8, 65.7, 0], [-36.8, -65.7, 0]]
  17. b = [0, 0, 0, 0, 0, 1, -1]
  18. z1 = [150,130,0]
  19. bounds= [(0,None),(0,None),(0,None)]
  20. res = linear(M, b, z1, bounds,True)
  21. print(res)
  22.  
  23. x1 = res[0]/res[2]
  24. print("A:")
  25. print(round(x1))
  26.  
  27. x2 = res[1]/res[2]
  28. print("B:")
  29. print(round(x2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement