diff --git a/__pycache__/RotTable.cpython-37.pyc b/__pycache__/RotTable.cpython-37.pyc index eda825aff2fc67047d02eda36807123f6b5899fc..6611c6bdf67c60524cc9c963f7a2261ce632ed52 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 27f1de9630c467c4d2341a5f33c68535c5d6a139..82a390bdf94f09f504f253f023b0405e31d60754 100644 Binary files a/__pycache__/Traj3D.cpython-37.pyc and b/__pycache__/Traj3D.cpython-37.pyc differ diff --git a/algogenetique.py b/algogenetique.py index 8a1874e03d214a4c3f2f9804b275af26d35d8f5e..1be4716b802797a9f4b70810ff38d739cd422c8c 100644 --- a/algogenetique.py +++ b/algogenetique.py @@ -12,12 +12,10 @@ import matplotlib.pyplot as plt def main(N,tmax,pmutation, proportion,brin="plasmid_8k.fasta"): - '''lineList = [line.rstrip('\n') for line in open(brin)] - brin = ''.join(lineList[1:])''' L=[] People=Population(N) for i in range(tmax): - print(i) + #print(i) max=0 best=None People.reproduction(p = proportion, proba_mutation= pmutation) @@ -26,13 +24,16 @@ def main(N,tmax,pmutation, proportion,brin="plasmid_8k.fasta"): best=individu max=individu.score L.append(max) + print(i,":",max) plt.plot([i for i in range(tmax)], L) plt.show() - return(best) + return(best, People) -main(100,100,0,50) - +best, People = main(60,100,0.01,20) +traj = Traj3D() +traj.compute(best.brin,best.table) +traj.draw("plot") diff --git a/individu.py b/individu.py index 24193810b0c780eb4bc09bdd034a82094d59f376..6457428c303ba4241b9d4d99513ef6a21ef4f89a 100644 --- a/individu.py +++ b/individu.py @@ -2,7 +2,7 @@ from RotTable import RotTable from Traj3D import Traj3D import numpy as np from math import sqrt, inf -from random import random +from random import random, randrange P1 = 0.015 @@ -10,17 +10,20 @@ class Individu(): def __init__(self, table): self.table = table - self.score = self.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") + lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] + self.brin = ''.join(lineList[1:]) + #self.brin = "AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA" + self.score = self.evaluate() - def evaluate(self, brin): + def evaluate(self): traj = Traj3D() numb_ajout = 3 - fisrt_seq = brin[0:numb_ajout] - last_seq = brin[-numb_ajout:] + fisrt_seq = self.brin[0:numb_ajout] + last_seq = self.brin[-numb_ajout:] - traj.compute(last_seq + brin + fisrt_seq, self.table) + traj.compute(last_seq + self.brin + fisrt_seq, self.table) traj_array = np.array(traj.getTraj()) list_distance = [] @@ -44,10 +47,17 @@ class Individu(): def mutation(self, proba = P1): table_rotations = self.table.rot_table - for doublet in table_rotations : - for coord in range(3): - tir = random() - if tir < proba : + number_of_mutations = 5 + for i in range(0,number_of_mutations): + tir = random() + if tir < proba : + doubletNumber = randrange(0,8) + counter = 0 + for doublet in table_rotations: + if counter==doubletNumber: + break + counter+=1 + for coord in range(3): table_rotations[doublet][coord] =np.random.uniform(low = self.table.orta()[doublet][coord] - self.table.orta()[doublet][coord + 3], high = self.table.orta()[doublet][coord] + self.table.orta()[doublet][coord + 3]) doublet2 = self.table.corr()[doublet] if coord == 0 or coord == 1 : diff --git a/population.py b/population.py index 828caac54389b4296f47305d41e41a990b3b09dd..6e2657bef08024066bcb0ffc24f0c3930e410d40 100644 --- a/population.py +++ b/population.py @@ -15,8 +15,7 @@ class Population: self.n = len(liste_individus) self.indiv = liste_individus for i in range(0,self.n): - self.indiv[i].evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") - + self.indiv[i].evaluate() return self def selection_p_best(self,p=None): @@ -68,7 +67,7 @@ class Population: meilleur = self.indiv[0] for individu in self.indiv : if meilleur.score < individu.score: - print("meilleur, individu: ", meilleur.score, individu.score) + #print("meilleur, individu: ", meilleur.score, individu.score) meilleur = individu newself = [meilleur] vu=set() @@ -168,7 +167,7 @@ class Population: couple_enfant = enfant(x,y) for child in couple_enfant : child.mutation(proba_mutation) - child.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") + child.evaluate() newself.append(couple_enfant[0]) newself.append(couple_enfant[1]) self = self.modifier_population(newself) @@ -184,7 +183,7 @@ def test(): popu = Population(4) print("\n POPULATION INITIALE \n") for individu in popu.indiv : - individu.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") + individu.evaluate() afficher(popu) popu.reproduction(selection = popu.selection_duel) print("\n REPRODUCTION \n")