diff --git a/.DS_Store b/.DS_Store index ce584036d310ff852c50dff6063d64ba8881c0a3..eb0f78382c04c8e58afb90d646790e2b7fb5c130 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/RotTable.py b/RotTable.py index e3486c1b21452cfed789090694fdb3d372884c98..9f841efe35b5e7de98443db1b6948ec1a040ef33 100644 --- a/RotTable.py +++ b/RotTable.py @@ -21,9 +21,40 @@ class RotTable: "TA": [36, 0.9, 0, 1.1, 2, 0],\ "TC": [36.9, 5.3, -120, 0.9, 6, 0],\ "TG": [34.5, 3.5, 64, 0.9, 34, 0],\ - "TT": [35.62, 7.2, -154, 0.06, 0.6, 0]\ + "TT": [35.62, 7.2, 154, 0.06, 0.6, 0]\ } + __CORRESPONDANCE = {\ + "AA": "TT",\ + "AC": "GT",\ + "AG": "CT",\ + "AT": "AT",\ + "CA": "TG",\ + "CC": "GG",\ + "CG": "CG",\ + "CT": "AG",\ + "GA": "TC",\ + "GC": "GC",\ + "GG": "CC",\ + "GT": "AC",\ + "TA": "TA",\ + "TC": "GA",\ + "TG": "CA",\ + "TT": "AA"\ + } + + __SOUS_CORRESPONDANCE = {\ + "AA": "TT",\ + "AC": "GT",\ + "AG": "CT",\ + "AT": "AT",\ + "CA": "TG",\ + "CC": "GG",\ + "CG": "CG",\ + "GA": "TC",\ + "GC": "GC",\ + "TA": "TA"\ + } # get the angles in each axis (x, y, z), considering the deviation def __init__(self): self.rot_table = {} @@ -34,13 +65,18 @@ class RotTable: # get a random deviation, considering the "limits" given in the last 3 columns # of __ORIGINAL_ROT_TABLE def alea(self): - for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE: + for dinucleotide in RotTable.__SOUS_CORRESPONDANCE: for i in range(2): - self.rot_table[dinucleotide][i] += numpy.random.uniform(low = -RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3], high= RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3]) + delta = numpy.random.uniform(low = -RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3], high= RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3]) + self.rot_table[dinucleotide][i] += delta + self.rot_table[RotTable.__SOUS_CORRESPONDANCE[dinucleotide]][i] += delta # return __ORIGINAL_ROT_TABLE def orta(self): return self.__ORIGINAL_ROT_TABLE + + def corr(self): + return self.__CORRESPONDANCE ################### # WRITING METHODS # @@ -53,17 +89,17 @@ class RotTable: ################### def getTwist(self, dinucleotide): - return RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][0] + return self.rot_table[dinucleotide][0] def getWedge(self, dinucleotide): - return RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][1] + return self.rot_table[dinucleotide][1] def getDirection(self, dinucleotide): - return RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][2] + return self.rot_table[dinucleotide][2] ################### -# table1 = RotTable() -# print(table1.orta()) +#table1 = RotTable() +#print(table1.orta()) -# print(table1.rot_table["AA"]) +# print(table1.rot_table) diff --git a/Traj3D.py b/Traj3D.py index eee71819327b28c570771dcdca2b603043a014b9..92cc9720555ee8c29c954b2ea9a40cfc814917aa 100644 --- a/Traj3D.py +++ b/Traj3D.py @@ -65,3 +65,9 @@ class Traj3D: ax.plot(x,y,z) plt.show() plt.savefig(filename) + +# from RotTable import RotTable +# table = RotTable() +# test = Traj3D() +# test.compute("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA", table) +# test.draw("first_plot") \ No newline at end of file diff --git a/__pycache__/Initialisation.cpython-37.pyc b/__pycache__/Initialisation.cpython-37.pyc deleted file mode 100644 index e986e03a10e3574402c013796cf8296d4a58eb32..0000000000000000000000000000000000000000 Binary files a/__pycache__/Initialisation.cpython-37.pyc and /dev/null differ diff --git a/__pycache__/RotTable.cpython-36.pyc b/__pycache__/RotTable.cpython-36.pyc index dbb2e4134f6503a6df95598a7c5505e659fc5c85..a8064bb45dbaad46db289f9e730b7dd816423ae4 100644 Binary files a/__pycache__/RotTable.cpython-36.pyc and b/__pycache__/RotTable.cpython-36.pyc differ diff --git a/__pycache__/RotTable.cpython-37.pyc b/__pycache__/RotTable.cpython-37.pyc index 306bef3707a8dfe8d997aa52208ffe660f6a4161..34a0caf41c6c790ba653935d986362949db3c6b6 100644 Binary files a/__pycache__/RotTable.cpython-37.pyc and b/__pycache__/RotTable.cpython-37.pyc differ diff --git a/__pycache__/Traj3D.cpython-36.pyc b/__pycache__/Traj3D.cpython-36.pyc index ecd80201694553fe02c71577fca8c84a37602d91..b5c1da4e7f16d56be5828446b2f8423d03027c1c 100644 Binary files a/__pycache__/Traj3D.cpython-36.pyc and b/__pycache__/Traj3D.cpython-36.pyc differ diff --git a/__pycache__/Traj3D.cpython-37.pyc b/__pycache__/Traj3D.cpython-37.pyc index 9089d353fd2661eb0e1c444fe75a6b707a6ecd10..868cf3c5285c75f887b4c574b83184755ea94f88 100644 Binary files a/__pycache__/Traj3D.cpython-37.pyc and b/__pycache__/Traj3D.cpython-37.pyc differ diff --git a/__pycache__/croisement.cpython-37.pyc b/__pycache__/croisement.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ecad689e2e6d0e89bac238cab0e024e5e204b30d Binary files /dev/null and b/__pycache__/croisement.cpython-37.pyc differ diff --git a/__pycache__/individu.cpython-37.pyc b/__pycache__/individu.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..37d35b2ce8c0d3c05331c63b2112883e7ee05733 Binary files /dev/null and b/__pycache__/individu.cpython-37.pyc differ diff --git a/__pycache__/population.cpython-37.pyc b/__pycache__/population.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0a6a330d28c49e773950856fc4d57e01af3ba167 Binary files /dev/null and b/__pycache__/population.cpython-37.pyc differ diff --git a/algogenetique.py b/algogenetique.py new file mode 100644 index 0000000000000000000000000000000000000000..8a1874e03d214a4c3f2f9804b275af26d35d8f5e --- /dev/null +++ b/algogenetique.py @@ -0,0 +1,38 @@ +import mathutils +import math +import numpy +import RotTable +from individu import Individu +from population import Population, afficher +import croisement +from Traj3D import * +from random import random +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) + max=0 + best=None + People.reproduction(p = proportion, proba_mutation= pmutation) + for individu in People.indiv: + if individu.score>max: + best=individu + max=individu.score + L.append(max) + + plt.plot([i for i in range(tmax)], L) + plt.show() + return(best) + + +main(100,100,0,50) + + + diff --git a/croisement.py b/croisement.py index 48a399f3e03e49d46867b53a1695e99657f13c67..96f85a8a89e1dcaa97cbed0f06233942ee36f211 100644 --- a/croisement.py +++ b/croisement.py @@ -26,30 +26,71 @@ def croisement_un_point(parent1, parent2): enfant1 = Individu(RotTable()) enfant2 = Individu(RotTable()) comp = 0 - point_crois= numpy.random.random_integers(0,16) + point_crois= numpy.random.random_integers(0,8) for doublet in ROT_TABLE: + if doublet == "GA": + break if comp < point_crois: enfant1.table.rot_table[doublet] = parent1.table.rot_table[doublet] + correspondent_doublet1 = enfant1.table.corr()[doublet] + enfant1.table.rot_table[correspondent_doublet1] = parent1.table.rot_table[correspondent_doublet1] + enfant1.table.rot_table[correspondent_doublet1][2] *= -1 + enfant2.table.rot_table[doublet] = parent2.table.rot_table[doublet] + correspondent_doublet2 = enfant2.table.corr()[doublet] + enfant2.table.rot_table[correspondent_doublet2] = parent2.table.rot_table[correspondent_doublet2] + enfant2.table.rot_table[correspondent_doublet2][2] *= -1 + else : enfant1.table.rot_table[doublet] = parent2.table.rot_table[doublet] + correspondent_doublet1 = enfant1.table.corr()[doublet] + enfant1.table.rot_table[correspondent_doublet1] = parent2.table.rot_table[correspondent_doublet1] + enfant1.table.rot_table[correspondent_doublet1][2] *= -1 + enfant2.table.rot_table[doublet] = parent1.table.rot_table[doublet] + correspondent_doublet2 = enfant2.table.corr()[doublet] + enfant2.table.rot_table[correspondent_doublet2] = parent1.table.rot_table[correspondent_doublet1] + enfant2.table.rot_table[correspondent_doublet2][2] *= -1 + comp += 1 return enfant1, enfant2 def croisement_deux_points(parent1, parent2): - enfant1 = RotTable() - enfant2 = RotTable() + enfant1 = Individu(RotTable()) + enfant2 = Individu(RotTable()) comp = 0 - point_crois1= numpy.random.random_integers(0,16) - point_crois2= numpy.random.random_integers(0,16) + point_crois1= numpy.random.random_integers(0,8) + point_crois2= numpy.random.random_integers(0,8) for doublet in ROT_TABLE: if comp < min(point_crois1,point_crois2) or comp > max(point_crois1,point_crois2): - 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] + correspondent_doublet1 = enfant1.table.corr()[doublet] + enfant1.table.rot_table[correspondent_doublet1] = parent1.table.rot_table[correspondent_doublet1] + enfant1.table.rot_table[correspondent_doublet1][2] *= -1 + + enfant2.table.rot_table[doublet] = parent2.table.rot_table[doublet] + correspondent_doublet2 = enfant2.table.corr()[doublet] + enfant2.table.rot_table[correspondent_doublet2] = parent2.table.rot_table[correspondent_doublet2] + enfant2.table.rot_table[correspondent_doublet2][2] *= -1 + 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] + correspondent_doublet1 = enfant1.table.corr()[doublet] + enfant1.table.rot_table[correspondent_doublet1] = parent2.table.rot_table[correspondent_doublet1] + enfant1.table.rot_table[correspondent_doublet1][2] *= -1 + + enfant2.table.rot_table[doublet] = parent1.table.rot_table[doublet] + correspondent_doublet2 = enfant2.table.corr()[doublet] + enfant2.table.rot_table[correspondent_doublet2] = parent1.table.rot_table[correspondent_doublet1] + enfant2.table.rot_table[correspondent_doublet2][2] *= -1 comp += 1 - return enfant1, enfant2 \ No newline at end of file + return enfant1, enfant2 + +# parent1 = Individu(RotTable()) +# parent2 = Individu(RotTable()) +# print("parent1: ", parent1.table.rot_table) +# print("parent2: ", parent2.table.rot_table) +# enfant1, enfant2 = croisement_un_point(parent1, parent2) +# print("enfant1: ", enfant1.table.rot_table) +# print("enfant2: ", enfant2.table.rot_table) \ No newline at end of file diff --git a/first_plot.png b/first_plot.png new file mode 100644 index 0000000000000000000000000000000000000000..0e536fb530ea40bc82a9395940755ad27a030609 Binary files /dev/null and b/first_plot.png differ diff --git a/individu.py b/individu.py index 0bc68e4926298da3172bec0b670ea360435d13ca..24193810b0c780eb4bc09bdd034a82094d59f376 100644 --- a/individu.py +++ b/individu.py @@ -1,7 +1,7 @@ from RotTable import RotTable -from Traj3D import * +from Traj3D import Traj3D import numpy as np -from math import sqrt +from math import sqrt, inf from random import random P1 = 0.015 @@ -10,27 +10,36 @@ class Individu(): def __init__(self, table): self.table = table - self.score = None + self.score = self.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") def evaluate(self, brin): traj = Traj3D() - traj.compute(brin, self.table) + + numb_ajout = 3 + + fisrt_seq = brin[0:numb_ajout] + last_seq = brin[-numb_ajout:] + + traj.compute(last_seq + brin + fisrt_seq, self.table) traj_array = np.array(traj.getTraj()) + list_distance = [] + + for i in range(numb_ajout): + first_nuc_coordonate = traj_array[numb_ajout+i, 0:3] + first_nuc_coordonate_compute = traj_array[-(numb_ajout-i), 0:3] + + last_nuc_coordonate = traj_array[-(2*numb_ajout-i), 0:3] + last_nuc_coordonate_compute = traj_array[i, 0:3] - first_nucleotide = traj_array[0, 0:3] - last_nucleotide = traj_array[-1, 0:3] - distance = sqrt(sum((first_nucleotide - last_nucleotide) ** 2)) + distance_first_nuc = np.linalg.norm(first_nuc_coordonate - first_nuc_coordonate_compute, ord=2) + distance_last_nuc = np.linalg.norm(last_nuc_coordonate - last_nuc_coordonate_compute, ord=2) - first_name = brin[0] - last_name = brin[-1] + list_distance += [distance_first_nuc, distance_last_nuc] - rot_computed = self.table.rot_table[last_name+first_name] - rot_traj = first_nucleotide - last_nucleotide - # print(rot_traj) - # print(rot_computed) - diff_angle = sum(abs(rot_computed - rot_traj)) - self.score = 1/(distance + diff_angle) + self.score = 1/max(list_distance) + + return 1/max(list_distance) def mutation(self, proba = P1): @@ -39,10 +48,14 @@ class Individu(): for coord in range(3): tir = random() if tir < proba : - # print("mutation", doublet, coord) - # print("table", table_rotations[doublet][coord]) 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]) - # print("table", table_rotations[doublet][coord]) + doublet2 = self.table.corr()[doublet] + if coord == 0 or coord == 1 : + table_rotations[doublet2][coord] = table_rotations[doublet][coord] + else : + #sur l'axe z il y a un moins + table_rotations[doublet2][coord] = - table_rotations[doublet][coord] + # individu1 = Individu(RotTable()) # print(individu1.table.rot_table) @@ -52,3 +65,9 @@ class Individu(): # test = Individu(table) # test.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") # print(test.score) + + +# qqun=Individu(RotTable()) +# qqun.table.rot_table={'AA': [35.576558502141, 7.433901511509349, -154], 'AC': [33.22048222654215, 5.25191751302917, 143], 'AG': [26.446029097301288, 6.052240462237622, -2], 'AT': [30.47045254036881, 1.333716025628036, 0], 'CA': [34.00734209585039, 33.70710613604862, -64], 'CC': [33.61019622767888, 3.713127032109607, -57], 'CG': [29.664061041382677, 6.725155507162601, 0], 'CT': [26.446029097301288, 6.052240462237622, 2], 'GA': [36.655773481637176, 10.45337581740701, 120], 'GC': [42.26984493493484, 3.5310453395352823, 180], 'GG': [33.61019622767888, 3.713127032109607, -57], 'GT': [33.22048222654215, 5.25191751302917, 143], 'TA': [36.951508786388914, -2.5174751178033303, 0], 'TC': [36.655773481637176, 10.45337581740701, -120], 'TG': [34.00734209585039, 33.70710613604862, -64], 'TT': [35.576558502141, 7.433901511509349, -154]} +# qqun.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") +# print(qqun.score) diff --git a/inutile.py b/inutile.py index 1a2947e5d6d776eaab4c42387fcd36f075272bea..420a646fc6e25c17b5aec102de8321736ae1ebaf 100644 --- a/inutile.py +++ b/inutile.py @@ -31,7 +31,7 @@ class table_rotation(rotation): self.dict = {doublet : rotation(doublet) for doublet in ORIGINAL_ROT_TABLE} table1 = table_rotation() -print(table1.dict["AA"].x) +# print(table1.dict["AA"].x) #table1.dict --> {'AA': <__main__.rotation object at 0x000001A722E1BAC8>, 'AC': <__main__.rotation object at 0x000001A722E1BB00>, 'AG': <__main__.rotation object at 0x000001A729A66A58>, 'AT': <__main__.rotation object at 0x000001A729A66A20>, 'CA': <__main__.rotation object at 0x000001A729A669E8>, 'CC': <__main__.rotation object at 0x000001A729A66A90>, 'CG': <__main__.rotation object at 0x000001A729A66B00>, 'CT': <__main__.rotation object at 0x000001A729A66B70>, 'GA': <__main__.rotation object at 0x000001A729B88D68>, 'GC': <__main__.rotation object at 0x000001A729B88DA0>, 'GG': <__main__.rotation object at 0x000001A729B88DD8>, 'GT': <__main__.rotation object at 0x000001A729B88E10>, 'TA': <__main__.rotation object at 0x000001A729B88E48>, 'TC': <__main__.rotation object at 0x000001A729B88E80>, 'TG': <__main__.rotation object at 0x000001A729B88EB8>, 'TT': <__main__.rotation object at 0x000001A729B88EF0>} #table1.dict["AA"] ---> <__main__.rotation object at 0x000001A722E1BAC8> (qui est l'object rotation) diff --git a/population.py b/population.py index fdcb337769f967dce43c6738a3a2729364390cfe..828caac54389b4296f47305d41e41a990b3b09dd 100644 --- a/population.py +++ b/population.py @@ -1,8 +1,9 @@ -import random -from random import random, randint, randrange + +from random import * from individu import Individu from RotTable import RotTable -from croisement import * +from croisement import croisement_un_point, croisement_deux_points +import copy class Population: def __init__(self,n): @@ -13,8 +14,30 @@ class Population: """Fonction qui renvoie une nouvelle instance de population a partir d'une liste d'individus""" self.n = len(liste_individus) self.indiv = liste_individus + for i in range(0,self.n): + self.indiv[i].evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") + return self + def selection_p_best(self,p=None): + if p==None: + p=(self.n)//2 + + def tri_rapide_aux(tableau,debut,fin): + if debut < fin-1: + positionPivot=partitionner(tableau,debut,fin) + tri_rapide_aux(tableau,debut,positionPivot) + tri_rapide_aux(tableau,positionPivot+1,fin) + + def tri_rapide(tableau): + tri_rapide_aux(tableau,0,len(tableau)) + + liste_individus=self.indiv + tri_rapide(liste_individus) + individus_selectionnes = [element for element in liste_individus[:p]] + self = self.modifier_population(individus_selectionnes) + + def selection_duel_pondere(self,p=None): if p == None : p = (self.n)//2 @@ -31,7 +54,7 @@ class Population: y=self.indiv[t] vu.add(t) vu.add(m) - p=random(0,1) + p=random() if p>x.score/(x.score+y.score): newself.append(y) else: @@ -42,25 +65,32 @@ 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: + print("meilleur, individu: ", meilleur.score, individu.score) + meilleur = individu + newself = [meilleur] vu=set() t=randrange(0,self.n) - m=randrange(0,self.n) + m=randrange(0,self.n) + non_vu = [i for i in range(0, self.n)] while len(newself)<p: - while m in vu: - m=randrange(0,self.n) - while t in vu: - t=randrange(0,self.n) + m = choice(non_vu) + non_vu.remove(m) + t = choice(non_vu) + non_vu.remove(t) + x=self.indiv[m] y=self.indiv[t] - vu.add(t) - vu.add(m) - if x.score<=y.score: + if x.score>=y.score: newself.append(x) else: newself.append(y) self = self.modifier_population(newself) + + def selection_par_rang(self,p = None): if p == None : p = (self.n)//2 @@ -115,33 +145,40 @@ class Population: while len(newself)<p: m=m=randrange(0, self.n) x=self.indiv[m] - p=random(0,1) + p=random() if p<=x.score/somme: 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 : p = (self.n)//2 vieille_taille = self.n selection(p) - newself = list(self.indiv) + newself = [element for element in self.indiv] while len(newself)<vieille_taille: m=randrange(0,self.n) t=randrange(0,self.n) - x=newself[m] - y=newself[t] + x=copy.deepcopy(newself[m]) + y=copy.deepcopy(newself[t]) couple_enfant = enfant(x,y) + for child in couple_enfant : + child.mutation(proba_mutation) + child.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") newself.append(couple_enfant[0]) newself.append(couple_enfant[1]) self = self.modifier_population(newself) + def afficher(popu): for individu in popu.indiv : print("\n individu \n") print(individu.table.rot_table) + print ("score", individu.score) def test(): popu = Population(4) @@ -149,16 +186,11 @@ def test(): for individu in popu.indiv : individu.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") afficher(popu) - # popu.selection_par_rang() - # print("\n SELECTION PAR RANG \n") - # afficher(popu) - popu.reproduction() + popu.reproduction(selection = popu.selection_duel) print("\n REPRODUCTION \n") afficher(popu) -test() - - +#test() diff --git a/selection_par_rang.py b/selection_par_rang.py deleted file mode 100644 index ded5567fe7094249e4e3f1e0222031f0010a0164..0000000000000000000000000000000000000000 --- a/selection_par_rang.py +++ /dev/null @@ -1,45 +0,0 @@ -from random import random - -def creer_population(self, liste_individus): - self.n = len(liste_individus) - self.indiv = set(liste_individus) - return self - -def selection_par_rang(self, p = n//2): - set_individus = self.indiv - n = self.n - - def partitionner(tableau,debut,fin): - echanger(tableau,debut,random.randint(debut,fin-1)) - partition=debut - for i in range(debut+1,fin): - if tableau[i].score<tableau[debut].score: - partition+=1 - echanger(tableau,i,partition) - echanger(tableau,debut,partition) - return partition - - def tri_rapide_aux(tableau,debut,fin): - if debut < fin-1: - positionPivot=partitionner(tableau,debut,fin) - tri_rapide_aux(tableau,debut,positionPivot) - tri_rapide_aux(tableau,positionPivot+1,fin) - - def tri_rapide(tableau): - tri_rapide_aux(tableau,0,len(tableau)) - - liste = list(set_individus) - tri_rapide(liste) - individus_selectionnes = [] - - for _ in range(p): - curseur = random()*n*(n+1)/2 - j = 1 - while j*(j+1)/2 < curseur : - j+=1 - #on doit prendre l'individu avec le jème score - individus_selectionnes.append(liste[j]) - self = creer_population(self, liste_individus) - - - \ No newline at end of file