Skip to content

Commit

Permalink
Status dictionary of Organism is now implemented inside the initializ…
Browse files Browse the repository at this point in the history
…ation of Organism to prevent referencing to the same dictionary
  • Loading branch information
Clarence Castillo committed Oct 9, 2013
1 parent 204f514 commit b5b500c
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions dose/genetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,7 @@ class as some functions need to be over-ridden in the inherited class for
@since: version 0.4
"""
status = {'alive': True, # is the organism alive?
'vitality': 100.0, # % of vitality
'age': 0.0, # age of the organism
'lifespan': 100.0, # maximum lifespan
'fitness': 100.0, # % of fitness
'death': None}


genome = []

def __init__(self, genome='default',
Expand Down Expand Up @@ -236,6 +230,12 @@ def __init__(self, genome='default',
@since: version 0.4
"""
self.status = {'alive': True, # is the organism alive?
'vitality': 100.0, # % of vitality
'age': 0.0, # age of the organism
'lifespan': 100.0, # maximum lifespan
'fitness': 100.0, # % of fitness
'death': None}
if genome == 'default':
self.genome = [Chromosome()]
elif genome == 'dummy':
Expand All @@ -245,7 +245,7 @@ def __init__(self, genome='default',
self.mutation_type = mutation_type
self.additional_mutation_rate = additional_mutation_rate
self.gender = gender

def generate_name(self):
name = ''.join([random.choice(('1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E',
Expand Down Expand Up @@ -372,10 +372,6 @@ def clone(self):
@since: version 0.4
"""
org = deepcopy(self)
temp_status = {}
for key in self.status.keys():
temp_status[key] = self.status[key]
org.status = temp_status
return org

class Population(object):
Expand Down

0 comments on commit b5b500c

Please sign in to comment.