-
Notifications
You must be signed in to change notification settings - Fork 56
/
allgenomes.py
60 lines (43 loc) · 1.51 KB
/
allgenomes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
""" Class that keeps track of all genomes trained so far, and their scores.
Among other things, ensures that genomes are unique.
"""
import random
import logging
from genome import Genome
class AllGenomes():
"""Store all genomes
"""
def __init__(self, firstgenome):
"""Initialize
"""
self.population = []
self.population.append(firstgenome)
def add_genome(self, genome):
"""Add the genome to our population.
"""
for i in range(0,len(self.population)):
if (genome.hash == self.population[i].hash):
logging.info("add_genome() ERROR: hash clash - duplicate genome")
return False
self.population.append(genome)
return True
def set_accuracy(self, genome):
"""Add the genome to our population.
"""
for i in range(0,len(self.population)):
if (genome.hash == self.population[i].hash):
self.population[i].accuracy = genome.accuracy
return
logging.info("set_accuracy() ERROR: Genome not found")
def is_duplicate(self, genome):
"""Add the genome to our population.
"""
for i in range(0,len(self.population)):
if (genome.hash == self.population[i].hash):
return True
return False
def print_all_genomes(self):
"""Print out a genome.
"""
for genome in self.population:
genome.print_genome_ma()