diff --git a/DiscreteENN_TSP_table.csv b/DiscreteENN_TSP_table.csv index f095471..e5981b2 100644 --- a/DiscreteENN_TSP_table.csv +++ b/DiscreteENN_TSP_table.csv @@ -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 diff --git a/DiscreteENN_TSP_table.txt b/DiscreteENN_TSP_table.txt index b85eed6..d4548a2 100644 --- a/DiscreteENN_TSP_table.txt +++ b/DiscreteENN_TSP_table.txt @@ -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 diff --git a/plot_data.py b/plot_data.py index 75138e8..49e3477 100644 --- a/plot_data.py +++ b/plot_data.py @@ -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 @@ -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): @@ -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__": diff --git a/tsp_discrete_enn.hpp b/tsp_discrete_enn.hpp index 8609665..609c547 100644 --- a/tsp_discrete_enn.hpp +++ b/tsp_discrete_enn.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,7 @@ using TimeMicroS_t = std::chrono::microseconds; using TimeUnit_t = TimeMicroS_t; using TimePoint_t = std::chrono::steady_clock::time_point; const std::string& time_unit{ "us" }; +const std::string& pos_sep{ "sep" }; using namespace std::string_literals; using utils::ErrorBool, utils::ErrorMsg; @@ -449,6 +451,10 @@ inline bool hasIntersection(const City& cityA1, const City& cityA2, return false; // Doesn't fall in any of the above cases } +// typedef Indices_t Stack_t; +// typedef std::set Stack_t; +typedef std::set> Stack_t; + class DiscreteENN_TSP { public: @@ -458,7 +464,7 @@ class DiscreteENN_TSP { return m_cities; } - Indices_t& stack() + Stack_t& stack() { return m_stack; } @@ -501,39 +507,44 @@ class DiscreteENN_TSP std::size_t stackPopBack() { - const std::size_t result{ m_stack.back() }; - m_stack.pop_back(); + const Stack_t::const_iterator back{ --(m_stack.end()) }; + const std::size_t result{ *back }; + m_stack.erase(back); m_cities[result].on_stack = false; return result; } std::size_t stackPopAt(std::size_t index) { - const std::size_t result{ m_stack[index] }; - m_stack.erase(m_stack.begin() + index); + const Stack_t::const_iterator it{ std::next(m_stack.begin(), index) }; + const std::size_t result{ *it }; + m_stack.erase(it); m_cities[result].on_stack = false; return result; } void removeNode(std::size_t index) { + auto tmp = m_pattern; const std::size_t pos{ m_path[index] }; - const std::string& node_idx_str{ "|" + std::to_string(pos) + "|" }; + const std::string& node_idx_str{ pos_sep + std::to_string(pos) + + pos_sep }; std::string::size_type idx_erase = m_pattern.find(node_idx_str); m_pattern.erase(idx_erase, node_idx_str.length()); const Indices_t::iterator node_iter{ m_path.begin() + index }; m_path.erase(node_iter); m_cities[pos].on_stack = true; - m_stack.push_back(pos); + m_stack.insert(pos); } void addNode(std::size_t index, std::size_t pos) { - const std::string& node_idx_str{ "|" + std::to_string(m_path[index]) + - "|" }; - const std::string& node_idx_added_str{ "|" + std::to_string(pos) + - "|" }; + const std::string& node_idx_str{ + pos_sep + std::to_string(m_path[index]) + pos_sep + }; + const std::string& node_idx_added_str{ pos_sep + std::to_string(pos) + + pos_sep }; std::string::size_type idx_insert = m_pattern.find(node_idx_str); m_pattern.insert(idx_insert, node_idx_added_str); @@ -1020,22 +1031,23 @@ class DiscreteENN_TSP m_fromScratch = true; break; } - end = idx_remove_next == 0 ? - 0 : - properIndex(idx_remove); + end = idx_remove_next == 0 ? 0 : properIndex(idx_remove); start = properIndex(int(end) - 1); updateCost(start); updateCost(end); const auto erased = validateEdge(start, end); if (erased.err()) { utils::printErr( - "validateEdge failed with (" + std::to_string(start) + ", " + std::to_string(end) + - ") current path size " + std::to_string(m_path.size()), + "validateEdge failed with (" + std::to_string(start) + + ", " + std::to_string(end) + ") current path size " + + std::to_string(m_path.size()), "removeIntersectionEdge"); return IndexExp_t{ pos_erased, true }; } if (erased.has_value()) { - pos_erased = pos_erased.has_value() ? std::min(*pos_erased, erased.value()) : erased.opt(); + pos_erased = pos_erased.has_value() ? + std::min(*pos_erased, erased.value()) : + erased.opt(); } num_nodes = m_path.size(); idx = 0; @@ -1048,10 +1060,10 @@ class DiscreteENN_TSP IndexOpt_t pos_erased{ std::nullopt }; const auto [valid1, err1] = validateNode(start); if (err1) { - utils::printErr( - "first validateNode failed at " + std::to_string(start) + - " current path size " + std::to_string(m_path.size()), - "validateEdgeNodes"); + utils::printErr("first validateNode failed at " + + std::to_string(start) + " current path size " + + std::to_string(m_path.size()), + "validateEdgeNodes"); return IndexExp_t{ pos_erased, true }; } if (valid1) { @@ -1075,14 +1087,18 @@ class DiscreteENN_TSP updateCost(end); const auto erased1 = validateEdge(start, end); if (erased1.err()) { - utils::printErr( - "validateEdge failed with (" + std::to_string(start) + ", " + std::to_string(end) + - ") current path size " + std::to_string(m_path.size()), - "validateEdgeNodes"); + utils::printErr("validateEdge failed with (" + + std::to_string(start) + ", " + + std::to_string(end) + + ") current path size " + + std::to_string(m_path.size()), + "validateEdgeNodes"); return IndexExp_t{ pos_erased, true }; } if (erased1.has_value()) { - pos_erased = pos_erased.has_value() ? std::min(*pos_erased, erased1.value()) : erased1.opt(); + pos_erased = pos_erased.has_value() ? + std::min(*pos_erased, erased1.value()) : + erased1.opt(); } } } else { @@ -1098,13 +1114,16 @@ class DiscreteENN_TSP const auto erased2 = validateEdge(start, end); if (erased2.err()) { utils::printErr( - "validateEdge failed with (" + std::to_string(start) + ", " + std::to_string(end) + - ") current path size " + std::to_string(m_path.size()), + "validateEdge failed with (" + std::to_string(start) + + ", " + std::to_string(end) + ") current path size " + + std::to_string(m_path.size()), "validateEdgeNodes"); return IndexExp_t{ pos_erased, true }; } if (erased2.has_value()) { - pos_erased = pos_erased.has_value() ? std::min(*pos_erased, erased2.value()) : erased2.opt(); + pos_erased = pos_erased.has_value() ? + std::min(*pos_erased, erased2.value()) : + erased2.opt(); } } return IndexExp_t{ pos_erased, false }; @@ -1116,7 +1135,7 @@ class DiscreteENN_TSP const std::size_t pos_end{ m_path[end] }; const City& city_start{ m_cities[pos_start] }; const City& city_end{ m_cities[pos_end] }; - for (std::size_t idx{0}; idx != m_path.size();) { + for (std::size_t idx{ 0 }; idx != m_path.size();) { if (m_fromScratch or city_start.on_stack or city_end.on_stack) { break; } @@ -1138,20 +1157,23 @@ class DiscreteENN_TSP updateCost(end); const auto erased = validateEdge(start, end); if (erased.err()) { - utils::printErr( - "validateEdge failed with (" + std::to_string(start) + ", " + std::to_string(end) + - ") current path size " + std::to_string(m_path.size()), - "validateWithEdge"); + utils::printErr("validateEdge failed with (" + + std::to_string(start) + ", " + + std::to_string(end) + + ") current path size " + + std::to_string(m_path.size()), + "validateWithEdge"); return IndexExp_t{ pos_erased, true }; } if (erased.has_value()) { - pos_erased = pos_erased.has_value() ? std::min(*pos_erased, erased.value()) : erased.opt(); + pos_erased = pos_erased.has_value() ? + std::min(*pos_erased, erased.value()) : + erased.opt(); } idx = 0; } else { ++idx; } - } return IndexExp_t{ pos_erased, false }; } @@ -1162,41 +1184,54 @@ class DiscreteENN_TSP const std::size_t pos_end{ m_path[end] }; const auto erased1 = removeIntersectionEdge(start, end); if (erased1.err()) { - utils::printErr( - "removeIntersectionEdge failed with (" + std::to_string(start) + ", " + std::to_string(end) + - ") current path size " + std::to_string(m_path.size()), - "validateEdge"); + utils::printErr("removeIntersectionEdge failed with (" + + std::to_string(start) + ", " + + std::to_string(end) + ") current path size " + + std::to_string(m_path.size()), + "validateEdge"); return IndexExp_t{ pos_erased, true }; } if (erased1.has_value()) { - pos_erased = pos_erased.has_value() ? std::min(*pos_erased, erased1.value()) : erased1.opt(); + pos_erased = pos_erased.has_value() ? + std::min(*pos_erased, erased1.value()) : + erased1.opt(); } - if ((not m_fromScratch) and (not m_cities[pos_start].on_stack) and (not m_cities[pos_end].on_stack)) { + if ((not m_fromScratch) and (not m_cities[pos_start].on_stack) and + (not m_cities[pos_end].on_stack)) { auto [start_new, end_new] = findEdge(pos_start, pos_end); const auto erased2 = validateEdgeNodes(start_new, end_new); if (erased2.err()) { - utils::printErr( - "validateEdgeNodes failed with (" + std::to_string(start_new) + ", " + std::to_string(end_new) + - ") current path size " + std::to_string(m_path.size()), - "validateEdge"); + utils::printErr("validateEdgeNodes failed with (" + + std::to_string(start_new) + ", " + + std::to_string(end_new) + + ") current path size " + + std::to_string(m_path.size()), + "validateEdge"); return IndexExp_t{ pos_erased, true }; } if (erased2.has_value()) { - pos_erased = pos_erased.has_value() ? std::min(*pos_erased, erased2.value()) : erased2.opt(); + pos_erased = pos_erased.has_value() ? + std::min(*pos_erased, erased2.value()) : + erased2.opt(); } } - if ((not m_fromScratch) and (not m_cities[pos_start].on_stack) and (not m_cities[pos_end].on_stack)) { + if ((not m_fromScratch) and (not m_cities[pos_start].on_stack) and + (not m_cities[pos_end].on_stack)) { auto [start_new, end_new] = findEdge(pos_start, pos_end); const auto erased3 = validateWithEdge(start_new, end_new); if (erased3.err()) { - utils::printErr( - "validateEdgeNodes failed with (" + std::to_string(start_new) + ", " + std::to_string(end_new) + - ") current path size " + std::to_string(m_path.size()), - "validateEdge"); + utils::printErr("validateEdgeNodes failed with (" + + std::to_string(start_new) + ", " + + std::to_string(end_new) + + ") current path size " + + std::to_string(m_path.size()), + "validateEdge"); return IndexExp_t{ pos_erased, true }; } if (erased3.has_value()) { - pos_erased = pos_erased.has_value() ? std::min(*pos_erased, erased3.value()) : erased3.opt(); + pos_erased = pos_erased.has_value() ? + std::min(*pos_erased, erased3.value()) : + erased3.opt(); } } return IndexExp_t{ pos_erased, false }; @@ -1295,11 +1330,12 @@ class DiscreteENN_TSP } return; } - m_stack.reserve(num_cities); + // m_stack.reserve(num_cities); [[maybe_unused]] const std::size_t end{ num_cities - 1 }; for (std::size_t idx{ 0 }; idx != num_cities; ++idx) { - m_stack.push_back(end - idx); + // m_stack.push_back(end - idx); // m_stack.push_back(idx); + m_stack.insert(idx); } } @@ -1310,11 +1346,11 @@ class DiscreteENN_TSP } const std::size_t pos{ stackPopBack() }; m_path.push_back(pos); - m_pattern = "|" + std::to_string(pos) + "|"; + m_pattern = pos_sep + std::to_string(pos) + pos_sep; for (int idx{ 1 }; idx != m_initialSize; ++idx) { const std::size_t pos{ stackPopBack() }; m_path.push_back(pos); - m_pattern += "|" + std::to_string(pos) + "|"; + m_pattern += pos_sep + std::to_string(pos) + pos_sep; } if (m_path.size() == 2) { m_fromScratch = true; @@ -1329,7 +1365,7 @@ class DiscreteENN_TSP { typedef std::uniform_int_distribution distrib_t; [[maybe_unused]] const std::size_t num_cities = m_cities.size(); - // distrib_t distrib(0, num_cities - 1); + distrib_t distrib(0, num_cities - 1); std::unordered_set pattern_hashes; // [[maybe_unused]] bool flip = false; // [[maybe_unused]] bool print_pos{ false }; @@ -1405,19 +1441,23 @@ class DiscreteENN_TSP const auto erased1 = validateEdge(idx_prev, idx_added); if (erased1.err()) { utils::printErr( - "validateEdge failed with (" + std::to_string(idx_prev) + ", " + std::to_string(idx_added) + + "validateEdge failed with (" + std::to_string(idx_prev) + + ", " + std::to_string(idx_added) + ") current path size " + std::to_string(m_path.size()), "run"); return false; } - if (not m_fromScratch and (not m_cities[pos_start].on_stack) and (not m_cities[pos_end].on_stack)) { + if (not m_fromScratch and (not m_cities[pos_start].on_stack) and + (not m_cities[pos_end].on_stack)) { const auto [start, end] = findEdge(pos_start, pos_end); const auto erased2 = validateEdge(start, end); if (erased2.err()) { - utils::printErr( - "validateEdge failed with (" + std::to_string(start) + ", " + std::to_string(end) + - ") current path size " + std::to_string(m_path.size()), - "run"); + utils::printErr("validateEdge failed with (" + + std::to_string(start) + ", " + + std::to_string(end) + + ") current path size " + + std::to_string(m_path.size()), + "run"); return false; } } @@ -1522,12 +1562,12 @@ class DiscreteENN_TSP } if (not pattern_hashes.insert(m_pattern).second) { // print_pos = true; - // utils::printInfo( - // "Found repeating pattern. Randomize input node", "run"); - // utils::printInfo("Path progress " + - // std::to_string(m_path.size()) + "/" + - // std::to_string(num_cities), - // "run"); + utils::printInfo( + "Found repeating pattern. Randomize input node", "run"); + utils::printInfo("Path progress " + + std::to_string(m_path.size()) + "/" + + std::to_string(num_cities), + "run"); // if (flip) { // distrib.param(distrib_t::param_type(0, m_path.size() - 1)); // } else { @@ -1535,15 +1575,15 @@ class DiscreteENN_TSP // num_cities - 1)); // } // flip = not flip; - // distrib.param(distrib_t::param_type(0, stack_size - 1)); - // const int idx_rand{ distrib(gen) }; + distrib.param(distrib_t::param_type(0, stack_size - 1)); + const int idx_rand{ distrib(gen) }; // const int idx_rand = stack_size - 2; - const int idx_rand = 0; + // const int idx_rand = 0; + pos = stackPopAt(idx_rand); utils::printInfo("New starting point " + std::to_string(idx_rand) + " with city " + - std::to_string(m_stack[idx_rand]), + std::to_string(pos), "run"); - pos = stackPopAt(idx_rand); continue; #if (TSP_DEBUG_PRINT > 0) std::cout << ("\n[Debug] (run): drawPath started\n"); @@ -1592,7 +1632,7 @@ class DiscreteENN_TSP std::string m_name; std::string m_pattern; Cities_t m_cities; - Indices_t m_stack; + Stack_t m_stack; Indices_t m_path; };