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