Skip to content
Snippets Groups Projects
Commit 4f45ed5b authored by Muller Sacha's avatar Muller Sacha
Browse files

Merge branch 'Chloe2'

parents 7dcbab36 1179c3ab
Branches
No related tags found
No related merge requests found
......@@ -63,3 +63,4 @@ class RotTable:
table1 = RotTable()
print(table1.orta())
print(table1.rot_table["AA"])
File added
No preview for this file type
File added
......@@ -2,6 +2,9 @@ from RotTable import RotTable
from Traj3D import *
import numpy as np
from math import sqrt
from random import random
P1 = 0.015
class Individu():
......@@ -28,13 +31,24 @@ class Individu():
diff_angle = sum(abs(rot_computed - rot_traj))
self.score = 1/(distance + diff_angle)
def mutation(self):
mutation = 0
return mutation
table = RotTable()
test = Individu(table)
test.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA")
print(test.score)
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 :
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])
# individu1 = Individu(RotTable())
# print(individu1.table.rot_table)
# individu1.mutation()
# table = RotTable()
# test = Individu(table)
# test.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA")
# print(test.score)
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment