Skip to content

Commit

Permalink
Standarize code.
Browse files Browse the repository at this point in the history
  • Loading branch information
PytLab committed Oct 10, 2017
1 parent 67f34ba commit 3ace43d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions gaft/components/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __get__(self, instance, cls):
return self

def __call__(self, fitness):
if ((not self.instance._updated) # population not changed
if ((not self.instance.updated) # population not changed
and (self.result is not None) # result already cached
and (fitness == self.fitness)): # fitness not changed
# Return cached result directly.
Expand Down Expand Up @@ -46,7 +46,7 @@ def __get__(self, instance, owner):
def __set__(self, instance, value):
instance.__dict__[self.name] = value
# Update flag.
instance._updated = True
instance.update_flag()


class GAPopulation(object):
Expand Down Expand Up @@ -97,22 +97,22 @@ def __setitem__(this, key, value):
return
super(this.__class__, self).__setitem__(key, value)
# Update population flag.
self._updated = True
self.update_flag()

def append(this, item):
'''
Override append method of built-in list type.
'''
super(this.__class__, this).append(item)
# Update population flag.
self._updated = True
self.update_flag()

def extend(this, iterable_item):
if not iterable_item:
return
super(this.__class__, this).extend(iterable_item)
# Update population flag.
self._updated = True
self.update_flag()
# }}}

self._individuals = IndvList()
Expand Down Expand Up @@ -144,12 +144,19 @@ def init(self, indvs=None):

return self

def flag_update(self):
def update_flag(self):
'''
Interface for updating individual update flag to True.
'''
self._updated = True

@property
def updated(self):
'''
Query function for population updating flag.
'''
return self._updated

def new(self):
'''
Create a new emtpy population.
Expand Down

0 comments on commit 3ace43d

Please sign in to comment.