I'm trying to run an optimization with scipy.optimize.differential_evolution. The code calls for bounds for each variable in x. But I want to a solution where parts of x must be integers, while others can range freely as floats. The relevant part of my code looks like
bounds = [(0,3),(0,3),(0,3),???,???]
result = differential_evolution(func, bounds)
What do I replace the ???'s with to force those variables to be ints in a given range?
As noted in the comments there isn't direct support for a "integer constraint".
You could however minimize a modified objective function, e.g.:
and this will force
x[3]towards an integer value (unfortunately you have to tune theKparameter).An alternative is to round (some of) the real-valued parameters before evaluating the objective function:
Both are common techniques to approach a discrete optimization problem using Differential Evolution and they work quite well.