- END of bugfixing

with Michał Malinowski
This commit is contained in:
Lewy 2021-06-21 04:47:16 +02:00
parent 5ca916873d
commit bd33fa3df5

View File

@ -32,7 +32,7 @@ def genetic_algorithm_setup(field):
# units per population in generation # units per population in generation
best_outputs = [] best_outputs = []
num_generations = 10 num_generations = 100
num_parents = 4 num_parents = 4
# iterative var # iterative var
@ -65,14 +65,13 @@ def genetic_algorithm_setup(field):
# TODO METODA WYBORU OSOBNIKA - RANKING # TODO METODA WYBORU OSOBNIKA - RANKING
# Selecting the best parents in the population for mating. # Selecting the best parents in the population for mating.
print(best)
parents = [population_text[i[0]] for i in best] parents = [population_text[i[0]] for i in best]
parents_copy = copy.deepcopy(parents) parents_copy = copy.deepcopy(parents)
print("Parents") print("Parents")
# for i in range(0, len(parents)): for i in range(0, len(parents)):
# print('\n'.join([''.join(['{:4}'.format(item) for item in row]) print('\n'.join([''.join(['{:4}'.format(item) for item in row])
# for row in parents[i]])) for row in parents[i]]))
# print("") print("")
# Generating next generation using crossover. # Generating next generation using crossover.
offspring_x = random.randint(1, D.GSIZE - 2) offspring_x = random.randint(1, D.GSIZE - 2)
@ -81,19 +80,19 @@ def genetic_algorithm_setup(field):
# TODO OPERATOR KRZYŻOWANIA # TODO OPERATOR KRZYŻOWANIA
offspring_crossover = crossover(parents) offspring_crossover = crossover(parents)
print("Crossover") print("Crossover")
# for i in range(0, len(offspring_crossover)): for i in range(0, len(offspring_crossover)):
# print('\n'.join([''.join(['{:4}'.format(item) for item in row]) print('\n'.join([''.join(['{:4}'.format(item) for item in row])
# for row in offspring_crossover[i]])) for row in offspring_crossover[i]]))
# print("") print("")
# TODO OPERATOR MUTACJI # TODO OPERATOR MUTACJI
offspring_mutation = mutation(population_units, offspring_crossover, population_size - num_parents, offspring_mutation = mutation(population_units, offspring_crossover, population_size - num_parents,
num_mutations=10) num_mutations=10)
print("Mutation") print("Mutation")
# for i in range(0, len(offspring_mutation)): for i in range(0, len(offspring_mutation)):
# print('\n'.join([''.join(['{:4}'.format(item) for item in row]) print('\n'.join([''.join(['{:4}'.format(item) for item in row])
# for row in offspring_mutation[i]])) for row in offspring_mutation[i]]))
# print("") print("")
population_text_copy = copy.deepcopy(population_text) population_text_copy = copy.deepcopy(population_text)
unused_indexes = [i for i in range(0, population_size) if i not in [j[0] for j in best]] unused_indexes = [i for i in range(0, population_size) if i not in [j[0] for j in best]]
@ -111,11 +110,11 @@ def genetic_algorithm_setup(field):
# TODO WARUNEK STOPU # TODO WARUNEK STOPU
stop = 0 stop = 0
if generation > 10: if generation > 10:
if best_outputs[-1] / best_outputs[-2] < 1.05: if best_outputs[-1] / best_outputs[-2] < 1.001:
stop += 1 stop += 1
if best_outputs[-1] / best_outputs[-3] < 1.05: if best_outputs[-1] / best_outputs[-3] < 1.001:
stop += 1 stop += 1
if best_outputs[-2] / best_outputs[-3] < 1.05: if best_outputs[-2] / best_outputs[-3] < 1.001:
stop += 1 stop += 1
# final Fitness # final Fitness