diff --git a/algogenetique.py b/algogenetique.py index fcdb9895d145935e45c1685b2fc0f4ddce2fe373..cbcde6366a75846200845f298aabc3b3588fda1c 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 7268915b15f592aa862b42b3c6decc53c587020e..dc51f8c876c286ad1822991da190f5dcf3804b40 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)