Skip to content

Instantly share code, notes, and snippets.

@jakwuh
Created October 22, 2016 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakwuh/3bbaa3a77f0bcef864a039993156cfe1 to your computer and use it in GitHub Desktop.
Save jakwuh/3bbaa3a77f0bcef864a039993156cfe1 to your computer and use it in GitHub Desktop.
from scipy.optimize import linprog
c = [-6, -3, 2, 1, 14] # x_1 + x_2 - 2x_3 - x_4 -> max
# Ax <= b
A = [[0, 0, 0, 1, 2], [3, 0, 2, 0, -4], [0, -1, 3, 0, 0]]
b = [-4, 25, 6]
x0_bounds = (1, 4)
x1_bounds = (-1, 3)
x2_bounds = (-2, 2)
x3_bounds = (1, 4)
x4_bounds = (-3, 1)
res = linprog(c, A_ub=A, b_ub=b, bounds=(x0_bounds, x1_bounds, x2_bounds, x3_bounds, x4_bounds),
options={"disp": True})
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment