forked from marcovarrone/advanced-algorithms-goldberg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotting_goldberg.py
57 lines (44 loc) · 1.42 KB
/
plotting_goldberg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import matplotlib.pyplot as plt
DIFFERENT_NODES = 9
SAMPLES = 35
#plotting Goldberg implementation
file = open("complexity_data/temporal_complexity_data_goldberg_4 edges for each vertex_10-90_nodes", "r")
nodes = []
edges = []
seconds = []
result = []
file = file.read()
for i in range(0, DIFFERENT_NODES):
local_seconds = []
first_iteration = True
for sample in range(0, SAMPLES):
#to find the nodes
file = file[file.find(" con ") + len(" con "):]
if first_iteration:
nodes += [file[:3]]
#to find the edges
file = file[file.find(" e ") + len(" e "):]
x = file[0:file.find(" archi")]
if first_iteration:
edges += [x]
first_iteration = False
file = file[file.find("in"):]
local_seconds += [float(file[3:file.find(" sec")])]
#average case
seconds += [sum(local_seconds) / float(len(local_seconds))]
#max case
#seconds += [max(local_seconds)]
first_iteration = True
print(nodes)
print(edges)
print(seconds)
for i in range(0, DIFFERENT_NODES):
result += [float(seconds[i]) / float(nodes[i]) ** 2 * float(edges[i])]
f = plt.figure()
f = plt.figure()
plt.xlabel('Time')
plt.ylabel('Time/(n^2 * m)')
plt.title("Temporal complexity Goldberg implementation")
plt.plot(seconds, result)
plt.show()
f.savefig("Complexity_graphs/temporal_complexity_Goldberg_max_case_4_edges_per_vertex.pdf", bbox_inches='tight')