Skip to content
Snippets Groups Projects
Commit 5fe4c4b1 authored by Muller Sacha's avatar Muller Sacha
Browse files

Merge branch 'master' of...

Merge branch 'master' of https://gitlab-research.centralesupelec.fr/2019santosgc/ei-jeux-evolutionnaires
parents 4f45ed5b 293c6eb1
No related branches found
No related tags found
No related merge requests found
...@@ -24,18 +24,21 @@ class RotTable: ...@@ -24,18 +24,21 @@ class RotTable:
"TT": [35.62, 7.2, -154, 0.06, 0.6, 0]\ "TT": [35.62, 7.2, -154, 0.06, 0.6, 0]\
} }
# get the angles in each axis (x, y, z), considering the deviation
def __init__(self): def __init__(self):
self.rot_table = {} self.rot_table = {}
for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE: for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE:
self.rot_table[dinucleotide] = RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][:3] self.rot_table[dinucleotide] = RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][:3]
self.alea() self.alea()
# get a random deviation, considering the "limits" given in the last 3 columns
# of __ORIGINAL_ROT_TABLE
def alea(self): def alea(self):
for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE: for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE:
for i in range(2): for i in range(2):
self.rot_table[dinucleotide][i] += numpy.random.uniform(low = -RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3], high= RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3]) self.rot_table[dinucleotide][i] += numpy.random.uniform(low = -RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3], high= RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3])
# return __ORIGINAL_ROT_TABLE
def orta(self): def orta(self):
return self.__ORIGINAL_ROT_TABLE return self.__ORIGINAL_ROT_TABLE
......
...@@ -6,35 +6,48 @@ class Population: ...@@ -6,35 +6,48 @@ class Population:
self.n = n self.n = n
def selection_duel_pondere(self,p=(self.n)//2): def selection_duel_pondere(self,p=(self.n)//2):
n=self.n newself=[]
newself=[] #méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer vu={}
while len(self)>p: m=None
m=random.randrange(0,len(self)) t=None #méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer
t=random.randrange(0,len(self)) while len(newself)<p:
while m in vu:
m=random.randrange(0,len(self))
while t in vu:
t=random.randrange(0,len(self))
x=self[m] x=self[m]
y=self[t] y=self[t]
vu.add(t)
vu.add(m)
p=uniform(0,1) p=uniform(0,1)
if p>x.score/(x.score+y.score): if p>x.score/(x.score+y.score):
newself.append(y) newself.append(y)
else: else:
newself.append(x) newself.append(x)
return(newself) return(newself)
def selection_duel(self,p=(self.n)//2): def selection_duel(self,p=(self.n)//2):
n=self.n newself=[]
newself=[] #méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer vu={}
while len(self)>p: t=None
m=random.randrange(0,len(self)) m=None
t=random.randrange(0,len(self)) while len(newself)<p:
while m in vu:
m=random.randrange(0,len(self))
while t in vu:
t=random.randrange(0,len(self))
x=self[m] x=self[m]
y=self[t] y=self[t]
vu.add(t)
vu.add(m)
if x.score<=y.score: if x.score<=y.score:
newself.append(x) newself.append(x)
else: else:
newself.append(y) newself.append(y)
return(newself) return(newself)
def selection_par_rang(self, p): def selection_par_rang(self, p=(self.n)//2):
liste_individus = self.indiv liste_individus = self.indiv
n = self.n n = self.n
...@@ -80,6 +93,19 @@ class Population: ...@@ -80,6 +93,19 @@ class Population:
return self return self
self = modifier_population(self, individus_selectionnes) self = modifier_population(self, individus_selectionnes)
def selection_proportionelle(self,p=(self.n)//2):
newself=[]
somme=0
for indiv in self:
somme=somme+indiv.score
while len(newself)<p:
m=m=random.randrange(0,len(self))
x=self[m]
p=uniform(0,1)
if p<=x.score/somme:
newself.append(x)
return(newself)
def reproduction(self,selection=selection_duel,enfant=mixage,p=n//2): def reproduction(self,selection=selection_duel,enfant=mixage,p=n//2):
newself=selection(self,p) newself=selection(self,p)
...@@ -91,7 +117,6 @@ class Population: ...@@ -91,7 +117,6 @@ class Population:
newself.append(enfant(x,y)) newself.append(enfant(x,y))
return(newself) return(newself)
print([random.randrange(1,10) for i in range(5)])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment