diff --git a/EA/helloworld.py b/EA/helloworld.py deleted file mode 100644 index c6943ce..0000000 --- a/EA/helloworld.py +++ /dev/null @@ -1,34 +0,0 @@ -import random -from deap import creator, base, tools, algorithms - -creator.create("FitnessMax", base.Fitness, weights=(1.0,)) -creator.create("Individual", list, fitness=creator.FitnessMax) - -toolbox = base.Toolbox() - -toolbox.register("attr_bool", random.randint, 0, 1) -toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_bool, n=100) -toolbox.register("population", tools.initRepeat, list, toolbox.individual) - - -def evalOneMax(individual): - return sum(individual), - -toolbox.register("evaluate", evalOneMax) -toolbox.register("mate", tools.cxTwoPoint) -toolbox.register("mutate", tools.mutFlipBit, indpb=0.05) -toolbox.register("select", tools.selTournament, tournsize=3) - -population = toolbox.population(n=300) - -NGEN=40 -for gen in range(NGEN): - offspring = algorithms.varAnd(population, toolbox, cxpb=0.5, mutpb=0.1) - fits = toolbox.map(toolbox.evaluate, offspring) - for fit, ind in zip(fits, offspring): - ind.fitness.values = fit - population = toolbox.select(offspring, k=len(population)) -top10 = tools.selBest(population, k=10) - -for individual in top10: - print(sum(individual)) \ No newline at end of file