コード例 #1
0
    def act(self):
        # Process the information if the agent has sense nearby agents
        if self.agents_found:

            # Combine the original individual and individuals found by interacting with nearby agents to form
            # a population
            individuals = self.individual + self.nearby_agents

            # Find out parents from the population
            parents = selection(individuals)

            # Crossover parents and add to the new population.
            cross_pop = crossover(parents)

            # Mutate the new population.
            new_pop = mutation(cross_pop)

            # Evaluate the fitness of the new population.
            new_pop = evaluate_fitness(new_pop)

            # Replace the old population with the new population.
            individuals = replacement(new_pop, individuals)

            # Generate statistics for run so far
            get_stats(individuals)

            # Sort the individuals list
            individuals.sort(reverse=True)

            # Get the highest performing individual from the sorted population
            self.new_individual = individuals[0]
コード例 #2
0
def step(individuals):
    """
    Runs a single generation of the evolutionary algorithm process:
        Selection
        Variation
        Evaluation
        Replacement
    
    :param individuals: The current generation, upon which a single
    evolutionary generation will be imposed.
    :return: The next generation of the population.
    """

    # Select parents from the original population.
    parents = selection(individuals)

    # Crossover parents and add to the new population.
    cross_pop = crossover(parents)

    # Mutate the new population.
    new_pop = mutation(cross_pop)

    # Evaluate the fitness of the new population.
    new_pop = evaluate_fitness(new_pop)

    # Replace the old population with the new population.
    individuals = replacement(new_pop, individuals)

    # Generate statistics for run so far
    params['STATISTICS'].get_stats(individuals)

    return individuals
コード例 #3
0
ファイル: agent.py プロジェクト: jmmcd/PonyGE2
    def act(self):
        # Process the information if the agent has sense nearby agents
        if self.agents_found:

            # Combine the original individual and individuals found by interacting with nearby agents to form 
            # a population
            individuals = self.individual + self.nearby_agents

            # Find out parents from the population
            parents = selection(individuals)

            # Crossover parents and add to the new population.
            cross_pop = crossover(parents)

            # Mutate the new population.
            new_pop = mutation(cross_pop)

            # Evaluate the fitness of the new population.
            new_pop = evaluate_fitness(new_pop)

            # Replace the old population with the new population.
            individuals = replacement(new_pop, individuals)

            # Generate statistics for run so far
            get_stats(individuals)
            
            # Sort the individuals list 
            individuals.sort(reverse=True)

            # Get the higest performing individual from the sorted population 
            self.new_individual = individuals[0]
コード例 #4
0
def weips_step(individuals, weight_matrix):
    """
    Runs a single generation of the evolutionary algorithm process:
        Selection
        Variation
        Evaluation
        Replacement

    :param individuals: The current generation, upon which a single
    :param weight_matrix: The matrix of weights used by the selection method.
    :return: The next generation of the population.
    """

    # Size of the population
    pop_size = params['GENERATION_SIZE']

    # Select parents from the original population.
    parents = weips_selection(individuals, weight_matrix, pop_size)

    # Crossover parents and add to the new population.
    cross_pop = crossover(parents)

    # Mutate the new population.
    new_pop = mutation(cross_pop)

    # Evaluate the fitness of the new population (Q_t).
    new_pop = evaluate_fitness(new_pop)

    # Replace the old population with the new population.
    individuals = weips_replacement(new_pop, individuals, weight_matrix)

    # Generate statistics for run so far
    params['STATISTICS'].get_stats(individuals)

    return individuals
コード例 #5
0
ファイル: step.py プロジェクト: jmmcd/PonyGE2
def step(individuals):
    """
    Runs a single generation of the evolutionary algorithm process:
        Selection
        Variation
        Evaluation
        Replacement
    
    :param individuals: The current generation, upon which a single
    evolutionary generation will be imposed.
    :return: The next generation of the population.
    """

    # Select parents from the original population.
    parents = selection(individuals)

    # Crossover parents and add to the new population.
    cross_pop = crossover(parents)

    # Mutate the new population.
    new_pop = mutation(cross_pop)

    # Evaluate the fitness of the new population.
    new_pop = evaluate_fitness(new_pop)

    # Replace the old population with the new population.
    individuals = replacement(new_pop, individuals)

    # Generate statistics for run so far
    get_stats(individuals)
    
    return individuals
コード例 #6
0
def step_reload(individuals,initial_population):
    individuals.sort(reverse=True)
    print(str(individuals[0].fitness) + " -v- " + str(params['RESET_FITNESS']))
    if individuals[0].fitness > params['RESET_FITNESS']:
        if params['DYNAMIC_ENVIRONMENT_RELOAD_PERCENTAGE']:
            print("RESETTING PERCENTAGE OF POP")
            new_inds = int(len(initial_population)*params['DYNAMIC_ENVIRONMENT_RELOAD_PERCENTAGE_VALUE'])
            #sample from initial pop randomly
            reload_pop_a = deepcopy(random.sample(initial_population, new_inds))
            reload_pop_b = deepcopy(individuals[:-new_inds])
            reload_pop = reload_pop_a + reload_pop_b
            reload_pop = evaluation(reload_pop)
            reload_pop.sort(reverse=True)
            params['RESET_FITNESS'] = reload_pop[0].fitness
            print("Reload Threshold now: " + str(params['RESET_FITNESS']))
            params['RELOAD_PERFORMED'] = 1
            rep_inds = deepcopy(reload_pop)
            # If we want to use replacement :D
            # individuals = replacement(initial_population, individuals)
        else:
            print("RESETTING POP")
            initial_population = evaluation(initial_population)
            initial_population.sort(reverse=True)
            params['RESET_FITNESS'] = initial_population[0].fitness
            print("Reload Threshold now: "+ str(params['RESET_FITNESS']))
            params['RELOAD_PERFORMED'] = 1
            rep_inds = deepcopy(initial_population)
            #If we want to use replacement :D
            #individuals = replacement(initial_population, individuals)
    else:
        # Select parents
        parents = selection(individuals)

        # Crossover parents and add to the new population
        cross_pop = crossover(parents)

        # Mutate the new population
        new_pop = mutation(cross_pop)

        # Evaluate the fitness of the new population
        new_pop = evaluation(new_pop)

        # Replace the sorted individuals with the new populations
        rep_inds = replacement(new_pop, individuals)

        params['RELOAD_PERFORMED'] = 0

    return rep_inds
コード例 #7
0
def step(individuals):
    """Return individuals and best ever individual from a step of
    the EA iteration"""

    if params['BASELINE_STEPS']:
        individuals = evaluation(individuals)
    else:
        # Select parents
        parents = selection(individuals)

        # Crossover parents and add to the new population
        cross_pop = crossover(parents)

        # Mutate the new population
        new_pop = mutation(cross_pop)

        # Evaluate the fitness of the new population
        new_pop = evaluation(new_pop)

        # Replace the sorted individuals with the new populations
        individuals = replacement(new_pop, individuals)

    return individuals