Skip to content

Instantly share code, notes, and snippets.

@airalcorn2
Created October 21, 2019 20:48
Show Gist options
  • Select an option

  • Save airalcorn2/afd661a266ae188e5c5ad72d9cc75438 to your computer and use it in GitHub Desktop.

Select an option

Save airalcorn2/afd661a266ae188e5c5ad72d9cc75438 to your computer and use it in GitHub Desktop.
Solve and plot the level curves of a simple linear program.
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import linprog
A_ub = np.eye(3)
b_ub = np.ones(3)
A_eq = np.array([[0.95, 0.9, 0.15]])
b_eq = np.ones(1)
c = -np.array([0.9, 0.02, 0.08])
print(linprog(c, A_ub, b_ub, A_eq, b_eq))
delta = 0.025
a = np.arange(0.0, 1.0, delta)
b = np.arange(0.0, 1.0, delta)
(A, B) = np.meshgrid(a, b)
P = 0.9 * A + 0.02 * B + 0.08 * (1 - 0.95 * A - 0.9 * B) / 0.15
(fig, ax) = plt.subplots()
contours = ax.contour(A, B, P)
ax.clabel(contours, inline=1, fontsize=10)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment