diff --git a/croisement.py b/croisement.py index a59546f35101170f94063bcc93992754ca4c402a..48a399f3e03e49d46867b53a1695e99657f13c67 100644 --- a/croisement.py +++ b/croisement.py @@ -1,5 +1,6 @@ import numpy from RotTable import RotTable +from individu import Individu ROT_TABLE = {\ "AA": [35.62, 7.2, -154, 0.06, 0.6, 0],\ @@ -22,17 +23,17 @@ ROT_TABLE = {\ def croisement_un_point(parent1, parent2): - enfant1 = RotTable() - enfant2 = RotTable() + enfant1 = Individu(RotTable()) + enfant2 = Individu(RotTable()) comp = 0 point_crois= numpy.random.random_integers(0,16) for doublet in ROT_TABLE: if comp < point_crois: - enfant1.rot_table[doublet] = parent1.rot_table[doublet] - enfant2.rot_table[doublet] = parent2.rot_table[doublet] + enfant1.table.rot_table[doublet] = parent1.table.rot_table[doublet] + enfant2.table.rot_table[doublet] = parent2.table.rot_table[doublet] else : - enfant1.rot_table[doublet] = parent2.rot_table[doublet] - enfant2.rot_table[doublet] = parent1.rot_table[doublet] + enfant1.table.rot_table[doublet] = parent2.table.rot_table[doublet] + enfant2.table.rot_table[doublet] = parent1.table.rot_table[doublet] comp += 1 return enfant1, enfant2 diff --git a/population.py b/population.py index 8a55446c540df399cff28f533f1ecf13a6081c15..fdcb337769f967dce43c6738a3a2729364390cfe 100644 --- a/population.py +++ b/population.py @@ -20,8 +20,8 @@ class Population: p = (self.n)//2 newself=[] vu=set() - m=None - t=None #méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer + m=randrange(0,self.n) + t=randrange(0,self.n) #méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer while len(newself)<p: while m in vu: m=randrange(0,self.n) @@ -44,14 +44,12 @@ class Population: p = (self.n)//2 newself=[] vu=set() - t=None - m=None + t=randrange(0,self.n) + m=randrange(0,self.n) while len(newself)<p: while m in vu: - print("self.n", self.n) m=randrange(0,self.n) while t in vu: - print("self.n", self.n) t=randrange(0,self.n) x=self.indiv[m] y=self.indiv[t] @@ -135,7 +133,9 @@ class Population: t=randrange(0,self.n) x=newself[m] y=newself[t] - newself.append(enfant(x,y)) + couple_enfant = enfant(x,y) + newself.append(couple_enfant[0]) + newself.append(couple_enfant[1]) self = self.modifier_population(newself) def afficher(popu):