Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. import csv
  2. import os
  3. import matplotlib.pyplot as plt
  4.  
  5. maior_sub = []
  6.  
  7.  
  8. prob = ['0.01/', '0.110000/', '0.210000/', '0.310000/', '0.410000/', '0.510000/', '0.610000/', '0.710000/', '0.810000/', '0.910000/']
  9.  
  10.  
  11. def format_n(string):
  12. aux_str = ""
  13. for i in range(len(string)):
  14. if i > 4 and i < (len(string) - 4):
  15. aux_str += string[i]
  16.  
  17. return aux_str
  18.  
  19.  
  20. def format_prob(string):
  21. return string[:-1]
  22.  
  23.  
  24. def sort_prob(dic):
  25. new_dic = {}
  26. for key, value in sorted(dic.items()):
  27. print(key, value)
  28. new_dic.update({key: value})
  29.  
  30. return new_dic
  31.  
  32.  
  33. def get_by_algorithm(algo):
  34.  
  35. list_dicts = []
  36.  
  37. for j in range(10):
  38. dir = "/home/tiago/Desktop/MEI/Assigment1/data/output1/" + algo + "/" + prob[j]
  39. arr = sorted(os.listdir(dir))
  40.  
  41. print(">>> prob: " + str(format_prob(prob[j])))
  42.  
  43. prob_dict = {}
  44. for i in range(10):
  45.  
  46. file = dir + arr[i]
  47.  
  48. with open(file) as csv_file:
  49. line = 0
  50. data = csv.reader(csv_file)
  51. for row in data:
  52. line += 1
  53. if line == 4:
  54. prob_dict.update({int(format_n(arr[i])): int(row[0])})
  55.  
  56. prob_dict = sort_prob(prob_dict)
  57.  
  58. print(prob_dict.keys())
  59. print(prob_dict.values())
  60.  
  61. list_dicts.append(prob_dict)
  62.  
  63. for i in range(10):
  64. #print(list_dicts[i].keys(), list_dicts[i].values())
  65. plt.plot(prob_dict.keys(), prob_dict.values(), label=i)
  66. plt.legend()
  67.  
  68. plt.show()
  69. '''
  70.  
  71.  
  72. plt.title("["+algo+"] Gráfico de sub-sequencia maior com prob: " + str(format_prob(prob[j])))
  73. plt.xlabel('Nº elementos')
  74. plt.ylabel('Maior sub-sequência')
  75.  
  76. '''
  77.  
  78. def main():
  79. get_by_algorithm("bubble")
  80. get_by_algorithm("insertion")
  81. get_by_algorithm("merge")
  82. get_by_algorithm("quick")
  83.  
  84. #plt.plot([0.1, 0.2, 0.3, 0.4], [1, 2, 3, 4], label='first plot')
  85. #plt.plot([0.1, 0.2, 0.3, 0.4], [1, 4, 9, 16], label='second plot')
  86. #plt.legend()
  87. #plt.show()
  88.  
  89.  
  90. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement