diff --git a/__pycache__/RotTable.cpython-37.pyc b/__pycache__/RotTable.cpython-37.pyc index 488d94e3495eb14f5e5656ee066c85187063795a..20d277d55079d7a6401199aa6d99042a10aacd32 100644 Binary files a/__pycache__/RotTable.cpython-37.pyc and b/__pycache__/RotTable.cpython-37.pyc differ diff --git a/__pycache__/Traj3D.cpython-37.pyc b/__pycache__/Traj3D.cpython-37.pyc index bb19acf2cb441bd950ad0bafe725b66e924b457a..3051667333c64564621cb2fe405f2b8ac037b6bd 100644 Binary files a/__pycache__/Traj3D.cpython-37.pyc and b/__pycache__/Traj3D.cpython-37.pyc differ diff --git a/__pycache__/individu.cpython-37.pyc b/__pycache__/individu.cpython-37.pyc index 421ada9911f9aceeb1a109b57518c98bb35bfd74..98e1fc46b75b89e6b1481052c1f6d4bf92a9d04c 100644 Binary files a/__pycache__/individu.cpython-37.pyc and b/__pycache__/individu.cpython-37.pyc differ diff --git a/algogenetique.py b/algogenetique.py index a2c977b0ea7b69061d3bf6275614a6ffbe78ec29..7726e23836b7b1aee14371db67c9da0cce462b1e 100644 --- a/algogenetique.py +++ b/algogenetique.py @@ -8,32 +8,59 @@ import croisement from Traj3D import * from random import random import matplotlib.pyplot as plt +import time +# Debut du decompte du temps +start_time = time.time() -def main(N,tmax,pmutation, proportion,brin="plasmid_8k.fasta"): - '''lineList = [line.rstrip('\n') for line in open(brin)] - brin = ''.join(lineList[1:])''' + +def main(N,tmax,pmutation, proportion): L=[] + lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] + brin = ''.join(lineList[1:]) People=Population(N) + S1=[] + for individu in People.indiv: + individu.evaluate(brin) + S1.append(int(individu.score)) + maximum=int(max(S1)) for i in range(tmax): print(i) - max=0 - best=None + mini=People.indiv[0].score + best=People.indiv[0] People.reproduction(p = proportion, proba_mutation= pmutation) for individu in People.indiv: - if individu.score>max: + if individu.score<mini: best=individu - max=individu.score - L.append(max) + mini=individu.score + L.append(mini) + plt.subplot(221) plt.plot([i for i in range(tmax)], L) + + + plt.subplot(223) + plt.hist(S1, range = (0, maximum+10), bins = 20, color = 'red') + + S2=[individu.score for individu in People.indiv] + print("Score final: ",best.score) + + + plt.subplot(224) + plt.hist(S2, range = (0,maximum+10), bins = 20, color = 'blue') plt.show() - return(best,People) + + return(best,People) -best,People = main(100,100,0.01,50) +lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] +brin = ''.join(lineList[1:]) +best,People = main(10,10,0.01,5) test = Traj3D() -test.compute("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA", best.table) +test.compute(brin, best.table) test.draw("first_plot") + +# Affichage du temps d execution +print("Temps d'execution : %s secondes " % (time.time() - start_time)) diff --git a/individu.py b/individu.py index 24193810b0c780eb4bc09bdd034a82094d59f376..20958d3de778f360a6da39856777dffe233336bf 100644 --- a/individu.py +++ b/individu.py @@ -37,9 +37,9 @@ class Individu(): list_distance += [distance_first_nuc, distance_last_nuc] - self.score = 1/max(list_distance) + self.score = max(list_distance) - return 1/max(list_distance) + return max(list_distance) def mutation(self, proba = P1): diff --git a/population.py b/population.py index 828caac54389b4296f47305d41e41a990b3b09dd..104f66bb97b274d923f7dcf554ea4fe3599ef717 100644 --- a/population.py +++ b/population.py @@ -67,7 +67,7 @@ class Population: p = (self.n)//2 meilleur = self.indiv[0] for individu in self.indiv : - if meilleur.score < individu.score: + if meilleur.score > individu.score: print("meilleur, individu: ", meilleur.score, individu.score) meilleur = individu newself = [meilleur] @@ -83,7 +83,7 @@ class Population: x=self.indiv[m] y=self.indiv[t] - if x.score>=y.score: + if x.score<y.score: newself.append(x) else: newself.append(y) @@ -167,8 +167,10 @@ class Population: y=copy.deepcopy(newself[t]) couple_enfant = enfant(x,y) for child in couple_enfant : + lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] + brin = ''.join(lineList[1:]) child.mutation(proba_mutation) - child.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") + child.evaluate(brin) newself.append(couple_enfant[0]) newself.append(couple_enfant[1]) self = self.modifier_population(newself)