def mating(self, Populations, pop_name):
     for location in parameters["population_locations"][0]:
         group = dose.filter_location(location,
                                      Populations[pop_name].agents)
         for x in range(len(group) // 2):
             parents = []
             for i in range(2):
                 parents.append(random.choice(Populations[pop_name].agents))
                 while parents[i] not in group:
                     parents[i] = random.choice(
                         Populations[pop_name].agents)
                 Populations[pop_name].agents.remove(parents[i])
             crossover_pt = random.randint(
                 0, len(parents[0].genome[0].sequence))
             (new_chromo1,
              new_chromo2) = dose.genetic.crossover(parents[0].genome[0],
                                                    parents[1].genome[0],
                                                    crossover_pt)
             children = [
                 dose.genetic.Organism([new_chromo1],
                                       parameters["mutation_type"],
                                       parameters["additional_mutation"]),
                 dose.genetic.Organism([new_chromo2],
                                       parameters["mutation_type"],
                                       parameters["additional_mutation"])
             ]
             for child in children:
                 child.status['parents'] = [
                     parents[0].status['identity'],
                     parents[1].status['identity']
                 ]
                 child.status['location'] = location
                 child.generate_name()
                 child.status['deme'] = pop_name
                 Populations[pop_name].agents.append(child)
 def mating(self, Populations, pop_name): 
     for location in parameters["population_locations"][0]:
         group = dose.filter_location(location, Populations[pop_name].agents)
         for x in range(len(group)//2):
             parents = []
             for i in range(2):
                 parents.append(random.choice(Populations[pop_name].agents))
                 while parents[i] not in group:
                     parents[i] = random.choice(Populations[pop_name].agents)
                 Populations[pop_name].agents.remove(parents[i])
             crossover_pt = random.randint(0, len(parents[0].genome[0].sequence))
             (new_chromo1, new_chromo2) = dose.genetic.crossover(parents[0].genome[0], 
                                                            parents[1].genome[0], 
                                                            crossover_pt)
             children = [dose.genetic.Organism([new_chromo1],
                                          parameters["mutation_type"],
                                          parameters["additional_mutation"]),
                         dose.genetic.Organism([new_chromo2],
                                          parameters["mutation_type"],
                                          parameters["additional_mutation"])]
             for child in children:
                 child.status['parents'] = [parents[0].status['identity'], 
                                            parents[1].status['identity']]
                 child.status['location'] = location
                 child.generate_name()
                 child.status['deme'] = pop_name
                 Populations[pop_name].agents.append(child)
 def mating(self, Populations, pop_name): 
     for location in parameters["population_locations"][0]:
         group = dose.filter_location(location, Populations[pop_name].agents)
         for x in range(parameters["eco_cell_capacity"] - len(group)):
             parents = []
             alpha_organism = group[0]
             for organism in group:
                 if abs(parameters["goal"] - organism.status['fitness']) < \
                     abs(parameters["goal"] - alpha_organism.status['fitness']):
                     alpha_organism = organism
             parents.append(alpha_organism)
             parents.append(random.choice(group))
             crossover_pt = random.randint(0, len(parents[0].genome[0].sequence))
             (new_chromo1, new_chromo2) = dose.genetic.crossover(parents[0].genome[0], 
                                                            parents[1].genome[0], 
                                                            crossover_pt)
             child = dose.genetic.Organism([new_chromo1],
                                      parameters["mutation_type"],
                                      parameters["additional_mutation"])
             child.status['parents'] = [parents[0].status['identity'],
                                        parents[1].status['identity']]
             child.status['location'] = location
             child.generate_name()
             child.status['deme'] = pop_name
             Populations[pop_name].agents.append(child)
Example #4
0
 def mating(self, Populations, pop_name):
     for location in parameters["population_locations"][0]:
         group = dose.filter_location(location,
                                      Populations[pop_name].agents)
         for x in range(parameters["eco_cell_capacity"] - len(group)):
             parents = []
             alpha_organism = group[0]
             for organism in group:
                 if abs(parameters["goal"] - organism.status['fitness']) < \
                     abs(parameters["goal"] - alpha_organism.status['fitness']):
                     alpha_organism = organism
             parents.append(alpha_organism)
             parents.append(random.choice(group))
             crossover_pt = random.randint(
                 0, len(parents[0].genome[0].sequence))
             (new_chromo1,
              new_chromo2) = dose.genetic.crossover(parents[0].genome[0],
                                                    parents[1].genome[0],
                                                    crossover_pt)
             child = dose.genetic.Organism(
                 [new_chromo1], parameters["mutation_type"],
                 parameters["additional_mutation"])
             child.status['parents'] = [
                 parents[0].status['identity'],
                 parents[1].status['identity']
             ]
             child.status['location'] = location
             child.generate_name()
             child.status['deme'] = pop_name
             Populations[pop_name].agents.append(child)
 def postpopulation_control(self, Populations, pop_name):
     for location in parameters["population_locations"][0]:
         group = dose.filter_location(location, Populations[pop_name].agents)
         average_fitness = sum([organism.status["fitness"] for organism in group])/len(group)
         if average_fitness != parameters["goal"]:
             omega_organism_fitness = 0
             for organism in group:
                 if abs(parameters["goal"] - organism.status['fitness']) > \
                     abs(parameters["goal"] - omega_organism_fitness):
                     omega_organism_fitness = int(organism.status['fitness'])
             for organism in group:
                 if organism.status['fitness'] in range(omega_organism_fitness - 2,
                                                         omega_organism_fitness + 2):
                     Populations[pop_name].agents.remove(organism)
 def organism_movement(self, Populations, pop_name, World):
     for location in parameters["population_locations"][0]:
         group = dose.filter_location(location, Populations[pop_name].agents)
         adj_cells = dose.simulation_calls.adjacent_cells(parameters, location)
         for i in range(int(round((len(group) * 0.1)))):
             (x,y,z) = dose.simulation_calls.coordinates(location)
             World.ecosystem[x][y][z]['organisms'] -= 1
             immigrant = random.choice(Populations[pop_name].agents)
             while immigrant not in group:
                 immigrant = random.choice(Populations[pop_name].agents)
             new_location = random.choice(adj_cells)
             immigrant.status['location'] = new_location
             (x,y,z) = dose.simulation_calls.coordinates(new_location)
             World.ecosystem[x][y][z]['organisms'] += 1
Example #7
0
 def organism_movement(self, Populations, pop_name, World):
     for location in parameters["population_locations"][0]:
         group = dose.filter_location(location,
                                      Populations[pop_name].agents)
         adj_cells = dose.simulation_calls.adjacent_cells(
             parameters, location)
         for i in range(int(round((len(group) * 0.1)))):
             (x, y, z) = dose.simulation_calls.coordinates(location)
             World.ecosystem[x][y][z]['organisms'] -= 1
             immigrant = random.choice(Populations[pop_name].agents)
             while immigrant not in group:
                 immigrant = random.choice(Populations[pop_name].agents)
             new_location = random.choice(adj_cells)
             immigrant.status['location'] = new_location
             (x, y, z) = dose.simulation_calls.coordinates(new_location)
             World.ecosystem[x][y][z]['organisms'] += 1
 def prepopulation_control(self, Populations, pop_name):
     for location in parameters["population_locations"][0]:
         group = dose.filter_location(location, Populations[pop_name].agents)
         average_fitness = sum([organism.status["fitness"] for organism in group])/len(group)
         if average_fitness != parameters["goal"]:
             alpha_organism_fitness = 0
             for organism in group:
                 if abs(parameters["goal"] - organism.status['fitness']) < \
                     abs(parameters["goal"] - alpha_organism_fitness):
                     alpha_organism_fitness = int(organism.status['fitness'])
             for organism in group:
                 if organism.status['fitness'] not in range(alpha_organism_fitness - 2,
                                                             alpha_organism_fitness + 2):
                     Populations[pop_name].agents.remove(organism)
         else:
             if organism.status['fitness'] != parameters["goal"]:
                 Populations[pop_name].agents.remove(organism)