Advertisement
makispaiktis

Python - Linear Programming

Oct 30th, 2022 (edited)
1,041
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. from cvxopt import solvers, matrix
  2.  
  3. # Elements of a matrix are columns
  4. # All the elements must be FLOAT, so I add a '.', so 2 = 2. = 2.0
  5. A = matrix([[-1., -1., 0., 1.], [1., -1., -1., -2.]])
  6. print(A)
  7. b = matrix([1., -2., 0., 4.])
  8. print(b)
  9. c = matrix([2., 1.])
  10. print(c)
  11.  
  12. # Minimization problem is the following:
  13. # min(c^T * x)     subject to: Ax <= b
  14. sol = solvers.lp(c, A, b)
  15. sol2 = solvers.lp(c, A, b, options = {'maxiters': 3})
  16.  
  17. optimal = sol['x']
  18. print("Optimal Solution")
  19. print(optimal)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement