Fixed method names and added some crossover methods and tests for floats

This commit is contained in:
SimpleArt
2020-10-13 21:07:05 -04:00
parent b966b22b04
commit 0090db9dce
7 changed files with 89 additions and 36 deletions

View File

@ -7,8 +7,6 @@ class Chromosome:
self.gene_list = gene_list
self.fitness = None
# If the chromosome has been selected then the flag would switch to true
self.selected = False
def size(self):
@ -16,10 +14,10 @@ class Chromosome:
return len(self.gene_list)
def add_gene(self, gene, index = -1):
def add_gene(self, gene, index = None):
"""Add a gene to the chromosome at the specified index, defaulted to end of the chromosome"""
if index == -1:
index = len(self.gene_list)
if index is None:
index = self.size()
self.gene_list.insert(index, gene)
@ -30,7 +28,7 @@ class Chromosome:
def get_gene(self, index):
"""Returns the gene at the given index"""
return gene_list[index]
return self.gene_list[index]
def get_gene_list(self):