Skip to content
Snippets Groups Projects
Commit abf4b921 authored by Zhong Yi's avatar Zhong Yi
Browse files

generation main

parent 02679b03
No related branches found
No related tags found
No related merge requests found
......@@ -56,7 +56,6 @@ def tests_croisements():
plt.legend()
plt.show()
plt.savefig("tests_croisements.png")
# plt.close()
def tests_selection():
......@@ -102,7 +101,6 @@ def tests_selection():
plt.legend()
plt.show()
plt.savefig("selection_methodes.png")
# plt.close()
def test_opt():
......@@ -135,6 +133,46 @@ def test_opt():
print("time :", time.time()-time0)
def generation():
time0 = time.time()
gen = [i for i in range(1, nb_iter+1)]
moy = []
meilleur = []
rot_table = RotTable()
traj_final = Traj3D()
# Read file
lineList = [line.rstrip('\n') for line in open(args.filename)]
# Formatting
seq = ''.join(lineList[1:])
popu = Population(size)
for j in range(nb_iter):
popu.iteration(seq, nom_selection, nom_croisement)
final_tab, value = popu.meilleur(seq)
moy.append(popu.evaluate_moyenne(seq))
meilleur.append(value)
print(final_tab.distance(seq), "(distance optimisée)")
print(rot_table.distance(seq), "(distance de base)")
traj_final.compute(seq, final_tab)
traj_final.draw(str(int(final_tab.distance(seq))))
traj_final.write("data/traj_final.png")
print("time :", time.time()-time0)
plt.figure(5)
plt.plot(gen, moy, label='moyenne')
plt.plot(gen, meilleur, label="meilleur")
plt.xlabel('génration')
plt.ylabel('distance (log)')
plt.yscale('log')
plt.legend()
plt.savefig('data/evo.png')
def main():
time0 = time.time()
......@@ -150,8 +188,9 @@ def main():
popu = Population(size)
popu.make_evolution_iter(seq, nom_selection, nom_croisement, nb_iter)
final_tab, value = popu.meilleur(seq)
final_tab.exportation()
print(final_tab.distance(seq), "(distance optimisée)")
rot_init = RotTable(randomize=False)
print(rot_init.distance(seq), "(distance de base)")
......@@ -167,10 +206,8 @@ def main():
traj.write(args.filename+".png")
traj_final.draw(str(int(final_tab.distance(seq))))
traj_final.write("data/traj_final.png")
traj_final2.draw(str(int(math.sqrt(final_tab.evaluate(seq2)))))
traj_final2.draw(str(int(math.sqrt(final_tab.distance(seq2)))))
traj_final2.write("data/traj_final2.png")
print("time :", time.time()-time0)
......@@ -178,3 +215,4 @@ if __name__ == "__main__":
main()
# tests_croisements()
# tests_selection()
# generation()
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