ga_simple.py
def selection_and_reproduction(population):
    """
        Punctuate all the elements of the population and keep the best ones kept
         within 'selected'.
        Then mix the genetic material of the chosen ones to create new individuals
        and fill the population (also keeping a copy of the selected individuals
        without modifying).

        Finally, it mutates the individuals.

    """
    Scored = [ (calculateFitness(i), i) for i in population] # Calculates the fitness of each individual, and stores it in ordered pairs of the form (5, [1,2,1,1,4,1,8,9,4,1])
    Scored = [i[1] for i in sorted(Scored)] # Order the ordered pairs and stay only with the array of values
    population = Scored



    selected =  Scored[(len(Scored)-pressure):] # This line select the 'n' individuals at the end, where we are given by 'pressure'



    # The genetic material is mixed to create new individuals
    for i in range(len(population)-pressure):
        cut_point = random.randint(1,gen_size-1) # A point is chosen to make the exchange
        parents = random.sample(selected, 2) # Two parents are chosen

        population[i][:cut_point] = parents[0][:cut_point] # The genetic material of the parents is mixed in each new individual
        population[i][cut_point:] = parents[1][cut_point:]

    return population

        Punctuate all the elements of the population and keep the best ones kept
         within 'selected'.
        Then mix the genetic material of the chosen ones to create new individuals
        and fill the population (also keeping a copy of the selected individuals
        without modifying).

        Finally, it mutates the individuals.

    
Punctuate all the elements of the population and keep the best ones kept
within 'selected'.
Then mix the genetic material of the chosen ones to create new individuals
and fill the population (also keeping a copy of the selected individuals
without modifying).

Finally, it mutates the individuals.
Punctuate all the elements of the population and keep the best ones kept within ' selected ' . Then mix the genetic material of the chosen ones to create new individuals and fill the population ( also keeping a copy of the selected individuals without modifying ) . Finally it mutates the individuals .
def selection_and_reproduction(population):
    Scored = [ (calculateFitness(i), i) for i in population] 
    Scored = [i[1] for i in sorted(Scored)] 
    population = Scored
    selected =  Scored[(len(Scored)-pressure):] 
    for i in range(len(population)-pressure):
        cut_point = random.randint(1,gen_size-1) 
        parents = random.sample(selected, 2) 
        population[i][:cut_point] = parents[0][:cut_point] 
        population[i][cut_point:] = parents[1][cut_point:]
    return population
def selection_and_reproduction ( population ) : Scored = [ ( calculateFitness ( i ) , i ) for i in population ] Scored = [ i [ 1 ] for i in sorted ( Scored ) ] population = Scored selected = Scored [ ( len ( Scored ) - pressure ) : ] for i in range ( len ( population ) - pressure ) : cut_point = random . randint ( 1 , gen_size - 1 ) parents = random . sample ( selected , 2 ) population [ i ] [ : cut_point ] = parents [ 0 ] [ : cut_point ] population [ i ] [ cut_point : ] = parents [ 1 ] [ cut_point : ] return population
Punctuate all the elements of the population and keep the best ones kept
within 'selected'.
Punctuate all the elements of the population and keep the best ones kept within ' selected ' .
"""
        Punctuate all the elements of the population and keep the best ones kept
         within 'selected'.
        Then mix the genetic material of the chosen ones to create new individuals
        and fill the population (also keeping a copy of the selected individuals
        without modifying).

        Finally, it mutates the individuals.

    """ # Calculates the fitness of each individual, and stores it in ordered pairs of the form (5, [1,2,1,1,4,1,8,9,4,1]) # Order the ordered pairs and stay only with the array of values # This line select the 'n' individuals at the end, where we are given by 'pressure' # The genetic material is mixed to create new individuals # A point is chosen to make the exchange # Two parents are chosen # The genetic material of the parents is mixed in each new individual
population