Skip to content

Commit

Permalink
feat: replace batch flag with draw flag, round2 distances, times and …
Browse files Browse the repository at this point in the history
…error, remove time per city measures
  • Loading branch information
Akhil-CM committed Apr 24, 2024
1 parent 9848acd commit fc87eef
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/bin
compile_commands.json
perf.*
CMakeLists.txt.*
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions Data/ALL_tsp/test5.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions DiscreteENN_TSP_table.csv
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions DiscreteENN_TSP_table.txt
Original file line number Diff line number Diff line change
@@ -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
32 changes: 18 additions & 14 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
Expand Down Expand Up @@ -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) };
Expand All @@ -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) };
Expand All @@ -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) };
Expand All @@ -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;
Expand Down Expand Up @@ -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<Value_t>(duration)/num_cities;
info.m_time = utils::getRound2(duration);
info.m_timePerCity = utils::getRound2(static_cast<Value_t>(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";
Expand Down
2 changes: 1 addition & 1 deletion until_fail_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# while "$@"; do :; done
count=0
while "$@"; do
while "$@" &> /dev/null; do
echo "-------------------------------------------"
echo "[Info]: Run #${count} currently in progress"
echo "-------------------------------------------"
Expand Down
15 changes: 15 additions & 0 deletions utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <iostream>
#include <string>
#include <cassert>
#include <cmath>
#include <optional>
#include <vector>
#include <algorithm>
Expand All @@ -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";
Expand Down

0 comments on commit fc87eef

Please sign in to comment.