optimization - Constraints on parameters using differential evolution in python -
i trying use differential evolution optimize availability based on cost. however, have 3 unknown parameters (a, b, c) here , can define range using bounds. however, want define additional constraint a+b+c <= 10000. using python , tried use option "args" within differential evolution did not work. information appreciated.
here hack. used last example documentation , constrained sum(x) > 4.1 (without constraint optimized solution (0,0)):
from scipy.optimize import differential_evolution import numpy np def ackley(x): arg1 = -0.2 * np.sqrt(0.5 * (x[0] ** 2 + x[1] ** 2)) arg2 = 0.5 * (np.cos(2. * np.pi * x[0]) + np.cos(2. * np.pi * x[1])) if x[0]+x[1] > 4.1: #this constraint, a+b+c <=1000 return -20. * np.exp(arg1) - np.exp(arg2) + 20. + np.e else: return 1000 #some high value bounds = [(-5, 5), (-5, 5)] result = differential_evolution(ackley, bounds) result.x, result.fun
Comments
Post a Comment