|
1 | 1 | import pandas as pd |
| 2 | +from scipy.stats import linregress |
2 | 3 | import matplotlib.pyplot as plt |
3 | 4 |
|
4 | | -if __name__ == "__main__": |
5 | | - df = pd.read_csv("edge_stats.csv") |
| 5 | +out_directory = "graphs" |
6 | 6 |
|
| 7 | +def draw_edges(df, col, label): |
7 | 8 | x = df["edges"] |
| 9 | + y = df[f"{col} time (ms)"] |
| 10 | + plt.scatter(x, y, label=label) |
8 | 11 |
|
9 | | - plt.scatter(x, df["dfs time (ms)"], label="DFS") |
10 | | - plt.scatter(x, df["bfs time (ms)"], label="BFS") |
11 | | - plt.scatter(x, df["fat time (ms)"], label="Fattest path") |
| 12 | + slope, intercept, r_value, p_value, std_err = linregress(x, y) |
| 13 | + plt.plot(x, intercept + slope * x, 'r', label=f"Regressão linear (r={round(r_value,2)})") |
12 | 14 |
|
13 | | - plt.xlabel("Edge amount") |
14 | | - plt.ylabel("Time (ms)") |
| 15 | + plt.xlabel("Quantidade de arestas") |
| 16 | + plt.ylabel("Tempo (ms)") |
15 | 17 | plt.legend() |
16 | 18 |
|
17 | | - plt.savefig("edge_x_time_edges.png", format="png") |
| 19 | + plt.savefig(f"{out_directory}/edge_x_time_{col}.eps") |
18 | 20 | plt.clf() |
19 | 21 |
|
20 | | - plt.scatter(x, df["dfs vertices"], label="DFS") |
21 | | - plt.scatter(x, df["bfs vertices"], label="BFS") |
22 | | - plt.scatter(x, df["fat vertices"], label="Fattest path") |
| 22 | + y = df[f"{col} vertices"] |
| 23 | + plt.scatter(x, y, label=label) |
23 | 24 |
|
24 | | - plt.xlabel("Edge amount") |
25 | | - plt.ylabel("Vertices touched") |
| 25 | + slope, intercept, r_value, p_value, std_err = linregress(x, y) |
| 26 | + plt.plot(x, intercept + slope * x, 'r', label=f"Regressão linear (r={round(r_value,2)})") |
| 27 | + |
| 28 | + plt.xlabel("Quantidade de arestas") |
| 29 | + plt.ylabel("Vértices tocados") |
26 | 30 | plt.legend() |
27 | 31 |
|
28 | | - plt.savefig("vertices_touched_edges.png", format="png") |
| 32 | + plt.savefig(f"{out_directory}/vertices_touched_edges_{col}.eps") |
29 | 33 | plt.clf() |
30 | 34 |
|
31 | | - plt.scatter(x, df["dfs edges"], label="DFS") |
32 | | - plt.scatter(x, df["bfs edges"], label="BFS") |
33 | | - plt.scatter(x, df["fat edges"], label="Fattest path") |
| 35 | + y = df[f"{col} edges"] |
| 36 | + plt.scatter(x, y, label=label) |
34 | 37 |
|
35 | | - plt.xlabel("Edge amount") |
36 | | - plt.ylabel("Edges touched") |
| 38 | + slope, intercept, r_value, p_value, std_err = linregress(x, y) |
| 39 | + plt.plot(x, intercept + slope * x, 'r', label=f"Regressão linear (r={round(r_value,2)})") |
| 40 | + |
| 41 | + plt.xlabel("Quantidade de arestas") |
| 42 | + plt.ylabel("Arestas tocadas") |
37 | 43 | plt.legend() |
38 | 44 |
|
39 | | - plt.savefig("edges_touched_edges.png", format="png") |
| 45 | + plt.savefig(f"{out_directory}/edges_touched_edges_{col}.eps") |
40 | 46 | plt.clf() |
41 | 47 |
|
42 | | - df = pd.read_csv("max_flow_stats.csv") |
43 | | - |
| 48 | +def draw_flow(df, col, label): |
44 | 49 | x = df["max_flow"] |
| 50 | + y = df[f"{col} time (ms)"] |
| 51 | + plt.scatter(x, y, label=label) |
45 | 52 |
|
46 | | - plt.scatter(x, df["dfs time (ms)"], label="DFS") |
47 | | - plt.scatter(x, df["bfs time (ms)"], label="BFS") |
48 | | - plt.scatter(x, df["fat time (ms)"], label="Fattest path") |
| 53 | + slope, intercept, r_value, p_value, std_err = linregress(x, y) |
| 54 | + plt.plot(x, intercept + slope * x, 'r', label=f"Regressão linear (r={round(r_value,2)})") |
49 | 55 |
|
50 | | - plt.xlabel("Edge amount") |
| 56 | + plt.xlabel("Max flow") |
51 | 57 | plt.ylabel("Time (ms)") |
52 | 58 | plt.legend() |
53 | 59 |
|
54 | | - plt.savefig("edge_x_time_max_flow.png", format="png") |
| 60 | + plt.savefig(f"{out_directory}/max_flow_x_time_{col}.eps") |
55 | 61 | plt.clf() |
56 | 62 |
|
57 | | - plt.scatter(x, df["dfs vertices"], label="DFS") |
58 | | - plt.scatter(x, df["bfs vertices"], label="BFS") |
59 | | - plt.scatter(x, df["fat vertices"], label="Fattest path") |
| 63 | + y = df[f"{col} vertices"] |
| 64 | + plt.scatter(x, y, label=label) |
| 65 | + |
| 66 | + slope, intercept, r_value, p_value, std_err = linregress(x, y) |
| 67 | + plt.plot(x, intercept + slope * x, 'r', label=f"Regressão linear (r={round(r_value,2)})") |
60 | 68 |
|
61 | | - plt.xlabel("Edge amount") |
| 69 | + plt.xlabel("Max flow") |
62 | 70 | plt.ylabel("Vertices touched") |
63 | 71 | plt.legend() |
64 | 72 |
|
65 | | - plt.savefig("vertices_touched_max_flow.png", format="png") |
| 73 | + plt.savefig(f"{out_directory}/vertices_touched_max_flow_{col}.eps") |
66 | 74 | plt.clf() |
67 | 75 |
|
68 | | - plt.scatter(x, df["dfs edges"], label="DFS") |
69 | | - plt.scatter(x, df["bfs edges"], label="BFS") |
70 | | - plt.scatter(x, df["fat edges"], label="Fattest path") |
| 76 | + y = df[f"{col} edges"] |
| 77 | + plt.scatter(x, y, label=label) |
71 | 78 |
|
72 | | - plt.xlabel("Edge amount") |
| 79 | + slope, intercept, r_value, p_value, std_err = linregress(x, y) |
| 80 | + plt.plot(x, intercept + slope * x, 'r', label=f"Regressão linear (r={round(r_value,2)})") |
| 81 | + |
| 82 | + plt.xlabel("Max flow") |
73 | 83 | plt.ylabel("Edges touched") |
74 | 84 | plt.legend() |
75 | 85 |
|
76 | | - plt.savefig("edges_touched_max_flow.png", format="png") |
| 86 | + plt.savefig(f"{out_directory}/edges_touched_max_flow_{col}.eps") |
77 | 87 | plt.clf() |
78 | 88 |
|
| 89 | +if __name__ == "__main__": |
| 90 | + df = pd.read_csv("edge_stats.csv") |
| 91 | + |
| 92 | + samples = {"dfs": "DFS", "bfs": "BFS", "fat": "Fattest Path"} |
| 93 | + |
| 94 | + |
| 95 | + for col, label in samples.items(): |
| 96 | + draw_edges(df, col, label) |
| 97 | + |
| 98 | + df = pd.read_csv("max_flow_stats.csv") |
| 99 | + |
| 100 | + for col, label in samples.items(): |
| 101 | + draw_flow(df, col, label) |
0 commit comments