Ejemplo n.º 1
0
    def step(self):
        print("nindividuals: " + str(len(self.individuals)) + "; fitnesses:")
        print(str(list(map(lambda x: x.fitness, self.individuals))))

        self.individuals, self.best_ever = ponyge.step(
            self.individuals, self.grammar, self.replacement,
            self.selection, ponyge.FITNESS_FUNCTION, self.best_ever)
        ponyge.print_stats(self.generation, self.individuals)
        # write to stderr. this allows us to redirect entire run to stdout
        # but still know which generation we're on, so can rename screenshots
        # correctly
        sys.stderr.write("Gen: " + str(self.generation) + "\n")
        self.generation += 1
Ejemplo n.º 2
0
    def step(self):
        print("nindividuals: " + str(len(self.individuals)) + "; fitnesses:")
        print(str(list(map(lambda x: x.fitness, self.individuals))))

        self.individuals, self.best_ever = ponyge.step(
            self.individuals, self.grammar, self.replacement, self.selection,
            ponyge.FITNESS_FUNCTION, self.best_ever)
        ponyge.print_stats(self.generation, self.individuals)
        # write to stderr. this allows us to redirect entire run to stdout
        # but still know which generation we're on, so can rename screenshots
        # correctly
        sys.stderr.write("Gen: " + str(self.generation) + "\n")
        self.generation += 1
Ejemplo n.º 3
0
 def __init__(self, grammar_file):
     self.generation = 0
     ponyge.GRAMMAR_FILE = grammar_file
     ponyge.POPULATION_SIZE = 9
     ponyge.GENERATION_SIZE = 9
     ponyge.ELITE_SIZE = 0
     ponyge.MUTATION_PROBABILITY = 0.01
     ponyge.CROSSOVER_PROBABILITY = 1.0 - ponyge.MUTATION_PROBABILITY
     self.grammar = ponyge.Grammar(ponyge.GRAMMAR_FILE)
     self.individuals = ponyge.initialise_population(ponyge.POPULATION_SIZE)
     self.replacement = ponyge.generational_replacement
     self.selection = lambda x: ponyge.tournament_selection(x, 6)
     ponyge.FITNESS_FUNCTION = DummyFitness()
     ponyge.evaluate_fitness(self.individuals, self.grammar, ponyge.FITNESS_FUNCTION)
     self.best_ever = min(self.individuals)
     self.individuals.sort()
     ponyge.print_stats(1, self.individuals)
Ejemplo n.º 4
0
 def __init__(self, grammar_file):
     self.generation = 0
     ponyge.GRAMMAR_FILE = grammar_file
     ponyge.POPULATION_SIZE = 9
     ponyge.GENERATION_SIZE = 9
     ponyge.ELITE_SIZE = 0
     ponyge.MUTATION_PROBABILITY = 0.01
     ponyge.CROSSOVER_PROBABILITY = 1.0 - ponyge.MUTATION_PROBABILITY
     self.grammar = ponyge.Grammar(ponyge.GRAMMAR_FILE)
     self.individuals = ponyge.initialise_population(ponyge.POPULATION_SIZE)
     self.replacement = ponyge.generational_replacement
     self.selection = lambda x: ponyge.tournament_selection(x, 6)
     ponyge.FITNESS_FUNCTION = DummyFitness()
     ponyge.evaluate_fitness(self.individuals, self.grammar,
                             ponyge.FITNESS_FUNCTION)
     self.best_ever = min(self.individuals)
     self.individuals.sort()
     ponyge.print_stats(1, self.individuals)