2""" @brief An Individual has a genome, several genes, a score and behaviours.
"""
4#============================================================================#
5# EVOLIFE http://evolife.telecom-paris.fr Jean-Louis Dessalles
20if __name__ ==
'__main__':
21 sys.path.append(
'../..')
22 from Evolife.Scenarii.MyScenario
import InstantiateScenario
23 InstantiateScenario(
'SexRatio')
26from random
import randint
33 """ class Individual: basic individual.
37 def __init__(self, Scenario, ID=None, Newborn = True):
41 AgeMax = self.
Scenario.Parameter(
'AgeMax', Default=100)
42 self.
age = randint(1,AgeMax)
47 self.
ID =
'A' + str(randint(0,9999))
53 """ Increments the individual's age
59 """ The victim suffers from a loss of life points
64 """ An individual is dead if it is too old or has lost all its 'LifePoints'
67 AgeMax = self.
Scenario.Parameter(
'AgeMax', Default=0)
68 if AgeMax
and (self.
age > AgeMax):
return True
72 """ Action to be performed when dying
76 def score(self, bonus=0, FlagSet=False):
77 """ Sets score or adds points to score, depending on FlagSet - Returns score value
79 if FlagSet: self.
__score = bonus
84 """ returns age and score
89 """ stores individual's signature in 'GroupExaminer'
91 GroupExaminer.store('Properties',self.
signature())
94 """ can be used to display individuals
104 return "ID: " + str(self.
ID) +
"\tage: " + str(self.
age) +
"\tscore: " \
105 +
"%.02f" % self.
score()
111 """ Individual + genome + phenome + social links
113 def __init__(self, Scenario, ID=None, Newborn=True, MaxFriends=0):
114 """ Merely calls parent classes' constructors
116 Individual.__init__(self, Scenario, ID=ID, Newborn=Newborn)
123 Follower.__init__(self, MaxFriends)
126 """ stores genome, phenome, social links and location into GroupExaminer
128 Individual.observation(self, GroupExaminer)
129 GroupExaminer.store('Genomes', Genome.signature(self))
130 GroupExaminer.store(
'DNA', list(self.get_DNA()), Numeric=
True)
131 GroupExaminer.store(
'Phenomes', Phenome.signature(self))
132 GroupExaminer.store(
'Network', (self.
ID, [T.ID
for T
in Follower.signature(self)]), Numeric=
False)
133 GroupExaminer.store(
'Field', (self.
ID, self.
location), Numeric=
False)
136 """ Action to be performed when dying
138 Follower.detach(self)
139 Individual.dies(self)
143 return Individual.__str__(self) +
"\tPhen: " + Phenome.__str__(self)
151if __name__ ==
"__main__":
153 print(Individual.__doc__ +
'\n\n')
157 raw_input(
'[Return]')
160__author__ =
'Dessalles'
Individual + genome + phenome + social links.
def dies(self)
Action to be performed when dying
def observation(self, GroupExaminer)
stores genome, phenome, social links and location into GroupExaminer
def __init__(self, Scenario, ID=None, Newborn=True, MaxFriends=0)
Merely calls parent classes' constructors.
class Individual: basic individual.
def dies(self)
Action to be performed when dying
def display(self, erase=False)
can be used to display individuals
def aging(self, step=1)
Increments the individual's age.
def observation(self, GroupExaminer)
stores individual's signature in 'GroupExaminer'
def dead(self)
An individual is dead if it is too old or has lost all its 'LifePoints'.
def score(self, bonus=0, FlagSet=False)
Sets score or adds points to score, depending on FlagSet - Returns score value.
def accident(self, loss=1)
The victim suffers from a loss of life points.
def signature(self)
returns age and score
class Phenome: set of non inheritable characteristics
class Genome: list of genes carried by individuals
Augmented version of Friends for asymmetrical links - replaces 'Alliances'.
Definition of phenotype as non inheritable characters.
Definition of genes as DNA segments having semantics.
Individuals inherit this class which determines who is friend with whom.