Updated repr/str
This commit is contained in:
@ -55,20 +55,10 @@ class Chromosome:
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
"""Format the repr() output for the chromosome"""
|
||||
output_str = ''
|
||||
for gene in self.gene_list:
|
||||
output_str += gene.__repr__()
|
||||
"""Create a backend string of the chromosome. Ex '1, 2, 3'."""
|
||||
return ', '.join(repr(gene) for gene in self.gene_list)
|
||||
|
||||
return output_str
|
||||
|
||||
def __str__(self):
|
||||
"""Create a string of the chromosome. Ex chromsome = 1,2,3"""
|
||||
output_str = ''
|
||||
for gene in self.gene_list:
|
||||
if gene == self.gene_list[0]:
|
||||
output_str += str(gene.get_value())
|
||||
else:
|
||||
output_str += ',' + str(gene.get_value())
|
||||
|
||||
return output_str
|
||||
"""Create a printable string of the chromosome. Ex '[1][2][3]'."""
|
||||
return ''.join(str(gene) for gene in self.gene_list)
|
||||
|
||||
@ -29,5 +29,10 @@ class Gene:
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
"""Format the repr() output value"""
|
||||
return f'[{self.value}]'
|
||||
"""Create a backend string of the chromosome. Ex '1'."""
|
||||
return str(self.value)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
"""Create a printable string of the chromosome. Ex '[1]'."""
|
||||
return f'[{str(self.value)}]'
|
||||
|
||||
@ -148,11 +148,11 @@ class Population:
|
||||
"""Sets the fitness value of the population"""
|
||||
self.fitness = fitness
|
||||
|
||||
|
||||
'''
|
||||
def __repr__(self):
|
||||
"""Returns a string representation of the entire population"""
|
||||
"""Returns a backend string representation of the entire population"""
|
||||
pass
|
||||
|
||||
'''
|
||||
|
||||
def print_all(self):
|
||||
"""Prints information about the population in the following format:
|
||||
|
||||
Reference in New Issue
Block a user