Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@matiasherranz
Created December 3, 2016 22:57
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 matiasherranz/9572f48e153f59b6aa3bfe11ec8d5e9e to your computer and use it in GitHub Desktop.
Save matiasherranz/9572f48e153f59b6aa3bfe11ec8d5e9e to your computer and use it in GitHub Desktop.
from numpy import array, sum as npsum
from scipy.optimize import minimize
cons = (
{'type': 'ineq', 'fun': lambda x: array([25 - 0.2 * x[0] - 0.4 * x[1] - 0.33 * x[2]])},
{'type': 'ineq', 'fun': lambda x: array([130 - 5 * x[0] - 8.33 * x[2]])},
{'type': 'ineq', 'fun': lambda x: array([16 - 0.6 * x[1] - 0.33 * x[2]])},
{'type': 'ineq', 'fun': lambda x: array([7 - 0.2 * x[0] - 0.1 * x[1] - 0.33 * x[2]])},
{'type': 'ineq', 'fun': lambda x: array([14 - 0.5 * x[1]])},
{'type': 'ineq', 'fun': lambda x: array([x[0]])},
{'type': 'ineq', 'fun': lambda x: array([x[1]])},
{'type': 'ineq', 'fun': lambda x: array([x[2]])},
{'type': 'eq', 'fun': lambda x: array([1 - npsum(x)])}
)
f = lambda x: -1 * (x[0] + x[1] + x[2])
res = minimize(f, [0, 0, 0], method='SLSQP', constraints=cons, options={'disp': True})
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment