Skip to content

Commit

Permalink
feat: make a set implementation for stack
Browse files Browse the repository at this point in the history
  • Loading branch information
Akhil-CM committed Apr 28, 2024
1 parent b1bab19 commit 05fea67
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 134 deletions.
34 changes: 17 additions & 17 deletions DiscreteENN_TSP_table.csv
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name,points,error,time(us),time per city(us),distance,optimal_distance
berlin52,52,8.610000,88.000000,1.690000,8191.640137,7542.000000
st70,70,4.720000,192.000000,2.740000,706.890015,675.000000
eil76,76,5.760000,284.000000,3.740000,569.010010,538.000000
pr76,76,5.540000,171.000000,2.250000,114149.859375,108159.000000
kroA100,100,4.290000,271.000000,2.710000,22195.070312,21282.000000
kroC100,100,3.920000,322.000000,3.220000,21562.000000,20749.000000
kroD100,100,4.410000,339.000000,3.390000,22233.359375,21294.000000
rd100,100,6.930000,367.000000,3.670000,8458.240234,7910.000000
eil101,101,7.650000,376.000000,3.720000,677.090027,629.000000
lin105,105,3.940000,419.000000,3.990000,14945.750000,14379.000000
ch130,130,4.350000,547.000000,4.210000,6375.870117,6110.000000
ch150,150,6.230000,723.000000,4.820000,6934.439941,6528.000000
tsp225,225,5.100000,1611.000000,7.160000,4115.830078,3916.000000
a280,279,6.170000,2786.000000,9.990000,2738.070068,2579.000000
pcb442,442,6.720000,6590.000000,14.910000,54189.570312,50778.000000
pr1002,1002,8.620000,29981.000000,29.920000,281368.750000,259045.000000
pr2392,2392,9.290000,192723.000000,80.570000,413165.906250,378032.000000
berlin52,52,5.720000,159.000000,3.060000,7973.629883,7542.000000
st70,70,4.030000,238.000000,3.400000,702.210022,675.000000
eil76,76,6.100000,274.000000,3.610000,570.799988,538.000000
pr76,76,4.440000,204.000000,2.680000,112965.257812,108159.000000
kroA100,100,3.480000,528.000000,5.280000,22022.210938,21282.000000
kroC100,100,4.320000,359.000000,3.590000,21645.830078,20749.000000
kroD100,100,5.920000,558.000000,5.580000,22554.320312,21294.000000
rd100,100,2.960000,443.000000,4.430000,8143.919922,7910.000000
eil101,101,5.420000,582.000000,5.760000,663.059998,629.000000
lin105,105,3.860000,517.000000,4.920000,14933.759766,14379.000000
ch130,130,5.600000,693.000000,5.330000,6451.919922,6110.000000
ch150,150,6.210000,948.000000,6.320000,6933.390137,6528.000000
tsp225,225,4.660000,4462.000000,19.830000,4098.509766,3916.000000
a280,279,7.330000,2807.000000,10.060000,2768.139893,2579.000000
pcb442,442,7.820000,6795.000000,15.370000,54749.230469,50778.000000
pr1002,1002,7.480000,62663.000000,62.540001,278407.812500,259045.000000
pr2392,2392,8.310000,199357.000000,83.339996,409444.718750,378032.000000
34 changes: 17 additions & 17 deletions DiscreteENN_TSP_table.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name points error time(us) time per city(us) distance optimal_distance
berlin52 52 8.610000 88.000000 1.690000 8191.640137 7542.000000
st70 70 4.720000 192.000000 2.740000 706.890015 675.000000
eil76 76 5.760000 284.000000 3.740000 569.010010 538.000000
pr76 76 5.540000 171.000000 2.250000 114149.859375 108159.000000
kroA100 100 4.290000 271.000000 2.710000 22195.070312 21282.000000
kroC100 100 3.920000 322.000000 3.220000 21562.000000 20749.000000
kroD100 100 4.410000 339.000000 3.390000 22233.359375 21294.000000
rd100 100 6.930000 367.000000 3.670000 8458.240234 7910.000000
eil101 101 7.650000 376.000000 3.720000 677.090027 629.000000
lin105 105 3.940000 419.000000 3.990000 14945.750000 14379.000000
ch130 130 4.350000 547.000000 4.210000 6375.870117 6110.000000
ch150 150 6.230000 723.000000 4.820000 6934.439941 6528.000000
tsp225 225 5.100000 1611.000000 7.160000 4115.830078 3916.000000
a280 279 6.170000 2786.000000 9.990000 2738.070068 2579.000000
pcb442 442 6.720000 6590.000000 14.910000 54189.570312 50778.000000
pr1002 1002 8.620000 29981.000000 29.920000 281368.750000 259045.000000
pr2392 2392 9.290000 192723.000000 80.570000 413165.906250 378032.000000
berlin52 52 5.720000 159.000000 3.060000 7973.629883 7542.000000
st70 70 4.030000 238.000000 3.400000 702.210022 675.000000
eil76 76 6.100000 274.000000 3.610000 570.799988 538.000000
pr76 76 4.440000 204.000000 2.680000 112965.257812 108159.000000
kroA100 100 3.480000 528.000000 5.280000 22022.210938 21282.000000
kroC100 100 4.320000 359.000000 3.590000 21645.830078 20749.000000
kroD100 100 5.920000 558.000000 5.580000 22554.320312 21294.000000
rd100 100 2.960000 443.000000 4.430000 8143.919922 7910.000000
eil101 101 5.420000 582.000000 5.760000 663.059998 629.000000
lin105 105 3.860000 517.000000 4.920000 14933.759766 14379.000000
ch130 130 5.600000 693.000000 5.330000 6451.919922 6110.000000
ch150 150 6.210000 948.000000 6.320000 6933.390137 6528.000000
tsp225 225 4.660000 4462.000000 19.830000 4098.509766 3916.000000
a280 279 7.330000 2807.000000 10.060000 2768.139893 2579.000000
pcb442 442 7.820000 6795.000000 15.370000 54749.230469 50778.000000
pr1002 1002 7.480000 62663.000000 62.540001 278407.812500 259045.000000
pr2392 2392 8.310000 199357.000000 83.339996 409444.718750 378032.000000
54 changes: 30 additions & 24 deletions plot_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,23 @@ def plotData(data_file, use_pandas: bool, sequence: bool):
x = np.arange(1, len(x_labels) + 1)

plt.figure(figsize=(10, 10)) # Optional: Adjusts the figure size
plt.subplot(131)
plt.subplot(311)
plt.plot(x, y1, color=color, marker='o', linestyle='-.') # Adjust markers and lines as needed
plt.title(f"Time ({time_str}) / N")
plt.xlabel("Cities") # Adjust with actual column name or description
# plt.ylabel(f"Time ({time_str})") # Adjust with actual column name or description
plt.grid(show_grid) # Optional: Adds a grid
if sequence:
axis = plt.gca()
plt.xticks(x, labels = x_labels, rotation='vertical')
plt.subplot(132)
plt.xticks(x)
plt.subplot(312)
plt.plot(x, y2, color=color, marker='o', linestyle='-.') # Adjust markers and lines as needed
plt.title(f"Time ({time_str}) / $N^2$")
plt.xlabel('Cities') # Adjust with actual column name or description
# plt.ylabel(f"Time ({time_str})") # Adjust with actual column name or description
plt.grid(show_grid) # Optional: Adds a grid
if sequence:
axis = plt.gca()
plt.xticks(x, labels = x_labels, rotation='vertical')
plt.subplot(133)
plt.xticks(x)
plt.subplot(313)
plt.plot(x, y3, color=color, marker='o', linestyle='-.') # Adjust markers and lines as needed
plt.title(f"Time ({time_str}) / $N \cdot log(N)$")
plt.xlabel('Cities') # Adjust with actual column name or description
Expand All @@ -76,6 +74,7 @@ def plotData(data_file, use_pandas: bool, sequence: bool):
plt.suptitle("Data from current implementation")
else:
plt.suptitle("Data from paper")
plt.tight_layout()
plt.show()

def plotDataBoth(data_file1, data_file2, sequence: bool):
Expand Down Expand Up @@ -112,43 +111,50 @@ def plotDataBoth(data_file1, data_file2, sequence: bool):
y2_2 = y2/(x2*x2)
y2_3 = y2/(x2*np.log(x2))

plt.figure(figsize=(10, 10)) # Optional: Adjusts the figure size
fig, ax = plt.subplots(3, 1, figsize=(10, 10)) # Optional: Adjusts the figure size
print(f"{x}\n{y1_1}")
print(f"{x}\n{y2_1}")
plt.subplot(131)
plt.plot(x, y1_1, color=color1, marker='o', linestyle='-.') # Adjust markers and lines as needed
plt.plot(x, y2_1, color=color2, marker='o', linestyle='-.') # Adjust markers and lines as needed
plt.title(f"Time ({time_str}) / N")
plt.xlabel("Cities") # Adjust with actual column name or description
# plt.subplot(311)
ax[0].plot(x, y1_1, color=color1, label="Paper", marker='o', linestyle='-.') # Adjust markers and lines as needed
ax[0].plot(x, y2_1, color=color2, label="New implementation", marker='o', linestyle='-.') # Adjust markers and lines as needed
ax[0].set_title(f"Time ({time_str}) / N")
# plt.ylabel(f"Time ({time_str})") # Adjust with actual column name or description
plt.grid(show_grid) # Optional: Adds a grid
if sequence:
axis = plt.gca()
plt.xticks(x, labels = x_labels, rotation='vertical')
plt.xticks(x)
print(f"{x}\n{y1_2}")
print(f"{x}\n{y2_2}")
plt.subplot(132)
plt.plot(x, y1_2, color=color1, marker='o', linestyle='-.') # Adjust markers and lines as needed
plt.plot(x, y2_2, color=color2, marker='o', linestyle='-.') # Adjust markers and lines as needed
plt.title(f"Time ({time_str}) / $N^2$")
plt.xlabel('Cities') # Adjust with actual column name or description
# plt.subplot(312)
ax[1].plot(x, y1_2, color=color1, marker='o', linestyle='-.') # Adjust markers and lines as needed
ax[1].plot(x, y2_2, color=color2, marker='o', linestyle='-.') # Adjust markers and lines as needed
ax[1].set_title(f"Time ({time_str}) / $N^2$")
# plt.ylabel(f"Time ({time_str})") # Adjust with actual column name or description
plt.grid(show_grid) # Optional: Adds a grid
if sequence:
axis = plt.gca()
plt.xticks(x, labels = x_labels, rotation='vertical')
plt.xticks(x)
print(f"{x}\n{y1_3}")
print(f"{x}\n{y2_3}")
plt.subplot(133)
plt.plot(x, y1_3, color=color1, marker='o', linestyle='-.') # Adjust markers and lines as needed
plt.plot(x, y2_3, color=color2, marker='o', linestyle='-.') # Adjust markers and lines as needed
plt.title(f"Time ({time_str}) / $N \cdot log(N)$")
# plt.subplot(313)
ax[2].plot(x, y1_3, color=color1, marker='o', linestyle='-.') # Adjust markers and lines as needed
ax[2].plot(x, y2_3, color=color2, marker='o', linestyle='-.') # Adjust markers and lines as needed
ax[2].set_title(f"Time ({time_str}) / $N \cdot log(N)$")
plt.xlabel('Cities') # Adjust with actual column name or description
# plt.ylabel(f"Time ({time_str})") # Adjust with actual column name or description
plt.grid(show_grid) # Optional: Adds a grid
if sequence:
axis = plt.gca()
plt.xticks(x, labels = x_labels, rotation='vertical')
# plt.suptitle("Paper vs New implementation")
# lines_labels = [axis.get_legend_handles_labels() for axis in fig.axes]
# lines, labels = [sum(lol, []) for lol in zip(*lines_labels)]
# print(f"lines:\n{lines}\nlabels:\n{labels}")
# fig.legend(lines, labels)
handles, labels = ax[0].get_legend_handles_labels()
print(f"handles:\n{handles}\nlabels:\n{labels}")
fig.legend(handles, labels, loc='upper right', ncol=2)
plt.tight_layout()
plt.show()

if __name__ == "__main__":
Expand Down

0 comments on commit 05fea67

Please sign in to comment.