Created
December 3, 2016 22:57
-
-
Save matiasherranz/9572f48e153f59b6aa3bfe11ec8d5e9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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