Skip to content

Commit

Permalink
Switch to cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
fontanf committed Apr 16, 2024
1 parent d65d197 commit 8ea1a96
Show file tree
Hide file tree
Showing 110 changed files with 368 additions and 378 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8"]

env:
TRAVELLING_THIEF_DATA: ${{ github.workspace }}/data/travelling_thief
TRAVELLING_WHILE_PACKING_DATA: ${{ github.workspace }}/data/travelling_while_packing
PACKING_WHILE_TRAVELLING_DATA: ${{ github.workspace }}/data/packing_while_travelling
THIEF_ORIENTEERING_DATA: ${{ github.workspace }}/data/thief_orienteering

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -25,7 +31,10 @@ jobs:
python3 -m pip install gdown
python3 scripts/download_data.py
- name: Build
run: bazel build -- //...
run: |
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release --parallel
cmake --install build --config Release --prefix install
- name: Run tests
run: python3 -u scripts/run_tests.py test_results
- name: Checkout main branch
Expand All @@ -34,8 +43,8 @@ jobs:
git fetch --depth 1
git checkout master
- name: Build
run: bazel build -- //...
run: bazel build -- //travellingthiefsolver/...
- name: Run tests
run: python3 -u scripts/run_tests.py test_results_ref
- name: Process tests
run: python3 ./bazel-travellingthiefsolver/external/optimizationtools/scripts/process_tests.py --ref test_results_ref --new test_results
run: python3 -u ./build/_deps/optimizationtools-src/scripts/process_tests.py --ref test_results_ref --new test_results
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.15.0)

project(TravellingThiefSolver LANGUAGES CXX)

# Require C++14.
set(CMAKE_CXX_STANDARD 14)

# Enable output of compile commands during generation.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Add sub-directories.
add_subdirectory(extern)
add_subdirectory(src)
add_subdirectory(test)
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ Authors:

Compile:
```shell
bazel build -- //...
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release --parallel
cmake --install build --config Release --prefix install
```

Download data:
Expand All @@ -72,7 +74,7 @@ python3 scripts/download_data.py
Examples:

```shell
./bazel-bin/travellingthiefsolver/travelling_thief/main -v 1 -i "data/travelling_thief/gecco2023/fnl4461_n4460_bounded-strongly-corr_01.ttp" -a "iterative-tsp-pwt-ttp" -t 600
./install/bin/travellingthiefsolver_travelling_thief --verbosity-level 1 --input "data/travelling_thief/gecco2023/fnl4461_n4460_bounded-strongly-corr_01.ttp" --algorithm "iterative-tsp-pwt-ttp" --time-limit 600
```
```
=====================================
Expand Down
26 changes: 26 additions & 0 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Enable FetchContent.
include(FetchContent)

# Fetch fontanf/knapsacksolver.
FetchContent_Declare(
knapsacksolver
GIT_REPOSITORY https://github.com/fontanf/knapsacksolver.git
GIT_TAG abbe052b56c6e985112cda23abda26f1eb0e43ce)
#SOURCE_DIR "${PROJECT_SOURCE_DIR}/../knapsacksolver/")
FetchContent_MakeAvailable(knapsacksolver)

# Fetch fontanf/treesearchsolver.
FetchContent_Declare(
treesearchsolver
GIT_REPOSITORY https://github.com/fontanf/treesearchsolver.git
GIT_TAG dca5b35d5cb6de3443b9ab08175f931b2df29b6b)
#SOURCE_DIR "${PROJECT_SOURCE_DIR}/../treesearchsolver/")
FetchContent_MakeAvailable(treesearchsolver)

# Fetch fontanf/localsearchsolver.
FetchContent_Declare(
localsearchsolver
GIT_REPOSITORY https://github.com/fontanf/localsearchsolver.git
GIT_TAG ecb15ef667d107f25ea51d056368f9c4e15545e2)
#SOURCE_DIR "${PROJECT_SOURCE_DIR}/../localsearchsolver/")
FetchContent_MakeAvailable(localsearchsolver)
13 changes: 10 additions & 3 deletions scripts/download_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@


def download(id):
gdown.download(id=id, output="data.7z")
os.system("7z x data.7z -odata")
pathlib.Path("data.7z").unlink()
for _ in range(3):
try:
gdown.download(id=id, output="data.7z")
os.system("7z x data.7z -odata")
pathlib.Path("data.7z").unlink()
except:
time.sleep(10)
continue
return
sys.exit(1)


download("1RmT19FCH3gnxTi8GRCrI_UUJGSMPUXTT")
Expand Down
37 changes: 17 additions & 20 deletions scripts/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@



travelling_thief_data = os.environ['TRAVELLING_THIEF_DATA']
travelling_thief_main = os.path.join(
"bazel-bin",
"travellingthiefsolver",
"travelling_thief",
"main")
"install",
"bin",
"travellingthiefsolver_travelling_thief")


if args.tests is None or "travelling-thief-local-search" in args.tests:
print("Travelling thief problem / local search")
print("---------------------------------------")
print()

travelling_thief_local_search_data = [
data = [
os.path.join("polyakovskiy2014", "berlin52-ttp", "berlin52_n51_bounded-strongly-corr_01.ttp"),
os.path.join("polyakovskiy2014", "berlin52-ttp", "berlin52_n51_uncorr_01.ttp"),
os.path.join("polyakovskiy2014", "berlin52-ttp", "berlin52_n51_uncorr-similar-weights_01.ttp"),
Expand All @@ -36,10 +36,9 @@
os.path.join("polyakovskiy2014", "berlin52-ttp", "berlin52_n255_bounded-strongly-corr_01.ttp"),
os.path.join("polyakovskiy2014", "berlin52-ttp", "berlin52_n255_uncorr_01.ttp"),
os.path.join("polyakovskiy2014", "berlin52-ttp", "berlin52_n255_uncorr-similar-weights_01.ttp")]
for instance in travelling_thief_local_search_data:
for instance in data:
instance_path = os.path.join(
"data",
"travelling_thief",
travelling_thief_data,
instance)
json_output_path = os.path.join(
args.directory,
Expand Down Expand Up @@ -67,7 +66,7 @@
print("--------------------------------------")
print()

travelling_thief_tree_search_data = [
data = [
os.path.join("wu2017", "eil51_n14_m13_multiple-strongly-corr_01.ttp"),
os.path.join("wu2017", "eil51_n14_m13_uncorr_01.ttp"),
os.path.join("wu2017", "eil51_n14_m13_uncorr-similar-weights_01.ttp"),
Expand All @@ -77,10 +76,9 @@
os.path.join("wu2017", "eil51_n05_m40_multiple-strongly-corr_01.ttp"),
os.path.join("wu2017", "eil51_n05_m40_uncorr_01.ttp"),
os.path.join("wu2017", "eil51_n05_m40_uncorr-similar-weights_01.ttp")]
for instance in travelling_thief_tree_search_data:
for instance in data:
instance_path = os.path.join(
"data",
"travelling_thief",
travelling_thief_data,
instance)
json_output_path = os.path.join(
args.directory,
Expand All @@ -102,19 +100,19 @@
print()


thief_orienteering_data = os.environ['THIEF_ORIENTEERING_DATA']
thief_orienteering_main = os.path.join(
"bazel-bin",
"travellingthiefsolver",
"thief_orienteering",
"main")
"install",
"bin",
"travellingthiefsolver_thief_orienteering")


if args.tests is None or "thief-orienteering-local-search" in args.tests:
print("Thief orienteering / local search")
print("---------------------------------")
print()

thief_orienteering_local_search_data = [
data = [
os.path.join("santos2018", "eil51-thop", "eil51_01_bsc_01_01.thop"),
os.path.join("santos2018", "eil51-thop", "eil51_01_unc_05_01.thop"),
os.path.join("santos2018", "eil51-thop", "eil51_01_usw_10_01.thop"),
Expand All @@ -124,10 +122,9 @@
os.path.join("santos2018", "eil51-thop", "eil51_05_bsc_10_01.thop"),
os.path.join("santos2018", "eil51-thop", "eil51_05_unc_01_01.thop"),
os.path.join("santos2018", "eil51-thop", "eil51_05_usw_05_01.thop")]
for instance in thief_orienteering_local_search_data:
for instance in data:
instance_path = os.path.join(
"data",
"thief_orienteering",
thief_orienteering_data,
instance)
json_output_path = os.path.join(
args.directory,
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_subdirectory(packing_while_travelling)
add_subdirectory(thief_orienteering)
add_subdirectory(travelling_thief)
add_subdirectory(travelling_while_packing)
31 changes: 31 additions & 0 deletions src/packing_while_travelling/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
add_library(TravellingThiefSolver_packing_while_travelling)
target_sources(TravellingThiefSolver_packing_while_travelling PRIVATE
instance.cpp
instance_builder.cpp
solution.cpp
solution_builder.cpp
utils.cpp
reduction.cpp
algorithm.cpp
algorithm_formatter.cpp)
target_include_directories(TravellingThiefSolver_packing_while_travelling PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(TravellingThiefSolver_packing_while_travelling PUBLIC
OptimizationTools::containers
OptimizationTools::utils)
add_library(TravellingThiefSolver::knapsack ALIAS TravellingThiefSolver_packing_while_travelling)

add_subdirectory(algorithms)

add_executable(TravellingThiefSolver_packing_while_travelling_main)
target_sources(TravellingThiefSolver_packing_while_travelling_main PRIVATE
main.cpp)
target_link_libraries(TravellingThiefSolver_packing_while_travelling_main PUBLIC
TravellingThiefSolver_packing_while_travelling_greedy
TravellingThiefSolver_packing_while_travelling_sequential_value_correction
TravellingThiefSolver_packing_while_travelling_dynamic_programming
TravellingThiefSolver_packing_while_travelling_efficient_local_search
TravellingThiefSolver_packing_while_travelling_large_neighborhood_search
Boost::program_options)
set_target_properties(TravellingThiefSolver_packing_while_travelling_main PROPERTIES OUTPUT_NAME "travellingthiefsolver_packing_while_travelling")
install(TARGETS TravellingThiefSolver_packing_while_travelling_main)
File renamed without changes.
48 changes: 48 additions & 0 deletions src/packing_while_travelling/algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
add_library(TravellingThiefSolver_packing_while_travelling_greedy)
target_sources(TravellingThiefSolver_packing_while_travelling_greedy PRIVATE
greedy.cpp)
target_include_directories(TravellingThiefSolver_packing_while_travelling_greedy PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(TravellingThiefSolver_packing_while_travelling_greedy PUBLIC
TravellingThiefSolver_packing_while_travelling)
add_library(TravellingThiefSolver::knapsack::greedy ALIAS TravellingThiefSolver_packing_while_travelling_greedy)

add_library(TravellingThiefSolver_packing_while_travelling_sequential_value_correction)
target_sources(TravellingThiefSolver_packing_while_travelling_sequential_value_correction PRIVATE
sequential_value_correction.cpp)
target_include_directories(TravellingThiefSolver_packing_while_travelling_sequential_value_correction PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(TravellingThiefSolver_packing_while_travelling_sequential_value_correction PUBLIC
TravellingThiefSolver_packing_while_travelling
KnapsackSolver::knapsack::dynamic_programming_primal_dual)
add_library(TravellingThiefSolver::knapsack::sequential_value_correction ALIAS TravellingThiefSolver_packing_while_travelling_sequential_value_correction)

add_library(TravellingThiefSolver_packing_while_travelling_dynamic_programming)
target_sources(TravellingThiefSolver_packing_while_travelling_dynamic_programming PRIVATE
dynamic_programming.cpp)
target_include_directories(TravellingThiefSolver_packing_while_travelling_dynamic_programming PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(TravellingThiefSolver_packing_while_travelling_dynamic_programming PUBLIC
TravellingThiefSolver_packing_while_travelling)
add_library(TravellingThiefSolver::knapsack::dynamic_programming ALIAS TravellingThiefSolver_packing_while_travelling_dynamic_programming)

add_library(TravellingThiefSolver_packing_while_travelling_efficient_local_search)
target_sources(TravellingThiefSolver_packing_while_travelling_efficient_local_search PRIVATE
efficient_local_search.cpp)
target_include_directories(TravellingThiefSolver_packing_while_travelling_efficient_local_search PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(TravellingThiefSolver_packing_while_travelling_efficient_local_search PUBLIC
TravellingThiefSolver_packing_while_travelling
TravellingThiefSolver_packing_while_travelling_sequential_value_correction)
add_library(TravellingThiefSolver::knapsack::efficient_local_search ALIAS TravellingThiefSolver_packing_while_travelling_efficient_local_search)

add_library(TravellingThiefSolver_packing_while_travelling_large_neighborhood_search)
target_sources(TravellingThiefSolver_packing_while_travelling_large_neighborhood_search PRIVATE
large_neighborhood_search.cpp)
target_include_directories(TravellingThiefSolver_packing_while_travelling_large_neighborhood_search PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(TravellingThiefSolver_packing_while_travelling_large_neighborhood_search PUBLIC
TravellingThiefSolver_packing_while_travelling
TravellingThiefSolver_packing_while_travelling_greedy
TravellingThiefSolver_packing_while_travelling_sequential_value_correction)
add_library(TravellingThiefSolver::knapsack::large_neighborhood_search ALIAS TravellingThiefSolver_packing_while_travelling_large_neighborhood_search)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions src/thief_orienteering/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
add_library(TravellingThiefSolver_thief_orienteering)
target_sources(TravellingThiefSolver_thief_orienteering PRIVATE
instance.cpp
instance_builder.cpp
solution.cpp
algorithm_formatter.cpp)
target_include_directories(TravellingThiefSolver_thief_orienteering PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(TravellingThiefSolver_thief_orienteering PUBLIC
OptimizationTools::utils
TravelingSalesmanSolver::distances)
add_library(TravellingThiefSolver::knapsack ALIAS TravellingThiefSolver_thief_orienteering)

add_subdirectory(algorithms)

add_executable(TravellingThiefSolver_thief_orienteering_main)
target_sources(TravellingThiefSolver_thief_orienteering_main PRIVATE
main.cpp)
target_link_libraries(TravellingThiefSolver_thief_orienteering_main PUBLIC
TravellingThiefSolver_thief_orienteering_tree_search
TravellingThiefSolver_thief_orienteering_local_search
Boost::program_options)
set_target_properties(TravellingThiefSolver_thief_orienteering_main PROPERTIES OUTPUT_NAME "travellingthiefsolver_thief_orienteering")
install(TARGETS TravellingThiefSolver_thief_orienteering_main)

add_executable(TravellingThiefSolver_thief_orienteering_checker)
target_sources(TravellingThiefSolver_thief_orienteering_checker PRIVATE
checker.cpp)
target_link_libraries(TravellingThiefSolver_thief_orienteering_checker PUBLIC
TravellingThiefSolver_thief_orienteering
Boost::program_options)
set_target_properties(TravellingThiefSolver_thief_orienteering_checker PROPERTIES OUTPUT_NAME "travellingthiefsolver_thief_orienteering_checker")
install(TARGETS TravellingThiefSolver_thief_orienteering_checker)
19 changes: 19 additions & 0 deletions src/thief_orienteering/algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
add_library(TravellingThiefSolver_thief_orienteering_tree_search)
target_sources(TravellingThiefSolver_thief_orienteering_tree_search PRIVATE
tree_search.cpp)
target_include_directories(TravellingThiefSolver_thief_orienteering_tree_search PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(TravellingThiefSolver_thief_orienteering_tree_search PUBLIC
TravellingThiefSolver_thief_orienteering
TreeSearchSolver::treesearchsolver)
add_library(TravellingThiefSolver::thief_orienteering::tree_search ALIAS TravellingThiefSolver_thief_orienteering_tree_search)

add_library(TravellingThiefSolver_thief_orienteering_local_search)
target_sources(TravellingThiefSolver_thief_orienteering_local_search PRIVATE
local_search.cpp)
target_include_directories(TravellingThiefSolver_thief_orienteering_local_search PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(TravellingThiefSolver_thief_orienteering_local_search PUBLIC
TravellingThiefSolver_thief_orienteering
LocalSearchSolver::localsearchsolver)
add_library(TravellingThiefSolver::thief_orienteering::local_search ALIAS TravellingThiefSolver_thief_orienteering_local_search)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 8ea1a96

Please sign in to comment.