Skip to content

Commit

Permalink
feat: add CMakeLists.txt and .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Akhil-CM committed Apr 24, 2024
1 parent da54313 commit 68fb9ea
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 66 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.cache
**/.cache/clangd
/build
/Release
/Debug
/bin
compile_commands.json
perf.*
76 changes: 76 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
cmake_minimum_required(VERSION 3.12)
# set the project name
project(DiscreteENN_TSP VERSION 0.1)

# specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# # we default to Release build type
# if(NOT CMAKE_BUILD_TYPE)
# set(CMAKE_BUILD_TYPE "Debug")
# endif()

if (MSVC)
add_compile_options(/W4 /WX)
else()
add_compile_options(-Wall -Wextra -pedantic)
endif()

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")

# Set compiler options for different build types
target_compile_options(enn_tsp PRIVATE
$<$<CONFIG:Release>:-O3;-march=native;-mtune=native>
$<$<CONFIG:Debug>:-fsanitize=address,undefined,float-divide-by-zero,nullability;-fno-omit-frame-pointer;-Og;-g>
)

# Link options, needed specifically for the sanitizer in Debug mode
target_link_options(enn_tsp PRIVATE
$<$<CONFIG:Debug>:-fsanitize=address,undefined,float-divide-by-zero,nullability;-fno-omit-frame-pointer>
)

target_link_libraries(enn_tsp PRIVATE
sfml-graphics
sfml-window
sfml-system
)

install(TARGETS enn_tsp DESTINATION "${PROJECT_SOURCE_DIR}/bin")

# Copy to source directory
add_custom_target(
copy-compile-commands ALL
DEPENDS
${CMAKE_SOURCE_DIR}/compile_commands.json
)
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/compile_commands.json
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_SOURCE_DIR}/compile_commands.json
DEPENDS
# Unlike "proper" targets like executables and libraries,
# custom command / target pairs will not set up source
# file dependencies, so we need to list file explicitly here
generate-compile-commands
${CMAKE_BINARY_DIR}/compile_commands.json
)

# Generate the compilation commands. Necessary so cmake knows where it came
# from and if for some reason you delete it.
add_custom_target(generate-compile-commands
DEPENDS
${CMAKE_BINARY_DIR}/compile_commands.json
)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/compile_commands.json
COMMAND ${CMAKE_COMMAND} -B${CMAKE_BINARY_DIR} -S${CMAKE_SOURCE_DIR}
)
18 changes: 1 addition & 17 deletions DiscreteENN_TSP_table.csv
Original file line number Diff line number Diff line change
@@ -1,18 +1,2 @@
name,points,error,time(us),time per city(us),time per city min(us),time per city max(us),distance,optimal_distance
berlin52,52,8.519310,288.000000,5.538462,340282346638528859811704183484516925440.000000,-1.000000,8184.526367,7542.000000
st70,70,6.103633,620.000000,8.857142,340282346638528859811704183484516925440.000000,-1.000000,716.199524,675.000000
eil76,76,4.718426,1096.000000,14.421053,340282346638528859811704183484516925440.000000,-1.000000,563.385132,538.000000
pr76,76,3.699711,1183.000000,15.565789,340282346638528859811704183484516925440.000000,-1.000000,112160.570312,108159.000000
kroA100,100,8.135396,1597.000000,15.970000,340282346638528859811704183484516925440.000000,-1.000000,23013.375000,21282.000000
kroC100,100,0.799013,1571.000000,15.710000,340282346638528859811704183484516925440.000000,-1.000000,20914.787109,20749.000000
kroD100,100,5.920948,1818.000000,18.180000,340282346638528859811704183484516925440.000000,-1.000000,22554.806641,21294.000000
rd100,100,5.625124,2576.000000,25.760000,340282346638528859811704183484516925440.000000,-1.000000,8354.947266,7910.000000
eil101,101,7.306752,2005.000000,19.851484,340282346638528859811704183484516925440.000000,-1.000000,674.959473,629.000000
lin105,105,5.906815,1573.000000,14.980952,340282346638528859811704183484516925440.000000,-1.000000,15228.340820,14379.000000
ch130,130,4.879879,3963.000000,30.484615,340282346638528859811704183484516925440.000000,-1.000000,6408.160645,6110.000000
ch150,150,5.822298,5902.000000,39.346668,340282346638528859811704183484516925440.000000,-1.000000,6908.079590,6528.000000
tsp225,225,4.255092,16507.000000,73.364441,340282346638528859811704183484516925440.000000,-1.000000,4082.629395,3916.000000
a280,280,8.966777,31469.000000,112.389282,340282346638528859811704183484516925440.000000,-1.000000,2810.253174,2579.000000
pcb442,442,8.710396,112518.000000,254.565613,340282346638528859811704183484516925440.000000,-1.000000,55200.964844,50778.000000
pr1002,1002,7.701775,1799999.000000,1796.406128,340282346638528859811704183484516925440.000000,-1.000000,278996.062500,259045.000000
pr2392,2392,10.202493,97116608.000000,40600.589844,340282346638528859811704183484516925440.000000,-1.000000,416600.687500,378032.000000
pr1002,1002,6.932652,5975245.000000,5963.318359,340282346638528859811704183484516925440.000000,-1.000000,277003.687500,259045.000000
18 changes: 1 addition & 17 deletions DiscreteENN_TSP_table.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,2 @@
name points error time(us) time per city(us) time per city min(us) time per city max(us) distance optimal_distance
berlin52 52 8.519310 288.000000 5.538462 340282346638528859811704183484516925440.000000 -1.000000 8184.526367 7542.000000
st70 70 6.103633 620.000000 8.857142 340282346638528859811704183484516925440.000000 -1.000000 716.199524 675.000000
eil76 76 4.718426 1096.000000 14.421053 340282346638528859811704183484516925440.000000 -1.000000 563.385132 538.000000
pr76 76 3.699711 1183.000000 15.565789 340282346638528859811704183484516925440.000000 -1.000000 112160.570312 108159.000000
kroA100 100 8.135396 1597.000000 15.970000 340282346638528859811704183484516925440.000000 -1.000000 23013.375000 21282.000000
kroC100 100 0.799013 1571.000000 15.710000 340282346638528859811704183484516925440.000000 -1.000000 20914.787109 20749.000000
kroD100 100 5.920948 1818.000000 18.180000 340282346638528859811704183484516925440.000000 -1.000000 22554.806641 21294.000000
rd100 100 5.625124 2576.000000 25.760000 340282346638528859811704183484516925440.000000 -1.000000 8354.947266 7910.000000
eil101 101 7.306752 2005.000000 19.851484 340282346638528859811704183484516925440.000000 -1.000000 674.959473 629.000000
lin105 105 5.906815 1573.000000 14.980952 340282346638528859811704183484516925440.000000 -1.000000 15228.340820 14379.000000
ch130 130 4.879879 3963.000000 30.484615 340282346638528859811704183484516925440.000000 -1.000000 6408.160645 6110.000000
ch150 150 5.822298 5902.000000 39.346668 340282346638528859811704183484516925440.000000 -1.000000 6908.079590 6528.000000
tsp225 225 4.255092 16507.000000 73.364441 340282346638528859811704183484516925440.000000 -1.000000 4082.629395 3916.000000
a280 280 8.966777 31469.000000 112.389282 340282346638528859811704183484516925440.000000 -1.000000 2810.253174 2579.000000
pcb442 442 8.710396 112518.000000 254.565613 340282346638528859811704183484516925440.000000 -1.000000 55200.964844 50778.000000
pr1002 1002 7.701775 1799999.000000 1796.406128 340282346638528859811704183484516925440.000000 -1.000000 278996.062500 259045.000000
pr2392 2392 10.202493 97116608.000000 40600.589844 340282346638528859811704183484516925440.000000 -1.000000 416600.687500 378032.000000
pr1002 1002 6.932652 5975245.000000 5963.318359 340282346638528859811704183484516925440.000000 -1.000000 277003.687500 259045.000000
Binary file removed a.out
Binary file not shown.
31 changes: 11 additions & 20 deletions compile_cpp.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
#!/usr/bin/env bash

