Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.