pop_size = int(arguments['<pop_size>']) solutions = generate_population(N, pop_size) Pop = Population(N, solutions, XOVER_PROB, MUTATION_PROB) optimal_solutions = [] iterations = 0 # Genetic algorithm loop starts here while iterations < MAX_ITER: print_iterations = 'Iteration=%i' % iterations Printer(print_iterations) # create the next generation next_generation = Pop.build_new_population() # modify the current population to the new one Pop.regenerate_population(next_generation) # increment generations iterations += 1 outfile_stats = 'output/N%iP%i_%s.txt' % (N, len(solutions), timestamp) outfile_sols = 'output/solutions_N%iP%i_%s.txt' % (N, len(solutions), timestamp) Pop.print_stats() if Pop.optimal_solutions: print 'Found %i solutions' % len(Pop.optimal_solutions) for s in Pop.optimal_solutions: print s Pop.export_stats(outfile_stats) Pop.export_optimal_solutions(outfile_sols)