Last active
July 21, 2018 12:16
-
-
Save rish-16/193afd54c5ab315c9782a60e0e9378bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Crossing over the Primary Agents | |
def crossover_pagent(agents): | |
offspring = [] | |
for _ in range(int((self.population - len(agents)) / 2)): | |
parent1 = random.choice(agents) | |
parent2 = random.choice(agents) | |
child1 = PAgent(self.in_str_len) | |
child2 = PAgent(self.in_str_len) | |
split = random.randint(0, self.in_str_len) | |
child1.string = parent1.string[0:split] + parent2.string[split:self.in_str_len] | |
child2.string = parent2.string[0:split] + parent1.string[split:self.in_str_len] | |
offspring.append(child1) | |
offspring.append(child2) | |
agents.extend(offspring) | |
return agents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Crossing over the Secondary Agents | |
def crossover_sagent(agents): | |
offspring = [] | |
for _ in range(int((agent_population - len(agents)) / 2)): | |
parent1 = random.choice(agents) | |
parent2 = random.choice(agents) | |
child1 = SAgent(in_str) | |
child2 = SAgent(in_str) | |
child1.population = int((0.2 * parent1.population) + (0.4 * parent2.population)) | |
child1.population = int((0.2 * parent2.population) + (0.4 * parent1.population)) | |
child1.generations = int((0.2 * parent1.population) + (0.4 * parent2.population)) | |
child2.generations = int((0.2 * parent2.population) + (0.4 * parent1.population)) | |
offspring.append(child1) | |
offspring.append(child2) | |
agents.extend(offspring) | |
return agents |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment