Esempio n. 1
0
# Create First Population
population = Population(POPULATION_SIZE)
genetic_algorithm = GA(MUTATION_RATE, CROSSOVER_RATE, OPENAI_EVALUATIONS)

# run_best('1575216646.5449824np_294')

populate_fitness(population.get())

best_individue = None
best_individues = []
mean = []
for i in range(1, GENERATIONS):
    best_individue = get_best_individue(population.get())
    best_individues.append(best_individue)
    new_poulation = genetic_algorithm.generation(population.get())
    new_poulation.get()[0] = best_individue
    population = new_poulation
    populate_fitness(population.get())
    print(i, best_individue.fitness)
    if best_individue.fitness == OPENAI_EVALUATIONS:
        np.save('best/' + str(time.time()) + 'np_' + '.npy',
                best_individue.weights)
        genetic_algorithm.openAI.run_result(best_individue.weights)
        break

# start = time.time()
# genetic_algorithm.openAI.run_result(best_individue.weights)
# end = time.time()
# print(end - start, ' seconds')