def breed(self, generation): splicer = GeneSplicer() children = [] for count in range(0, int(self.expected_children)): if count == 0: mum = copy.deepcopy(self.member_organisms[count]) else: mum = copy.deepcopy(self.member_organisms[random.randint(0, len(self.member_organisms) - 1)]) if random.random() < MATE_PROBABILITY: dad = copy.deepcopy(self.member_organisms[random.randint(0, len(self.member_organisms) - 1)]) junior = splicer.mate(mum, dad) junior["reproduction"] = "Mate" else: junior = mum splicer.mutate(junior) junior["reproduction"] = "Mutate" junior["parent"] = mum["id"] junior["id"] = ControlPanel.next_organism_number() junior["generation"] = generation junior["species"] = self.id children.append(junior) mutants = [] for child in children: if splicer.compatibility_scan(self.representative, child) < COMPATIBILITY_THRESHOLD: self.member_organisms.append(child) else: mutants.append(child) return mutants
def test_compatibility_of_different_genomes(self): genome1 = self.read_genome('Experiments/CryogenicStorage/xor_genome.json') genome2 = self.read_genome('Experiments/CryogenicStorage/xor_genome.json') del genome1["synapses"][2] del genome2["synapses"][6:9] genome2["synapses"][3]["weight"] = 1.5 splicer = GeneSplicer() self.assertEqual(splicer.compatibility_scan(genome1, genome2), 0.2664)
def invaded_by(self, mutants): lonesome_george = True for mutant in mutants: for species in self.species: splicer = GeneSplicer() if lonesome_george and splicer.compatibility_scan(species.representative, mutant) < COMPATIBILITY_THRESHOLD: species.member_organisms.append(mutant) lonesome_george = False if lonesome_george: self.species.append(Species(mutant))
def speciate(self): splicer = GeneSplicer() for organism in self.organisms: compatible = False count = 0 while not compatible and count < len(self.species): species = self.species[count] if splicer.compatibility_scan(species.representative, organism) < COMPATIBILITY_THRESHOLD: compatible = True species.assimilate(organism) count += 1 if not compatible: self.species.append(Species(organism))
def breed(self, generation): splicer = GeneSplicer() children = [] for count in range(0, int(self.expected_children)): if count == 0: mum = copy.deepcopy(self.member_organisms[count]) else: mum = copy.deepcopy(self.member_organisms[random.randint( 0, len(self.member_organisms) - 1)]) if random.random() < MATE_PROBABILITY: dad = copy.deepcopy(self.member_organisms[random.randint( 0, len(self.member_organisms) - 1)]) junior = splicer.mate(mum, dad) junior["reproduction"] = "Mate" else: junior = mum splicer.mutate(junior) junior["reproduction"] = "Mutate" junior["parent"] = mum["id"] junior["id"] = ControlPanel.next_organism_number() junior["generation"] = generation junior["species"] = self.id children.append(junior) mutants = [] for child in children: if splicer.compatibility_scan(self.representative, child) < COMPATIBILITY_THRESHOLD: self.member_organisms.append(child) else: mutants.append(child) return mutants
def test_compatibility_of_identical_genomes(self): genome = self.read_genome('Experiments/CryogenicStorage/xor_genome.json') splicer = GeneSplicer() self.assertEqual(splicer.compatibility_scan(genome, genome), 0)