wrapper_genetic_iter.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import os
  2. import matplotlib.pyplot as plt
  3. results = {}
  4. def errorfill(x, y, yerr, color=None, alpha_fill=0.3, ax=None):
  5. ax = ax if ax is not None else plt.gca()
  6. if color is None:
  7. color = ax._get_lines.color_cycle.next()
  8. ymin, ymax = yerr
  9. ax.plot(x, y, color=color)
  10. ax.fill_between(x, ymax, ymin, color=color, alpha=alpha_fill)
  11. def gen_generate(dim, l, mu = 5, la = 5, c = 0.5, iter=1000):
  12. axis = []
  13. resu = []
  14. resu_bars_mini = []
  15. resu_bars_maxi = []
  16. NB_IT = 8
  17. for i in range(80, 200, 25):
  18. results[i] = []
  19. axis.append(i)
  20. mini =10
  21. maxi = 0
  22. for j in range(NB_IT):
  23. os.system('./main '+str(l)+" "+str(i)+ " " + str(dim) + " "+str(iter)+ " "+ str(mu)+ " "+ str(la)+ " " + str(c) + " > res_genetic_i2"+str(dim))
  24. r = open("res_genetic_i2"+str(dim), "r")
  25. res = float(r.readline())
  26. mini = min(res, mini)
  27. maxi = max(res, maxi)
  28. results[i].append(res)
  29. resu.append(sum(results[i])/NB_IT)
  30. resu_bars_mini.append(mini)
  31. resu_bars_maxi.append(maxi)
  32. resu_bars = [resu_bars_mini, resu_bars_maxi]
  33. print results
  34. print axis
  35. print resu
  36. print resu_bars
  37. errorfill(axis, resu, resu_bars)
  38. dim = 2
  39. gen_generate(dim, 3, 5, 5, 0.5, 200)
  40. gen_generate(dim, 3, 5, 5, 0.5, 600)
  41. gen_generate(dim, 3, 5, 5, 0.5,1000)
  42. gen_generate(dim, 3, 5, 5, 0.5, 1200)
  43. gen_generate(dim, 3, 5, 5, 0.5, 1400)
  44. errorfill(axis, resu, resu_bars)
  45. plt.show()