Skip to content
Snippets Groups Projects
Commit 6e66e365 authored by Kappes Marques Rodrigo's avatar Kappes Marques Rodrigo
Browse files

cleaned a bit the main code

parent 6f6a45c8
Branches
No related tags found
No related merge requests found
...@@ -10,38 +10,50 @@ from random import random ...@@ -10,38 +10,50 @@ from random import random
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import time import time
# Debut du decompte du temps # Start of the time counting
start_time = time.time() start_time = time.time()
def main(N,tmax,pmutation, proportion): def main(N,tmax,pmutation, proportion):
#Setting up initial variables
L=[] L=[]
lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
brin = ''.join(lineList[1:]) brin = ''.join(lineList[1:])
#Creation of the initial population
People=Population(N) People=Population(N)
#Avaliating the initial population
S1=[] S1=[]
for individu in People.indiv: for individu in People.indiv:
individu.evaluate() individu.evaluate()
S1.append(int(individu.score)) S1.append(int(individu.score))
maximum=int(max(S1)) maximum=int(max(S1))
#The main loop of new generations
for i in range(tmax): for i in range(tmax):
mini=People.indiv[0].score mini=People.indiv[0].score
best=People.indiv[0] best=People.indiv[0]
People.reproduction(p = proportion, proba_mutation= pmutation) People.reproduction(p = proportion, proba_mutation= pmutation)
#Searching for the best individual in each generation
for individu in People.indiv: for individu in People.indiv:
if individu.score<mini: if individu.score<mini:
best=individu best=individu
mini=individu.score mini=individu.score
#Printing usefull data (generation average and their best score)
S2=[individu.score for individu in People.indiv] S2=[individu.score for individu in People.indiv]
avg = sum(S2)/len(S2) avg = sum(S2)/len(S2)
L.append(mini) L.append(mini)
print(i,"avg:",avg,"best score:", mini) print(i,"avg:",avg,"best score:", mini)
#Plotting all the graphs
plt.subplot(221) plt.subplot(221)
plt.plot([i for i in range(tmax)], L) plt.plot([i for i in range(tmax)], L)
plt.subplot(223) plt.subplot(223)
plt.hist(S1, range = (0, maximum+10), bins = 20, color = 'red') plt.hist(S1, range = (0, maximum+10), bins = 20, color = 'red')
...@@ -58,13 +70,12 @@ def main(N,tmax,pmutation, proportion): ...@@ -58,13 +70,12 @@ def main(N,tmax,pmutation, proportion):
return(best,People) return(best,People)
#Testing our solution and printing the result in 3D
lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
brin = ''.join(lineList[1:]) brin = ''.join(lineList[1:])
best,People = main(60,60,0.05,30) best,People = main(60,60,0.05,30)
test = Traj3D() test = Traj3D()
test.compute(brin, best.table) test.compute(brin, best.table)
test.draw("first_plot") test.draw("first_plot")
# Affichage du temps d execution
print("Temps d'execution : %s secondes " % (time.time() - start_time)) print("Temps d'execution : %s secondes " % (time.time() - start_time))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment