From 59c403af85e61e58fa930613f9e76ab077e7e31e Mon Sep 17 00:00:00 2001
From: Kappes Marques Rodrigo <rodrigo.kappes@student-cs.fr>
Date: Wed, 29 Jan 2020 09:23:14 +0100
Subject: [PATCH] added everything

---
 __pycache__/RotTable.cpython-37.pyc | Bin 2571 -> 2576 bytes
 __pycache__/Traj3D.cpython-37.pyc   | Bin 1925 -> 1930 bytes
 algogenetique.py                    |  13 ++++++------
 individu.py                         |  30 ++++++++++++++++++----------
 population.py                       |   9 ++++-----
 5 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/__pycache__/RotTable.cpython-37.pyc b/__pycache__/RotTable.cpython-37.pyc
index eda825aff2fc67047d02eda36807123f6b5899fc..6611c6bdf67c60524cc9c963f7a2261ce632ed52 100644
GIT binary patch
delta 60
zcmeAcnIOXD#LLUYz`(%pe9lI$9W2Uj$yPC;#i>QbG2V#<1*yd`E~&-YCHVz0Azr$v
QWifgAW%-*QuxPUa03~=6{{R30

delta 55
zcmbOr(k;T}#LLUYz`(#TbJ|9(9V~K=$yPC;#i>QbG2V#<1*yd`E~&-YCHVz0Azr$v
LWt*R}XtM$UwH^_O

diff --git a/__pycache__/Traj3D.cpython-37.pyc b/__pycache__/Traj3D.cpython-37.pyc
index 27f1de9630c467c4d2341a5f33c68535c5d6a139..82a390bdf94f09f504f253f023b0405e31d60754 100644
GIT binary patch
delta 35
rcmZqW@8aij;^pOHU|?W)K4&9WH6x?T<Tge*mc0D3{LPCQAF%=emN5z0

delta 30
lcmeC;Z{_E5;^pOHU|?X_nYodxnvv0davP)E=9P>OSpj8c2eJSF

diff --git a/algogenetique.py b/algogenetique.py
index 8a1874e..1be4716 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 2419381..6457428 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 828caac..6e2657b 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")
-- 
GitLab