# COMPILER="clang++"
COMPILER="g++"

CXX_STANDARD="-std=c++17"

FLAGS_CXX="-fstrict-aliasing -Wall -Wextra -pedantic"
FLAGS_CXX_EXTRA="-fsanitize=address,undefined"

FLAGS_RELEASE=""

FLAGS_EXTRA="-lsfml-graphics -lsfml-window -lsfml-system"
# FLAGS_EXTRA=""
EXE="enn_tsp"
CONFIG="Debug"

if [[ "$1" == "run" ]]; then
FLAGS_RELEASE="-march=native -O3 -DNDEBUG"
FLAGS_CXX_EXTRA=""
shift
CONFIG="Release"
fi

echo "Compiling the following:"
echo "$COMPILER $CXX_STANDARD $FLAGS_CXX $FLAGS_CXX_EXTRA $FLAGS_EXTRA $FLAGS_RELEASE $@"
"$COMPILER" $CXX_STANDARD $FLAGS_CXX $FLAGS_CXX_EXTRA $FLAGS_EXTRA $FLAGS_RELEASE "$@"
# sleep 2 &&
# time ./a.out
rm -rfv "${CONFIG}" &&
mkdir -p "${CONFIG}" &&
cmake -DCMAKE_CXX_COMPILER="/usr/bin/clang++" -DCMAKE_C_COMPILER="/usr/bin/clang" -DCMAKE_BUILD_TYPE="${CONFIG}" -S $PWD -B "${CONFIG}" &&
# cmake -DCMAKE_CXX_COMPILER="/usr/bin/g++" -DCMAKE_C_COMPILER="/usr/bin/gcc" -DCMAKE_BUILD_TYPE="${CONFIG}" -S $PWD -B "${CONFIG}" &&
cmake --build "${CONFIG}" &&
mkdir -p bin &&
cp "${CONFIG}/${EXE}" bin/"${EXE}"
# cp "${CONFIG}/compile_commands.json" "${PWD}/compile_commands.json"
11 changes: 0 additions & 11 deletions compile_flags.txt

This file was deleted.

2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ int runPipelineSingle(TSPInfo& info, const stdfs::path& data_path,
info.m_points = num_cities;
info.m_time = duration;
info.m_timePerCity = static_cast<Value_t>(duration)/num_cities;
info.m_timePerIter = enn_tsp.timePerCity();
// info.m_timePerIter = enn_tsp.timePerCity();
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';
Expand Down

0 comments on commit 68fb9ea

Please sign in to comment.