1
def checkBounds(min, max):
def decorator(func):
    def wrapper(*args, **kargs):
        offspring = func(*args, **kargs)
        for child in offspring:
            for i in range(len(child)):
                if child[i] > max:
                    child[i] = max
                elif child[i] < min:
                    child[i] = min
        return offspring
    return wrapper
return decorator

toolbox.register("mate", tools.cxBlend, alpha=0.2) toolbox.register("mutate", tools.mutGaussian, mu=0, sigma=2)

toolbox.decorate("mate", checkBounds(MIN, MAX)) toolbox.decorate("mutate", checkBounds(MIN, MAX))

This is the code(https://deap.readthedocs.io/en/master/tutorials/basic/part2.html#tool-decoration) which allows us to put bounds during an evolution in GA(Genetic Algorithm).

Suppose my population in subsequent generations are always touching the bounds. Then how do I update my bounds(value of min and max)? The problem is the mutate function is decorated earlier. Do I again have to use the decorate statement to change the bounds?

A method to be able to change the min and max value during evolution would be really helpful

Arijit
  • 11
  • 3

0 Answers0