-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: plot_data.py to compare results from paper and current
- Loading branch information
Showing
6 changed files
with
183 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,1.580000,255.000000,4.900000,7661.009766,7542.000000 | ||
st70,70,2.170000,661.000000,9.440000,689.640015,675.000000 | ||
eil76,76,4.850000,741.000000,9.750000,564.099976,538.000000 | ||
pr76,76,2.490000,1051.000000,13.830000,110850.609375,108159.000000 | ||
kroA100,100,3.750000,1695.000000,16.950001,22080.689453,21282.000000 | ||
kroC100,100,3.170000,1591.000000,15.910000,21405.820312,20749.000000 | ||
kroD100,100,6.780000,1609.000000,16.090000,22737.619141,21294.000000 | ||
rd100,100,8.360000,1675.000000,16.750000,8571.240234,7910.000000 | ||
eil101,101,6.060000,2053.000000,20.330000,667.119995,629.000000 | ||
lin105,105,6.090000,1564.000000,14.900000,15254.559570,14379.000000 | ||
ch130,130,7.320000,3135.000000,24.120001,6557.279785,6110.000000 | ||
ch150,150,4.270000,6040.000000,40.270000,6806.850098,6528.000000 | ||
tsp225,225,4.060000,18750.000000,83.330002,4074.899902,3916.000000 | ||
a280,280,7.400000,32272.000000,115.260002,2769.820068,2579.000000 | ||
pcb442,442,10.520000,137540.984375,311.179993,56120.769531,50778.000000 | ||
pr1002,1002,7.580000,1523460.000000,1520.420044,278676.968750,259045.000000 | ||
pr2392,2392,10.000000,32860496.000000,13737.669922,415825.000000,378032.000000 | ||
name,points,error,time(us),time per city(us),distance,optimal_distance | ||
berlin52,52,5.720000,250.000000,4.810000,7973.629883,7542.000000 | ||
st70,70,4.030000,494.000000,7.060000,702.210022,675.000000 | ||
eil76,76,6.100000,755.000000,9.930000,570.799988,538.000000 | ||
pr76,76,4.440000,765.000000,10.070000,112965.250000,108159.000000 | ||
kroA100,100,3.480000,1576.000000,15.760000,22022.210938,21282.000000 | ||
kroC100,100,4.320000,1349.000000,13.490000,21645.830078,20749.000000 | ||
kroD100,100,3.870000,2084.000000,20.840000,22118.060547,21294.000000 | ||
rd100,100,2.960000,1385.000000,13.850000,8143.919922,7910.000000 | ||
eil101,101,5.490000,1976.000000,19.559999,663.530029,629.000000 | ||
lin105,105,5.900000,1765.000000,16.809999,15227.559570,14379.000000 | ||
ch130,130,5.600000,3071.000000,23.620001,6451.919922,6110.000000 | ||
ch150,150,9.550000,5407.000000,36.049999,7151.419922,6528.000000 | ||
tsp225,225,4.660000,19827.000000,88.120003,4098.509766,3916.000000 | ||
a280,280,7.160000,36695.000000,131.050003,2763.530029,2579.000000 | ||
pcb442,442,7.860000,132595.000000,299.989990,54771.109375,50778.000000 | ||
pr1002,1002,8.100000,1413649.000000,1410.829956,280030.656250,259045.000000 | ||
pr2392,2392,10.050000,22980268.000000,9607.139648,416033.687500,378032.000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 1.580000 255.000000 4.900000 7661.009766 7542.000000 | ||
st70 70 2.170000 661.000000 9.440000 689.640015 675.000000 | ||
eil76 76 4.850000 741.000000 9.750000 564.099976 538.000000 | ||
pr76 76 2.490000 1051.000000 13.830000 110850.609375 108159.000000 | ||
kroA100 100 3.750000 1695.000000 16.950001 22080.689453 21282.000000 | ||
kroC100 100 3.170000 1591.000000 15.910000 21405.820312 20749.000000 | ||
kroD100 100 6.780000 1609.000000 16.090000 22737.619141 21294.000000 | ||
rd100 100 8.360000 1675.000000 16.750000 8571.240234 7910.000000 | ||
eil101 101 6.060000 2053.000000 20.330000 667.119995 629.000000 | ||
lin105 105 6.090000 1564.000000 14.900000 15254.559570 14379.000000 | ||
ch130 130 7.320000 3135.000000 24.120001 6557.279785 6110.000000 | ||
ch150 150 4.270000 6040.000000 40.270000 6806.850098 6528.000000 | ||
tsp225 225 4.060000 18750.000000 83.330002 4074.899902 3916.000000 | ||
a280 280 7.400000 32272.000000 115.260002 2769.820068 2579.000000 | ||
pcb442 442 10.520000 137540.984375 311.179993 56120.769531 50778.000000 | ||
pr1002 1002 7.580000 1523460.000000 1520.420044 278676.968750 259045.000000 | ||
pr2392 2392 10.000000 32860496.000000 13737.669922 415825.000000 378032.000000 | ||
berlin52 52 5.720000 250.000000 4.810000 7973.629883 7542.000000 | ||
st70 70 4.030000 494.000000 7.060000 702.210022 675.000000 | ||
eil76 76 6.100000 755.000000 9.930000 570.799988 538.000000 | ||
pr76 76 4.440000 765.000000 10.070000 112965.250000 108159.000000 | ||
kroA100 100 3.480000 1576.000000 15.760000 22022.210938 21282.000000 | ||
kroC100 100 4.320000 1349.000000 13.490000 21645.830078 20749.000000 | ||
kroD100 100 3.870000 2084.000000 20.840000 22118.060547 21294.000000 | ||
rd100 100 2.960000 1385.000000 13.850000 8143.919922 7910.000000 | ||
eil101 101 5.490000 1976.000000 19.559999 663.530029 629.000000 | ||
lin105 105 5.900000 1765.000000 16.809999 15227.559570 14379.000000 | ||
ch130 130 5.600000 3071.000000 23.620001 6451.919922 6110.000000 | ||
ch150 150 9.550000 5407.000000 36.049999 7151.419922 6528.000000 | ||
tsp225 225 4.660000 19827.000000 88.120003 4098.509766 3916.000000 | ||
a280 280 7.160000 36695.000000 131.050003 2763.530029 2579.000000 | ||
pcb442 442 7.860000 132595.000000 299.989990 54771.109375 50778.000000 | ||
pr1002 1002 8.100000 1413649.000000 1410.829956 280030.656250 259045.000000 | ||
pr2392 2392 10.050000 22980268.000000 9607.139648 416033.687500 378032.000000 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,157 @@ | ||
import numpy as np | ||
import math | ||
import os | ||
from os import path as osPath | ||
from matplotlib import pyplot as plt | ||
import pandas as pd | ||
|
||
DATA_DIR = os.getcwd() | ||
DATA_FILENAME = "./enn_tsp_data.csv" | ||
DATA_FILENAME1 = "./enn_tsp_data.csv" | ||
DATA_FILENAME2 = "./DiscreteENN_TSP_table.csv" | ||
|
||
DATA_FILE = osPath.join(DATA_DIR, DATA_FILENAME) | ||
DATA_FILE1 = osPath.join(DATA_DIR, DATA_FILENAME1) | ||
DATA_FILE2 = osPath.join(DATA_DIR, DATA_FILENAME2) | ||
|
||
def plotData(data, load_data: bool, sequence: bool): | ||
data = np.loadtxt(data, delimiter=',') if load_data else data | ||
# data = np.genfromtxt(data, delimiter=',') if load_data else data | ||
def plotData(data_file, use_pandas: bool, sequence: bool): | ||
time_str = "$\mu$s" | ||
show_grid = False | ||
|
||
if data.shape[1] < 2: | ||
if use_pandas: | ||
color = "red" | ||
data = pd.read_csv(data_file) | ||
# print(f"Pandas dataframe is:\n{data}") | ||
# exit(1) | ||
x = data.iloc[:, 1].to_numpy() | ||
y = data.iloc[:, 3].to_numpy() | ||
x_labels = (data.iloc[:, 1].to_numpy()).astype(int) # First column | ||
# xy_pd = pd.DataFrame({"x" : x, "y": y}) | ||
# print(f"Pandas dataframe is:\n{data}\nx and y are:\n{xy_pd}") | ||
# exit(1) | ||
else: | ||
color = "blue" | ||
data = np.loadtxt(data_file, delimiter=',') | ||
# data = np.genfromtxt(data_file, delimiter=',') | ||
if data.shape[1] < 2: | ||
print(f"[Error] (plotData): Data without two columns cannot be used for plotting x and y.") | ||
exit(1) | ||
x = data[:, 0] # First column | ||
y = data[:, 1] * 1e6 # Second column | ||
x_labels = data[:, 0].astype(int) # First column | ||
|
||
y1 = y/x | ||
y2 = y/(x*x) | ||
y3 = y/(x*np.log(x)) | ||
if sequence: | ||
x = np.arange(1, len(x_labels) + 1) | ||
|
||
plt.figure(figsize=(10, 10)) # Optional: Adjusts the figure size | ||
plt.subplot(131) | ||
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.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.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 | ||
# 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') | ||
if use_pandas: | ||
plt.suptitle("Data from current implementation") | ||
else: | ||
plt.suptitle("Data from paper") | ||
plt.show() | ||
|
||
def plotDataBoth(data_file1, data_file2, sequence: bool): | ||
time_str = "$\mu$s" | ||
show_grid = False | ||
|
||
color1 = "blue" | ||
data1 = np.loadtxt(data_file1, delimiter=',') | ||
# data1 = np.genfromtxt(data_file1, delimiter=',') | ||
if data1.shape[1] < 2: | ||
print(f"[Error] (plotData): Data without two columns cannot be used for plotting x and y.") | ||
exit(1) | ||
x = data[:, 0] # First column | ||
y = data[:, 1] # Second column | ||
x1 = data1[:, 0] # First column | ||
y1 = data1[:, 1] * 1e6 # Second column | ||
x1_labels = data1[:, 0].astype(int) # First column | ||
|
||
color2 = "red" | ||
data2 = pd.read_csv(data_file2) | ||
x2 = data2.iloc[:, 1].to_numpy() | ||
y2 = data2.iloc[:, 3].to_numpy() | ||
x2_labels = (data2.iloc[:, 1].to_numpy()).astype(int) # First column | ||
|
||
print(f"{x}\t{y}") | ||
plt.figure(figsize=(10, 6)) # Optional: Adjusts the figure size | ||
plt.plot(x, y, marker='o', linestyle='-') # Adjust markers and lines as needed | ||
plt.title('Number of Cites vs Time (seconds)') | ||
plt.xlabel('Cities') # Adjust with actual column name or description | ||
plt.ylabel('Time (s)') # Adjust with actual column name or description | ||
if sequence: | ||
x_labels = data[:, 0] # First column | ||
x_labels = x1_labels | ||
x = np.arange(1, len(x_labels) + 1) | ||
else: | ||
x = x1 | ||
|
||
y1_1 = y1/x1 | ||
y1_2 = y1/(x1*x1) | ||
y1_3 = y1/(x1*np.log(x1)) | ||
|
||
y2_1 = y2/x2 | ||
y2_2 = y2/(x2*x2) | ||
y2_3 = y2/(x2*np.log(x2)) | ||
|
||
plt.figure(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.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') | ||
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.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') | ||
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.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) | ||
plt.grid(True) # Optional: Adds a grid | ||
plt.xticks(x, labels = x_labels, rotation='vertical') | ||
plt.show() | ||
|
||
if __name__ == "__main__": | ||
plotData(DATA_FILE, load_data = True, sequence = False) | ||
plotData(DATA_FILE1, False, sequence = True) | ||
plotData(DATA_FILE2, True, sequence = True) | ||
plotDataBoth(DATA_FILE1, DATA_FILE2, sequence = True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters