Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import os
- import matplotlib.pyplot as plt
- maior_sub = []
- prob = ['0.01/', '0.110000/', '0.210000/', '0.310000/', '0.410000/', '0.510000/', '0.610000/', '0.710000/', '0.810000/', '0.910000/']
- def format_n(string):
- aux_str = ""
- for i in range(len(string)):
- if i > 4 and i < (len(string) - 4):
- aux_str += string[i]
- return aux_str
- def format_prob(string):
- return string[:-1]
- def sort_prob(dic):
- new_dic = {}
- for key, value in sorted(dic.items()):
- print(key, value)
- new_dic.update({key: value})
- return new_dic
- def get_by_algorithm(algo):
- list_dicts = []
- for j in range(10):
- dir = "/home/tiago/Desktop/MEI/Assigment1/data/output1/" + algo + "/" + prob[j]
- arr = sorted(os.listdir(dir))
- print(">>> prob: " + str(format_prob(prob[j])))
- prob_dict = {}
- for i in range(10):
- file = dir + arr[i]
- with open(file) as csv_file:
- line = 0
- data = csv.reader(csv_file)
- for row in data:
- line += 1
- if line == 4:
- prob_dict.update({int(format_n(arr[i])): int(row[0])})
- prob_dict = sort_prob(prob_dict)
- print(prob_dict.keys())
- print(prob_dict.values())
- list_dicts.append(prob_dict)
- for i in range(10):
- #print(list_dicts[i].keys(), list_dicts[i].values())
- plt.plot(prob_dict.keys(), prob_dict.values(), label=i)
- plt.legend()
- plt.show()
- '''
- plt.title("["+algo+"] Gráfico de sub-sequencia maior com prob: " + str(format_prob(prob[j])))
- plt.xlabel('Nº elementos')
- plt.ylabel('Maior sub-sequência')
- '''
- def main():
- get_by_algorithm("bubble")
- get_by_algorithm("insertion")
- get_by_algorithm("merge")
- get_by_algorithm("quick")
- #plt.plot([0.1, 0.2, 0.3, 0.4], [1, 2, 3, 4], label='first plot')
- #plt.plot([0.1, 0.2, 0.3, 0.4], [1, 4, 9, 16], label='second plot')
- #plt.legend()
- #plt.show()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement