From 246bb57cfb31e3c682138e09db5b479712304e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20Muller?= <chloe.muller@student-cs.fr> Date: Tue, 28 Jan 2020 15:20:04 +0100 Subject: [PATCH] mutations seulement sur les enfants --- algogenetique.py | 11 ++++++----- population.py | 13 +++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/algogenetique.py b/algogenetique.py index fcdb989..cbcde63 100644 --- a/algogenetique.py +++ b/algogenetique.py @@ -16,21 +16,22 @@ def main(N,tmax,pmutation, proportion,brin="plasmid_8k.fasta"): brin = ''.join(lineList[1:])''' L=[] People=Population(N) - afficher(People) + # afficher(People) for i in range(tmax): print("\n \n NOUVELLE GENERATION \n \n") max=0 best=None for individu in People.indiv: individu.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") - People.reproduction(p = proportion) - for individu in People.indiv: - individu.mutation(pmutation) + People.reproduction(p = proportion, proba_mutation= pmutation) + # for individu in People.indiv: + # individu.mutation(pmutation) for individu in People.indiv: individu.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") if individu.score>max: best=individu max=individu.score + afficher(People) L.append(max) #print(L) plt.plot([i for i in range(tmax)], L) @@ -38,7 +39,7 @@ def main(N,tmax,pmutation, proportion,brin="plasmid_8k.fasta"): return(best) -main(100,50,0.015,50) +main(10,50,0,5) diff --git a/population.py b/population.py index 7268915..dc51f8c 100644 --- a/population.py +++ b/population.py @@ -42,7 +42,12 @@ class Population: def selection_duel(self,p=None): if p == None : p = (self.n)//2 - newself=[] + meilleur = self.indiv[0] + for individu in self.indiv : + if meilleur.score < individu.score: + meilleur = individu + newself = [meilleur] + print("\n \n \nmeilleur", meilleur.table.rot_table, "\n \nscore", meilleur.score) vu=set() t=randrange(0,self.n) m=randrange(0,self.n) @@ -120,7 +125,9 @@ class Population: newself.append(x) self = self.modifier_population(newself) - def reproduction(self,selection=None,enfant=croisement_un_point, p = None): + def reproduction(self,proba_mutation = None, selection=None,enfant=croisement_un_point, p = None): + if proba_mutation == None : + proba_mutation = 0.001 if selection == None : selection = self.selection_duel if p == None : @@ -134,6 +141,8 @@ class Population: x=newself[m] y=newself[t] couple_enfant = enfant(x,y) + for child in couple_enfant : + child.mutation(proba_mutation) newself.append(couple_enfant[0]) newself.append(couple_enfant[1]) self = self.modifier_population(newself) -- GitLab