diff --git a/.gitignore b/.gitignore index 9a78d35..4b31b5e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /bin compile_commands.json perf.* +CMakeLists.txt.* diff --git a/CMakeLists.txt b/CMakeLists.txt index b15b566..27e9a76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_C_COMPILER "clang") +set(CMAKE_CXX_COMPILER "clang++") + # # we default to Release build type # if(NOT CMAKE_BUILD_TYPE) # set(CMAKE_BUILD_TYPE "Debug") @@ -24,7 +27,7 @@ include_directories( "${PROJECT_SOURCE_DIR}/include" ) # add_library(utilities OBJECT "${PROJECT_SOURCE_DIR}/src/utilities.cxx") # add the executable -add_executable(enn_tsp "${PROJECT_SOURCE_DIR}/main.cpp") +add_executable(enn_tsp "${PROJECT_SOURCE_DIR}/main.cpp" "${PROJECT_SOURCE_DIR}/tsp_discrete_enn.hpp" "${PROJECT_SOURCE_DIR}/utils.hpp") # Set compiler options for different build types target_compile_options(enn_tsp PRIVATE diff --git a/Data/ALL_tsp/test5.tsp b/Data/ALL_tsp/test5.tsp index 421bf4d..27ddc13 100644 --- a/Data/ALL_tsp/test5.tsp +++ b/Data/ALL_tsp/test5.tsp @@ -3,10 +3,10 @@ TYPE: TSP DIMENSION: 5 EDGE_WEIGHT_TYPE: EUC_2D NODE_COORD_SECTION -1 15.0 8.0 -2 35.0 8.0 -3 20.0 7.0 -4 30.0 7.0 -5 25.0 9.0 +1 24.0 30.0 +2 26.0 30.0 +3 23.0 37.0 +4 27.0 28.0 +5 25.0 35.0 EOF diff --git a/DiscreteENN_TSP_table.csv b/DiscreteENN_TSP_table.csv index d575a62..1fbd111 100644 --- a/DiscreteENN_TSP_table.csv +++ b/DiscreteENN_TSP_table.csv @@ -1,2 +1,2 @@ -name,points,error,time(us),time per city(us),time per city min(us),time per city max(us),distance,optimal_distance -pr1002,1002,6.932652,5975245.000000,5963.318359,340282346638528859811704183484516925440.000000,-1.000000,277003.687500,259045.000000 +name points error time(us) time per city(us) distance optimal_distance +tsp225,225,7.540000,64888.000000,288.390015,4211.290039,3916.000000 diff --git a/DiscreteENN_TSP_table.txt b/DiscreteENN_TSP_table.txt index 531804f..d0aff4c 100644 --- a/DiscreteENN_TSP_table.txt +++ b/DiscreteENN_TSP_table.txt @@ -1,2 +1,2 @@ -name points error time(us) time per city(us) time per city min(us) time per city max(us) distance optimal_distance -pr1002 1002 6.932652 5975245.000000 5963.318359 340282346638528859811704183484516925440.000000 -1.000000 277003.687500 259045.000000 +name points error time(us) time per city(us) distance optimal_distance +tsp225 225 7.540000 64888.000000 288.390015 4211.290039 3916.000000 diff --git a/main.cpp b/main.cpp index a944ff2..bdba684 100644 --- a/main.cpp +++ b/main.cpp @@ -48,7 +48,7 @@ int main(int argc, char** argv) const bool single_input{ utils::vectContains(std::string{ "--single" }, args) }; - const bool draw_path{ not utils::vectContains(std::string{ "--batch" }, + const bool draw_path{ utils::vectContains(std::string{ "--draw" }, args) }; const bool draw_coords{ utils::vectContains(std::string{ "--show-coords" }, args) }; @@ -117,9 +117,13 @@ int main(int argc, char** argv) }; const auto error = std::abs(info.m_distance - optimal_info.m_distance) / optimal_info.m_distance; - info.m_error = error*100; + info.m_error = utils::getRound2(error*100); + info.m_distance = utils::getRound2(info.m_distance); + optimal_info.m_distance = utils::getRound2(optimal_info.m_distance); } - utils::printInfo("name\tpoints\terror\ttime(" + time_unit + ")\ttime per city(" + time_unit + ")\ttime per city min(" + time_unit + ")\ttime per city max(" + time_unit + ")\tdistance\toptimal_distance\n"); + // const std::string& table_header{ "name\tpoints\terror\ttime(" + time_unit + ")\ttime per city(" + time_unit + ")\ttime per city min(" + time_unit + ")\ttime per city max(" + time_unit + ")\tdistance\toptimal_distance" }; + const std::string& table_header{ "name\tpoints\terror\ttime(" + time_unit + ")\ttime per city(" + time_unit + ")\tdistance\toptimal_distance" }; + utils::printInfo(table_header); for (auto it{ optimal_infos.begin() }; it != optimal_infos.end(); ++it) { TSPInfo& opt_info{ *it }; int info_pos{ utils::vectFind(opt_info, infos) }; @@ -135,13 +139,13 @@ int main(int argc, char** argv) std::to_string(info.m_error) + "\t" + std::to_string(info.m_time) + "\t" + std::to_string(info.m_timePerCity) + "\t" + - std::to_string(info.m_timePerCityMin) + "\t" + - std::to_string(info.m_timePerCityMax) + "\t" + + // std::to_string(info.m_timePerCityMin) + "\t" + + // std::to_string(info.m_timePerCityMax) + "\t" + std::to_string(info.m_distance) + "\t" + std::to_string(opt_info.m_distance)); } std::ofstream table_file{ "DiscreteENN_TSP_table.txt" }; - table_file << "name\tpoints\terror\ttime(" + time_unit + ")\ttime per city(" + time_unit + ")\ttime per city min(" + time_unit + ")\ttime per city max(" + time_unit + ")\tdistance\toptimal_distance\n"; + table_file << table_header << std::endl; for (auto it{ optimal_infos.begin() }; it != optimal_infos.end(); ++it) { TSPInfo& opt_info{ *it }; int info_pos{ utils::vectFind(opt_info, infos) }; @@ -157,15 +161,15 @@ int main(int argc, char** argv) std::to_string(info.m_error) + "\t" + std::to_string(info.m_time) + "\t" + std::to_string(info.m_timePerCity) + "\t" + - std::to_string(info.m_timePerCityMin) + "\t" + - std::to_string(info.m_timePerCityMax) + "\t" + + // std::to_string(info.m_timePerCityMin) + "\t" + + // std::to_string(info.m_timePerCityMax) + "\t" + std::to_string(info.m_distance) + "\t" + std::to_string(opt_info.m_distance)) << std::endl; } table_file.close(); std::ofstream csv_file{ "DiscreteENN_TSP_table.csv" }; - csv_file << "name,points,error,time(" + time_unit + "),time per city(" + time_unit + "),time per city min(" + time_unit + "),time per city max(" + time_unit + "),distance,optimal_distance\n"; + csv_file << table_header << std::endl; for (auto it{ optimal_infos.begin() }; it != optimal_infos.end(); ++it) { TSPInfo& opt_info{ *it }; int info_pos{ utils::vectFind(opt_info, infos) }; @@ -181,8 +185,8 @@ int main(int argc, char** argv) std::to_string(info.m_error) + "," + std::to_string(info.m_time) + "," + std::to_string(info.m_timePerCity) + "," + - std::to_string(info.m_timePerCityMin) + "," + - std::to_string(info.m_timePerCityMax) + "," + + // std::to_string(info.m_timePerCityMin) + "," + + // std::to_string(info.m_timePerCityMax) + "," + std::to_string(info.m_distance) + "," + std::to_string(opt_info.m_distance)) << std::endl; @@ -385,10 +389,10 @@ int runPipelineSingle(TSPInfo& info, const stdfs::path& data_path, info.m_name = filename; info.m_distance = dist; info.m_points = num_cities; - info.m_time = duration; - info.m_timePerCity = static_cast(duration)/num_cities; + info.m_time = utils::getRound2(duration); + info.m_timePerCity = utils::getRound2(static_cast(duration)/num_cities); // info.m_timePerIter = enn_tsp.timePerCity(); - std::tie(info.m_timePerCityMin, info.m_timePerCityMax) = enn_tsp.timePerCityMinMax(); + // std::tie(info.m_timePerCityMin, info.m_timePerCityMax) = enn_tsp.timePerCityMinMax(); std::cout << "\n" + utils::Line_Str + "\n"; std::cout << "[Info]: Total distance is : " << dist << '\n'; std::cout << utils::Line_Str + "\n"; diff --git a/until_fail_run.sh b/until_fail_run.sh index 5b96c53..921fa4a 100644 --- a/until_fail_run.sh +++ b/until_fail_run.sh @@ -2,7 +2,7 @@ # while "$@"; do :; done count=0 -while "$@"; do +while "$@" &> /dev/null; do echo "-------------------------------------------" echo "[Info]: Run #${count} currently in progress" echo "-------------------------------------------" diff --git a/utils.hpp b/utils.hpp index e0fbab4..e52dbe3 100644 --- a/utils.hpp +++ b/utils.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,20 @@ inline bool isEqual(float a, float b) return std::abs(a - b) < epsilonf; } +inline float getRound2(float value) +{ + const float round1{ std::round(value * 1000.f) }; + const float round2{ std::round(round1/10.f) }; + return (round2/100.f); +} + +inline float getRoundN(float value, int places) +{ + const float round1 = std::round(value * std::pow(10.f, places+1)); + const float round2{ std::round(round1/10.f) }; + return (round2/std::pow(10.f, places)); +} + // Console write related helpers const std::string Line_Str = std::string{}.assign(30, '-'); const std::string Whitespace_Str = " \n\r\t\f\v";