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