-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplotting_flow.py
More file actions
86 lines (69 loc) · 2.58 KB
/
Copy pathplotting_flow.py
File metadata and controls
86 lines (69 loc) · 2.58 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import matplotlib.pyplot as plt
numNodes = []
durations1 = []
durations2 = []
durations3 = []
durations4 = []
threshold = -1
with open("duration.txt", "r") as file:
for line in file:
if threshold == -1:
threshold = int(line)
continue
# Splitting each line by comma
data = line.split(", ")
# Extracting numNodes and duration
numNodes.append(int(data[0].split(": ")[1]))
durations1.append(float(data[1].split(": ")[1].split()[0]))
with open("duration2.txt", "r") as file:
for line in file:
# Splitting each line by comma
data = line.split(", ")
# Extracting numNodes and duration
# numNodes.append(int(data[0].split(": ")[1]))
durations2.append(float(data[1].split(": ")[1].split()[0]))
with open("duration3.txt", "r") as file:
for line in file:
# Splitting each line by comma
data = line.split(", ")
# Extracting numNodes and duration
# numNodes.append(int(data[0].split(": ")[1]))
durations3.append(float(data[1].split(": ")[1].split()[0]))
with open("duration4.txt", "r") as file:
for line in file:
# Splitting each line by comma
data = line.split(", ")
# Extracting numNodes and duration
# numNodes.append(int(data[0].split(": ")[1]))
durations4.append(float(data[1].split(": ")[1].split()[0]))
plt.rcParams['font.size'] = 22
lw = 6
# Plotting the graph
plt.plot(numNodes, durations1, label="Ford Fulkerson", linestyle='dotted', linewidth=lw)
plt.plot(numNodes, durations2, label="Dinit's Algorithm (No DT)", linestyle='dashdot', linewidth=lw)
plt.plot(numNodes, durations3, label="Dinit's Algorithm (DT)", linestyle="solid", linewidth=lw)
plt.plot(numNodes, durations4, label="Dinit's Algorithm (DT Optimized)", linestyle="dashed", linewidth=lw)
plt.legend()
# Adding labels and title
plt.xlabel("Nodes")
plt.ylabel("Time (s)")
plt.title(f"Network Flow Algorithm Performance Comparison ({threshold}% edge probability)")
# Displaying the plot
plt.show()
# numNodes = []
# durations = []
# with open("duration2.txt", "r") as file:
# for line in file:
# # Splitting each line by comma
# data = line.split(", ")
# # Extracting numNodes and duration
# numNodes.append(int(data[0].split(": ")[1]))
# durations.append(float(data[1].split(": ")[1].split()[0]))
# # Plotting the graph
# plt.plot(numNodes, durations)
# # Adding labels and title
# plt.xlabel("nodes")
# plt.ylabel("time")
# plt.title("Dinic's Algorithm with Dynamic Trees")
# # Displaying the plot
# plt.show()