Example #1
0
 def selection_Parent(self, pop):
     """
         Tournament selection :
         select a parent between K=tournament_Size arrays 
         and choose the best one
         """
     tournament = c.Population(self.configuration_Manager,
                               self.tournament_Size, False)
     for i in range(0, self.tournament_Size):
         random_array_index = random.randint(0, pop.population_Size() - 1)
         array = pop.get_Array(random_array_index)
         tournament.save_Array(i, array)
     fittest, pos = tournament.get_Fittest()
     return fittest
    def __init__(self, parametres):
        self.nombre_agents_par_population = parametres[
            "nombre_agents_par_population"]
        self.taille_agent = parametres["taille_agent"]

        number_of_agent_to_select = 2

        self.string_to_get = self.init_string_to_get(
            self.nombre_agents_par_population)
        print("string to get: " + self.string_to_get)

        self.population = classes.Population(self.nombre_agents_par_population,
                                             self.taille_agent)
        print("Population initiale")
        print(self.population)
Example #3
0
def Init_Pop(cfg_file, configuration_Manager, source_declination,
             source_hour_angle, num_subarrays, list_num_pads_subarrays,
             num_arrays, list_objective_constraints, list_constraints_weights,
             list_subarrays_weights):
    """
    Initialize a population with :
    - cfg_file : a file containing the pads to consider
    - configuration_Manager : a class wich allows to configurate the population
    - num_subarrays : a number of subarrays in each array
    - list_num_pads_subarrays : a list of the number of pads per subarrays
    - num_arrays : a number of arrays for the population
    """
    cfg = pd.read_csv(cfg_file,
                      comment='#',
                      names=['E', 'N', 'U', 'diam', 'pad'],
                      sep='\s+')

    cm = configuration_Manager

    xx, yy, zz = cfg[['E', 'N', 'U']].values.transpose()
    diam = cfg[['diam']].values.transpose()
    name = cfg[['pad']].values.transpose()
    s = 0
    for i in range(0, num_subarrays):
        s += list_num_pads_subarrays[i]

    cm.clear()
    for i in range(0, len(xx)):
        pad = c.Pad(xx[i], yy[i], zz[i], diam[0][i], name[0][i])
        cm.add_Pad(pad)

    cm.set_Source_Declination(source_declination)
    cm.set_Source_Hour_Angle(source_hour_angle)

    cm.set_Number_Subarrays(num_subarrays)
    cm.set_Number_Pads_Per_Subarray(list_num_pads_subarrays)

    cm.set_Objective_Constraints(list_objective_constraints)
    cm.set_Constraints_Weights(list_constraints_weights)
    cm.set_Subarrays_Weights(list_subarrays_weights)

    pop = c.Population(cm, num_arrays, True)

    return pop
Example #4
0
    def evolve_Population(self, pop):
        """
       Make a new population from the actual population doing :
       - elitism : choice of arrays to keep
       - selection_parent : choice of parents to cross in order to get knew arrays
       - crossover : generate new arrays
       - mutation : introduce mutation in the new population
        """
        new_pop = c.Population(self.configuration_Manager,
                               pop.population_Size(), False)
        self.elitism(pop, new_pop)

        for i in range(self.elitism_Num, new_pop.population_Size()):
            parent_1 = self.selection_Parent(pop)
            parent_2 = self.selection_Parent(pop)
            child = self.crossover(parent_1, parent_2)
            new_pop.save_Array(i, child)
        for i in range(self.elitism_Num, new_pop.population_Size()):
            self.mutation(new_pop.get_Array(i))

        return new_pop
 def reinit(self):
     self.population = classes.Population(self.nombre_agents_par_population,
                                          self.taille_agent)