Reputation: 11
I am working on a third party software optimization problem using Scipy optimize.minimize with constraints and bounds (using the SLSQP method). Exactly I am giving inputs to a very complex function (can't write it here) that will launch my software and return me one output I need to minimize.
def func_to_minimize(param):
launch_software(param)
return software_output() # I retrieve the output after the software finish his computation
While working on it, I notice that during the optimization, the algorithm does not always respect the constraints.
However, the software I am trying to optimize cannot be run with certain inputs values (physical law not to be violated), I wrote these equations as constraints in my code. For example the output flow rate can't be greater than the input flow rate.
I would like to know if it is possible to respect these constraints even during the optimization.
Upvotes: 1
Views: 329
Reputation: 545
One approach you could try is intercept param
and check whether it's feasible before sending it to launch_software
. If it's not feasible then return np.inf
. I'm not sure that this will work with SLSQP, but give it a go.
One approach, that will work, would be to use optimize.differential_evolution
. That function examines to see if your constraints are feasible before calculating the objective function; if it's not then your objective function isn't called. However, differential_evolution
does ask for orders of magnitude more function evaluations, so if your objective function is expensive then that could be an issue. One amelioration would be vectorisation or parallel computation.
Upvotes: 1