You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am beginner using DEAP to run a multi objective optimization using eaMuPlusLambda. The following code returns the ParetoFront after the last generation. Is there any way to get a set of ParetoFront for each generation? I would like to see the evolution of the fronts with every generation.
import random
import numpy
import matplotlib.pyplot as plt
from deap import base, creator, tools, algorithms
''' Objective Function 1 '''
def f1(individual):
x, y = individual
return x1 + y0
''' Objective Function 2 '''
def f2(individual):
x, y = individual
return (1+y)/x
def feasible(individual):
if 0.1 < individual[0] < 1:
if 0 < individual[1] < 5:
return True
return False
I am beginner using DEAP to run a multi objective optimization using eaMuPlusLambda. The following code returns the ParetoFront after the last generation. Is there any way to get a set of ParetoFront for each generation? I would like to see the evolution of the fronts with every generation.
import random
import numpy
import matplotlib.pyplot as plt
from deap import base, creator, tools, algorithms
''' Objective Function 1 '''
def f1(individual):
x, y = individual
return x1 + y0
''' Objective Function 2 '''
def f2(individual):
x, y = individual
return (1+y)/x
def feasible(individual):
if 0.1 < individual[0] < 1:
if 0 < individual[1] < 5:
return True
return False
creator.create("FitnessMulti", base.Fitness, weights=(-1.0, -1.0))
creator.create("Individual", list, fitness=creator.FitnessMulti)
toolbox = base.Toolbox()
toolbox.register("attr_float", random.random)
toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_float, n=2)
toolbox.register("population", tools.initRepeat, list, toolbox.individual)
toolbox.register("mate", tools.cxBlend, alpha=0.5)
toolbox.register("mutate", tools.mutGaussian, mu=0, sigma=1, indpb=0.2)
toolbox.register("evaluate", lambda ind: (f1(ind), f2(ind)))
toolbox.decorate("evaluate", tools.DeltaPenalty(feasible, 1000))
toolbox.register("select", tools.selNSGA2)
population = toolbox.population(n=100)
stats = tools.Statistics(lambda ind: ind.fitness.values)
stats.register('mean', numpy.mean, axis=0)
stats.register("min", numpy.min, axis=0)
stats.register("max", numpy.max, axis=0)
result, log = algorithms.eaMuPlusLambda(population, toolbox, mu=100, lambda_=200, cxpb=0.7, mutpb=0.2, ngen=200,
stats=stats,verbose=True)
pareto_front = tools.sortNondominated(population, len(population), first_front_only=True)[0]
O1 = []
O2 = []
for ind in pareto_front:
O1 = O1 + [ind.fitness.values[0]]
O2 = O2 + [ind.fitness.values[1]]
plt.scatter(O1, O2, label='Pareto Front’,s=10, marker=".", color='darkblue')
plt.show()
The text was updated successfully, but these errors were encountered: