From 9f8fe4b15ef85f8e75d6c9558ea70dad3e97a39f Mon Sep 17 00:00:00 2001 From: Florian Fontan Date: Sat, 27 Apr 2024 09:18:54 +0200 Subject: [PATCH] Switch to CMake --- .bazelrc | 10 - .github/workflows/build.yml | 12 +- CMakeLists.txt | 20 ++ README.md | 18 +- WORKSPACE | 237 ------------------ extern/CMakeLists.txt | 36 +++ .../setcoveringsolver}/algorithm.hpp | 0 .../algorithm_formatter.hpp | 0 .../setcoveringsolver}/algorithms/greedy.hpp | 0 .../algorithms/large_neighborhood_search.hpp | 0 .../algorithms/local_search_row_weighting.hpp | 0 .../algorithms/milp_cbc.hpp | 9 +- .../algorithms/milp_gurobi.hpp | 4 - .../setcoveringsolver}/instance.hpp | 0 .../setcoveringsolver}/instance_builder.hpp | 0 .../setcoveringsolver}/reduction.hpp | 0 .../setcoveringsolver}/solution.hpp | 0 scripts/run_tests.py | 9 +- setcoveringsolver/BUILD | 79 ------ setcoveringsolver/algorithms/BUILD | 56 ----- setcoveringsolver/variables.bzl | 31 --- src/CMakeLists.txt | 41 +++ {setcoveringsolver => src}/algorithm.cpp | 0 .../algorithm_formatter.cpp | 4 - src/algorithms/CMakeLists.txt | 50 ++++ .../algorithms/greedy.cpp | 0 .../algorithms/large_neighborhood_search.cpp | 0 .../algorithms/local_search_row_weighting.cpp | 0 .../algorithms/milp_cbc.cpp | 4 - .../algorithms/milp_gurobi.cpp | 4 - {setcoveringsolver => src}/instance.cpp | 0 .../instance_builder.cpp | 0 {setcoveringsolver => src}/main.cpp | 2 + {setcoveringsolver => src}/reduction.cpp | 0 {setcoveringsolver => src}/solution.cpp | 0 test/CMakeLists.txt | 1 + test/algorithms/CMakeLists.txt | 0 37 files changed, 173 insertions(+), 454 deletions(-) delete mode 100644 .bazelrc create mode 100644 CMakeLists.txt delete mode 100644 WORKSPACE create mode 100644 extern/CMakeLists.txt rename {setcoveringsolver => include/setcoveringsolver}/algorithm.hpp (100%) rename {setcoveringsolver => include/setcoveringsolver}/algorithm_formatter.hpp (100%) rename {setcoveringsolver => include/setcoveringsolver}/algorithms/greedy.hpp (100%) rename {setcoveringsolver => include/setcoveringsolver}/algorithms/large_neighborhood_search.hpp (100%) rename {setcoveringsolver => include/setcoveringsolver}/algorithms/local_search_row_weighting.hpp (100%) rename {setcoveringsolver => include/setcoveringsolver}/algorithms/milp_cbc.hpp (78%) rename {setcoveringsolver => include/setcoveringsolver}/algorithms/milp_gurobi.hpp (92%) rename {setcoveringsolver => include/setcoveringsolver}/instance.hpp (100%) rename {setcoveringsolver => include/setcoveringsolver}/instance_builder.hpp (100%) rename {setcoveringsolver => include/setcoveringsolver}/reduction.hpp (100%) rename {setcoveringsolver => include/setcoveringsolver}/solution.hpp (100%) delete mode 100644 setcoveringsolver/BUILD delete mode 100644 setcoveringsolver/algorithms/BUILD delete mode 100644 setcoveringsolver/variables.bzl create mode 100644 src/CMakeLists.txt rename {setcoveringsolver => src}/algorithm.cpp (100%) rename {setcoveringsolver => src}/algorithm_formatter.cpp (96%) create mode 100644 src/algorithms/CMakeLists.txt rename {setcoveringsolver => src}/algorithms/greedy.cpp (100%) rename {setcoveringsolver => src}/algorithms/large_neighborhood_search.cpp (100%) rename {setcoveringsolver => src}/algorithms/local_search_row_weighting.cpp (100%) rename {setcoveringsolver => src}/algorithms/milp_cbc.cpp (99%) rename {setcoveringsolver => src}/algorithms/milp_gurobi.cpp (99%) rename {setcoveringsolver => src}/instance.cpp (100%) rename {setcoveringsolver => src}/instance_builder.cpp (100%) rename {setcoveringsolver => src}/main.cpp (99%) rename {setcoveringsolver => src}/reduction.cpp (100%) rename {setcoveringsolver => src}/solution.cpp (100%) create mode 100644 test/CMakeLists.txt create mode 100644 test/algorithms/CMakeLists.txt diff --git a/.bazelrc b/.bazelrc deleted file mode 100644 index 3698f9e..0000000 --- a/.bazelrc +++ /dev/null @@ -1,10 +0,0 @@ -build --compilation_mode=opt -#build --cxxopt=-Wall --cxxopt=-Wextra - -################################################################################ -############################ Optional dependencies ############################# -################################################################################ - -#build --define gurobi=true -#build --define cplex=true -#build --define cbc=true diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 14cc26b..3a6719f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,6 +13,9 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] python-version: ["3.8"] + env: + SET_COVERING_DATA: ${{ github.workspace }}/data/ + steps: - name: Checkout code uses: actions/checkout@v4 @@ -25,7 +28,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 @@ -34,8 +40,8 @@ jobs: git fetch --depth 1 git checkout master - name: Build - run: bazel build -- //... + run: bazel build -- //setcoveringsolver/... - name: Run tests run: python3 -u scripts/run_tests.py test_results_ref - name: Process tests - run: python3 ./bazel-setcoveringsolver/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 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1a6ff93 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.15.0) + +project(SetCoveringSolver LANGUAGES CXX) + +option(SETCOVERINGSOLVER_USE_CBC "Use CPLEX" ON) +option(SETCOVERINGSOLVER_USE_GUROBI "Use Gurobi" OFF) + +# Require C++14. +set(CMAKE_CXX_STANDARD 14) + +# Enable output of compile commands during generation. +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# Set MSVC_RUNTIME_LIBRARY. +set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + +# Add sub-directories. +add_subdirectory(extern) +add_subdirectory(src) +add_subdirectory(test) diff --git a/README.md b/README.md index ee9aec1..5a97a0e 100644 --- a/README.md +++ b/README.md @@ -32,13 +32,9 @@ In the set packing problem solved, elements may be covered multiple times and th Compile: ```shell -bazel build -- //... - -# To use algorithm "milp_cbc": -bazel build --define coinor=true -- //... - -# To use algorithm "milp_gurobi": -bazel build --define gurobi=true -- //... +cmake -S . -B build -DCMAKE_BUILD_TYPE=Release +cmake --build build --config Release --parallel +cmake --install build --config Release --prefix install ``` Download data: @@ -50,7 +46,7 @@ python3 scripts/download_data.py --data gecco2020 Run: ```shell -./bazel-bin/setcoveringsolver/main -v 1 -i data/wedelin1995/sasd9imp2.dat -f wedelin1995 -a milp-cbc +./install/bin/setcoveringsolver -v 1 -i data/wedelin1995/sasd9imp2.dat -f wedelin1995 -a milp-cbc ``` ``` ===================================== @@ -130,7 +126,7 @@ Cost: 5262040 ``` ```shell -./bazel-bin/setcoveringsolver/main -v 1 -i data/beasley1990/scpnrh5.txt -f orlibrary -a large-neighborhood-search -t 0.3 +./install/bin/setcoveringsolver -v 1 -i data/beasley1990/scpnrh5.txt -f orlibrary -a large-neighborhood-search -t 0.3 ``` ``` ===================================== @@ -212,7 +208,7 @@ Cost: 55 ``` ```shell -./bazel-bin/setcoveringsolver/main -v 1 -i data/faster1994/rail582.txt -f faster --unicost -a local-search-row-weighting-1 -c solution.txt -t 2 +./install/bin/setcoveringsolver -v 1 -i data/faster1994/rail582.txt -f faster --unicost -a local-search-row-weighting-1 -c solution.txt -t 2 ``` ``` ===================================== @@ -312,7 +308,7 @@ Cost: 130 ``` ```shell -./bazel-bin/setcoveringsolver/main -v 1 -i data/gecco2020/AC_15_cover.txt -f gecco2020 --unicost -a local-search-row-weighting-2 -t 10 -c solution.txt +./install/bin/setcoveringsolver -v 1 -i data/gecco2020/AC_15_cover.txt -f gecco2020 --unicost -a local-search-row-weighting-2 -t 10 -c solution.txt ``` ``` ===================================== diff --git a/WORKSPACE b/WORKSPACE deleted file mode 100644 index dda7ddd..0000000 --- a/WORKSPACE +++ /dev/null @@ -1,237 +0,0 @@ -load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -git_repository( - name = "googletest", - remote = "https://github.com/google/googletest.git", - commit = "58d77fa8070e8cec2dc1ed015d66b454c8d78850", - shallow_since = "1656350095 -0400", -) - -git_repository( - name = "com_github_nelhage_rules_boost", - remote = "https://github.com/nelhage/rules_boost", - commit = "e83dfef18d91a3e35c8eac9b9aeb1444473c0efd", - shallow_since = "1671181466 +0000", -) -load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps") -boost_deps() - -http_archive( - name = "json", - build_file_content = """ -cc_library( - name = "json", - hdrs = ["single_include/nlohmann/json.hpp"], - visibility = ["//visibility:public"], - strip_include_prefix = "single_include/" -) -""", - urls = ["https://github.com/nlohmann/json/releases/download/v3.7.3/include.zip"], - sha256 = "87b5884741427220d3a33df1363ae0e8b898099fbc59f1c451113f6732891014", -) - -git_repository( - name = "optimizationtools", - remote = "https://github.com/fontanf/optimizationtools.git", - commit = "48b4c00424ef2aee31e5d139c16c33d0f8deac7e", -) - -local_repository( - name = "optimizationtools_", - path = "/home/florian/Dev/optimizationtools/", -) - -git_repository( - name = "localsearchsolver", - remote = "https://github.com/fontanf/localsearchsolver.git", - commit = "b49b95480671a886afb8159f565c3673cce2dd03", -) - -http_archive( - name = "osi_linux", - urls = ["https://github.com/coin-or/Osi/releases/download/releases%2F0.108.8/Osi-releases.0.108.8-x86_64-ubuntu20-gcc940-static.tar.gz"], - sha256 = "bd5a5bf1e6b6a28d13d41ab1554becd9f3992afe775785e51a88c9405cf2853e", - build_file_content = """ -cc_library( - name = "osi", - hdrs = glob(["include/coin/Osi*.h*"], exclude_directories = 0), - strip_include_prefix = "include/coin/", - srcs = ["lib/libOsi.a", "lib/libOsiCommonTests.a"], - visibility = ["//visibility:public"], -) -""", -) - -http_archive( - name = "osi_windows", - urls = ["https://github.com/coin-or/Osi/releases/download/releases%2F0.108.8/Osi-releases.0.108.8-w64-msvc16-md.zip"], - sha256 = "a61fc462cb598139d205cd2323522581a01900575d0d6bccf660b6c7e1b0b71c", - build_file_content = """ -cc_library( - name = "osi", - hdrs = glob(["include/coin/Osi*.h*"], exclude_directories = 0), - strip_include_prefix = "include/coin/", - visibility = ["//visibility:public"], - srcs = ["lib/libOsi.lib", "lib/libOsiCommonTests.lib"], -) -""", -) - -http_archive( - name = "coinutils_linux", - urls = ["https://github.com/coin-or/CoinUtils/releases/download/releases%2F2.11.9/CoinUtils-releases.2.11.9-x86_64-ubuntu20-gcc940-static.tar.gz"], - sha256 = "14d07de1b7961f68e037da6f0c57844fd67d4cc1a4b125642f42cd134b228094", - build_file_content = """ -cc_library( - name = "coinutils", - hdrs = glob(["include/coin/Coin*.h*"], exclude_directories = 0), - strip_include_prefix = "include/coin/", - srcs = ["lib/libCoinUtils.a"], - linkopts = ["-llapack", "-lblas", "-lbz2", "-lz"], - visibility = ["//visibility:public"], -) -""", -) - -http_archive( - name = "coinutils_windows", - urls = ["https://github.com/coin-or/CoinUtils/releases/download/releases%2F2.11.9/CoinUtils-releases.2.11.9-w64-msvc16-md.zip"], - sha256 = "2bc64f0afd80113571697e949b2663e9047272decf90d5f62e452c2628d33ca6", - build_file_content = """ -cc_library( - name = "coinutils", - hdrs = glob(["include/coin/Coin*.h*"], exclude_directories = 0), - strip_include_prefix = "include/coin/", - srcs = ["lib/libCoinUtils.lib"], - visibility = ["//visibility:public"], -) -""", -) - -http_archive( - name = "clp_linux", - urls = ["https://github.com/coin-or/Clp/releases/download/releases%2F1.17.8/Clp-releases.1.17.8-x86_64-ubuntu20-gcc940-static.tar.gz"], - sha256 = "d569b04d19c25876e55d2557a1d9739df8eb50ec8ca11a98ad387fd8b90212c9", - build_file_content = """ -cc_library( - name = "clp", - hdrs = glob(["include/coin/*Clp*.h*"], exclude_directories = 0), - strip_include_prefix = "include/coin", - srcs = ["lib/libClp.a", "lib/libOsiClp.a"], - deps = ["@osi_linux//:osi", "@coinutils_linux//:coinutils"], - visibility = ["//visibility:public"], -) -""", -) - -http_archive( - name = "clp_windows", - urls = ["https://github.com/coin-or/Clp/releases/download/releases%2F1.17.8/Clp-releases.1.17.8-w64-msvc16-md.zip"], - sha256 = "e37c834aea5c31dfd8620b7d2432cb31fc16ecb0c6ffb398e8f07c9c82dd5028", - build_file_content = """ -cc_library( - name = "clp", - hdrs = glob(["include/coin/*Clp*.h*"], exclude_directories = 0), - strip_include_prefix = "include/coin", - srcs = ["lib/libClp.lib", "lib/libOsiClp.lib"], - deps = ["@osi_windows//:osi", "@coinutils_windows//:coinutils"], - visibility = ["//visibility:public"], -) -""", -) - -http_archive( - name = "cbc_linux", - urls = ["https://github.com/coin-or/Cbc/releases/download/releases%2F2.10.10/Cbc-releases.2.10.10-x86_64-ubuntu20-gcc940-static.tar.gz"], - sha256 = "872c78bfcdd1566f134d2f7757b76b2a2479a5b1ade065cdd1d4b303ed6f8006", - build_file_content = """ -cc_library( - name = "cbc", - hdrs = glob(["include/coin/*Cbc*.h*"], exclude_directories = 0), - strip_include_prefix = "include/coin", - srcs = ["lib/libCbc.a", "lib/libOsiCbc.a", "lib/libCgl.a"], - deps = ["@clp_linux//:clp"], - linkopts = ["-lnauty"], - visibility = ["//visibility:public"], -) -""", -) - -http_archive( - name = "cbc_windows", - urls = ["https://github.com/coin-or/Cbc/releases/download/releases%2F2.10.10/Cbc-releases.2.10.10-w64-msvc16-md.zip"], - sha256 = "94a951904eb80c2f351785fc9340216e88970a716634bc1ccd8b4fc5024af37c", - build_file_content = """ -cc_library( - name = "cbc", - hdrs = glob(["include/coin/*Cbc*.h*"], exclude_directories = 0), - strip_include_prefix = "include/coin", - srcs = ["lib/libCbc.lib", "lib/libOsiCbc.lib", "lib/libCgl.lib"], - deps = ["@clp_windows//:clp"], - visibility = ["//visibility:public"], -) -""", -) - -new_local_repository( - name = "gurobi", - path = "/home/florian/Programmes/gurobi811/linux64/", - build_file_content = """ -cc_library( - name = "gurobi", - hdrs = [ - "include/gurobi_c.h", - "include/gurobi_c++.h", - ], - strip_include_prefix = "include/", - srcs = [ - "lib/libgurobi_c++.a", - "lib/libgurobi81.so", - ], - copts = [ - "-m64", - "-DIL_STD", - ], - visibility = ["//visibility:public"], -) -""", -) - -new_local_repository( - name = "cplex", - path = "/opt/ibm/ILOG/CPLEX_Studio129/", - build_file_content = """ -cc_library( - name = "concert", - hdrs = glob(["concert/include/ilconcert/**/*.h"], exclude_directories = 0), - strip_include_prefix = "concert/include/", - srcs = ["concert/lib/x86-64_linux/static_pic/libconcert.a"], - linkopts = [ - "-lm", - "-lpthread", - "-ldl", - ], - visibility = ["//visibility:public"], -) -cc_library( - name = "cplex", - hdrs = glob(["cplex/include/ilcplex/*.h"]), - strip_include_prefix = "cplex/include/", - srcs = [ - "cplex/lib/x86-64_linux/static_pic/libilocplex.a", - "cplex/lib/x86-64_linux/static_pic/libcplex.a", - ], - deps = [":concert"], - visibility = ["//visibility:public"], -) -cc_library( - name = "cpoptimizer", - hdrs = glob(["cpoptimizer/include/ilcp/*.h"]), - strip_include_prefix = "cpoptimizer/include/", - srcs = ["cpoptimizer/lib/x86-64_linux/static_pic/libcp.a"], - deps = [":cplex"], - visibility = ["//visibility:public"], -) -""", -) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt new file mode 100644 index 0000000..9f1ac1d --- /dev/null +++ b/extern/CMakeLists.txt @@ -0,0 +1,36 @@ +# Enable FetchContent. +include(FetchContent) + +# Fetch boost. +set(BOOST_INCLUDE_LIBRARIES thread filesystem system program_options) +set(BOOST_ENABLE_CMAKE ON) +include(FetchContent) +FetchContent_Declare( + Boost + GIT_REPOSITORY https://github.com/boostorg/boost.git + GIT_TAG boost-1.84.0 + GIT_SHALLOW TRUE +) +FetchContent_MakeAvailable(Boost) + +# Fetch fontanf/optimizationtools. +FetchContent_Declare( + optimizationtools + GIT_REPOSITORY https://github.com/fontanf/optimizationtools.git + GIT_TAG 33a3966ece149d390ec7ce08699669b5267e64aa) + #SOURCE_DIR "${PROJECT_SOURCE_DIR}/../optimizationtools/") +FetchContent_MakeAvailable(optimizationtools) + +# Fetch fontanf/mathoptsolverscmake. +if(SETCOVERINGSOLVER_USE_CBC) + set(MATHOPTSOLVERSCMAKE_USE_CBC ON) +endif() +if(SETCOVERINGSOLVER_USE_GUROBI) + set(MATHOPTSOLVERSCMAKE_USE_GUROBI ON) +endif() +FetchContent_Declare( + mathoptsolverscmake + GIT_REPOSITORY https://github.com/fontanf/mathoptsolverscmake.git + GIT_TAG 56190725f424249a3acd8fce3ff50e08fe675cc6) + #SOURCE_DIR "${PROJECT_SOURCE_DIR}/../mathoptsolverscmake/") +FetchContent_MakeAvailable(mathoptsolverscmake) diff --git a/setcoveringsolver/algorithm.hpp b/include/setcoveringsolver/algorithm.hpp similarity index 100% rename from setcoveringsolver/algorithm.hpp rename to include/setcoveringsolver/algorithm.hpp diff --git a/setcoveringsolver/algorithm_formatter.hpp b/include/setcoveringsolver/algorithm_formatter.hpp similarity index 100% rename from setcoveringsolver/algorithm_formatter.hpp rename to include/setcoveringsolver/algorithm_formatter.hpp diff --git a/setcoveringsolver/algorithms/greedy.hpp b/include/setcoveringsolver/algorithms/greedy.hpp similarity index 100% rename from setcoveringsolver/algorithms/greedy.hpp rename to include/setcoveringsolver/algorithms/greedy.hpp diff --git a/setcoveringsolver/algorithms/large_neighborhood_search.hpp b/include/setcoveringsolver/algorithms/large_neighborhood_search.hpp similarity index 100% rename from setcoveringsolver/algorithms/large_neighborhood_search.hpp rename to include/setcoveringsolver/algorithms/large_neighborhood_search.hpp diff --git a/setcoveringsolver/algorithms/local_search_row_weighting.hpp b/include/setcoveringsolver/algorithms/local_search_row_weighting.hpp similarity index 100% rename from setcoveringsolver/algorithms/local_search_row_weighting.hpp rename to include/setcoveringsolver/algorithms/local_search_row_weighting.hpp diff --git a/setcoveringsolver/algorithms/milp_cbc.hpp b/include/setcoveringsolver/algorithms/milp_cbc.hpp similarity index 78% rename from setcoveringsolver/algorithms/milp_cbc.hpp rename to include/setcoveringsolver/algorithms/milp_cbc.hpp index f2e51d4..1e05548 100644 --- a/setcoveringsolver/algorithms/milp_cbc.hpp +++ b/include/setcoveringsolver/algorithms/milp_cbc.hpp @@ -1,11 +1,9 @@ #pragma once -#if CBC_FOUND - #include "setcoveringsolver/algorithm.hpp" -#include -#include +#include +#include namespace setcoveringsolver { @@ -21,6 +19,3 @@ const Output milp_cbc( const MilpCbcParameters& parameters = {}); } - -#endif - diff --git a/setcoveringsolver/algorithms/milp_gurobi.hpp b/include/setcoveringsolver/algorithms/milp_gurobi.hpp similarity index 92% rename from setcoveringsolver/algorithms/milp_gurobi.hpp rename to include/setcoveringsolver/algorithms/milp_gurobi.hpp index 7a9def9..d39c5ab 100644 --- a/setcoveringsolver/algorithms/milp_gurobi.hpp +++ b/include/setcoveringsolver/algorithms/milp_gurobi.hpp @@ -1,7 +1,5 @@ #pragma once -#if GUROBI_FOUND - #include "setcoveringsolver/algorithm.hpp" namespace setcoveringsolver @@ -18,5 +16,3 @@ const Output milp_gurobi( const MilpGurobiParameters& parameters = {}); } - -#endif diff --git a/setcoveringsolver/instance.hpp b/include/setcoveringsolver/instance.hpp similarity index 100% rename from setcoveringsolver/instance.hpp rename to include/setcoveringsolver/instance.hpp diff --git a/setcoveringsolver/instance_builder.hpp b/include/setcoveringsolver/instance_builder.hpp similarity index 100% rename from setcoveringsolver/instance_builder.hpp rename to include/setcoveringsolver/instance_builder.hpp diff --git a/setcoveringsolver/reduction.hpp b/include/setcoveringsolver/reduction.hpp similarity index 100% rename from setcoveringsolver/reduction.hpp rename to include/setcoveringsolver/reduction.hpp diff --git a/setcoveringsolver/solution.hpp b/include/setcoveringsolver/solution.hpp similarity index 100% rename from setcoveringsolver/solution.hpp rename to include/setcoveringsolver/solution.hpp diff --git a/scripts/run_tests.py b/scripts/run_tests.py index ff37e82..0b48282 100644 --- a/scripts/run_tests.py +++ b/scripts/run_tests.py @@ -13,10 +13,11 @@ args = parser.parse_args() +data_dir = os.environ['SET_COVERING_DATA'] main = os.path.join( - "bazel-bin", - "setcoveringsolver", - "main") + "install", + "bin", + "setcoveringsolver") if args.tests is None or "greedy" in args.tests: @@ -33,7 +34,7 @@ for instance, instance_format in greedy_data: instance_path = os.path.join( - "data", + data_dir, instance) json_output_path = os.path.join( args.directory, diff --git a/setcoveringsolver/BUILD b/setcoveringsolver/BUILD deleted file mode 100644 index d73546e..0000000 --- a/setcoveringsolver/BUILD +++ /dev/null @@ -1,79 +0,0 @@ -load("@bazel_skylib//lib:selects.bzl", "selects") - -config_setting( - name = "cbc_build", - values = {"define": "cbc=true"}, - visibility = ["//visibility:public"], -) - -selects.config_setting_group( - name = "cbc_linux", - match_all = [":cbc_build", "@bazel_tools//src/conditions:linux"], -) - -selects.config_setting_group( - name = "cbc_windows", - match_all = [":cbc_build", "@bazel_tools//src/conditions:windows"], -) - -config_setting( - name = "cplex_build", - values = {"define": "cplex=true"}, - visibility = ["//visibility:public"], -) - -config_setting( - name = "gurobi_build", - values = {"define": "gurobi=true"}, - visibility = ["//visibility:public"], -) - -load("//setcoveringsolver:variables.bzl", "STDCPP", - "CBC_COPTS", "CBC_DEP", - "CPLEX_COPTS", "CPLEX_DEP", - "GUROBI_COPTS", "GUROBI_DEP") - -cc_library( - name = "data", - hdrs = [ - "instance.hpp", - "instance_builder.hpp", - "solution.hpp", - "reduction.hpp", - "algorithm.hpp", - "algorithm_formatter.hpp", - ], - srcs = [ - "instance.cpp", - "instance_builder.cpp", - "solution.cpp", - "reduction.cpp", - "algorithm.cpp", - "algorithm_formatter.cpp", - ], - deps = [ - "@optimizationtools//optimizationtools/utils:utils", - "@optimizationtools//optimizationtools/containers:containers", - ], - copts = STDCPP, - visibility = ["//visibility:public"], -) - -cc_binary( - name = "main", - srcs = ["main.cpp"], - deps = [ - "//setcoveringsolver/algorithms:greedy", - "//setcoveringsolver/algorithms:milp_cbc", - "//setcoveringsolver/algorithms:milp_gurobi", - "//setcoveringsolver/algorithms:local_search_row_weighting", - "//setcoveringsolver/algorithms:large_neighborhood_search", - "@boost//:program_options", - ] + CBC_DEP + GUROBI_DEP, - copts = CBC_COPTS + GUROBI_COPTS, - linkopts = select({ - "@bazel_tools//src/conditions:windows": [], - "//conditions:default": ["-lpthread"], - }), -) - diff --git a/setcoveringsolver/algorithms/BUILD b/setcoveringsolver/algorithms/BUILD deleted file mode 100644 index 88e39d5..0000000 --- a/setcoveringsolver/algorithms/BUILD +++ /dev/null @@ -1,56 +0,0 @@ -load("//setcoveringsolver:variables.bzl", "STDCPP", - "CBC_COPTS", "CBC_DEP", - "CPLEX_COPTS", "CPLEX_DEP", - "GUROBI_COPTS", "GUROBI_DEP") - -cc_library( - name = "greedy", - hdrs = ["greedy.hpp"], - srcs = ["greedy.cpp"], - deps = ["//setcoveringsolver:data"], - visibility = ["//visibility:public"], -) - -cc_library( - name = "milp_cbc", - hdrs = ["milp_cbc.hpp"], - srcs = ["milp_cbc.cpp"], - deps = [ - "//setcoveringsolver:data", - ] + CBC_DEP, - copts = CBC_COPTS, - visibility = ["//visibility:public"], -) - -cc_library( - name = "milp_gurobi", - hdrs = ["milp_gurobi.hpp"], - srcs = ["milp_gurobi.cpp"], - deps = [ - "//setcoveringsolver:data", - ] + GUROBI_DEP, - copts = GUROBI_COPTS, - visibility = ["//visibility:public"], -) - -cc_library( - name = "local_search_row_weighting", - hdrs = ["local_search_row_weighting.hpp"], - srcs = ["local_search_row_weighting.cpp"], - deps = [ - ":greedy", - "//setcoveringsolver:data", - ], - visibility = ["//visibility:public"], -) - -cc_library( - name = "large_neighborhood_search", - hdrs = ["large_neighborhood_search.hpp"], - srcs = ["large_neighborhood_search.cpp"], - deps = [ - ":greedy", - "//setcoveringsolver:data", - ], - visibility = ["//visibility:public"], -) diff --git a/setcoveringsolver/variables.bzl b/setcoveringsolver/variables.bzl deleted file mode 100644 index 4485f3a..0000000 --- a/setcoveringsolver/variables.bzl +++ /dev/null @@ -1,31 +0,0 @@ -STDCPP = select({ - "@bazel_tools//src/conditions:windows": ['/std:c++latest'], - "//conditions:default": ["-std=c++14"],}) - -CBC_COPTS = select({ - "//setcoveringsolver:cbc_build": ["-DCBC_FOUND"], - "//conditions:default": []}) -CBC_DEP = select({ - "//setcoveringsolver:cbc_windows": ["@cbc_windows//:cbc"], - "//conditions:default": [] - }) + select({ - "//setcoveringsolver:cbc_linux": ["@cbc_linux//:cbc"], - "//conditions:default": []}) - -CPLEX_COPTS = select({ - "//setcoveringsolver:cplex_build": [ - "-DCPLEX_FOUND", - "-m64", - "-DIL_STD"], - "//conditions:default": []}) -CPLEX_DEP = select({ - "//setcoveringsolver:cplex_build": ["@cplex//:cplex"], - "//conditions:default": []}) - -GUROBI_COPTS = select({ - "//setcoveringsolver:gurobi_build": ["-DGUROBI_FOUND"], - "//conditions:default": []}) -GUROBI_DEP = select({ - "//setcoveringsolver:gurobi_build": ["@gurobi//:gurobi"], - "//conditions:default": []}) - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..53dda4b --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,41 @@ +find_package(Threads REQUIRED) +add_library(SetCoveringSolver_set_covering) +target_sources(SetCoveringSolver_set_covering PRIVATE + instance.cpp + instance_builder.cpp + solution.cpp + reduction.cpp + algorithm.cpp + algorithm_formatter.cpp) +target_include_directories(SetCoveringSolver_set_covering PUBLIC + ${PROJECT_SOURCE_DIR}/include) +target_link_libraries(SetCoveringSolver_set_covering PUBLIC + OptimizationTools::utils + OptimizationTools::containers + Threads::Threads) +add_library(SetCoveringSolver::set_covering ALIAS SetCoveringSolver_set_covering) + +add_subdirectory(algorithms) + +add_executable(SetCoveringSolver_main) +target_sources(SetCoveringSolver_main PRIVATE + main.cpp) +target_link_libraries(SetCoveringSolver_main PUBLIC + SetCoveringSolver_greedy + SetCoveringSolver_local_search_row_weighting + SetCoveringSolver_large_neighborhood_search + Boost::program_options) +if(SETCOVERINGSOLVER_USE_CBC) + target_compile_definitions(SetCoveringSolver_main PUBLIC + CBC_FOUND=1) + target_link_libraries(SetCoveringSolver_main PUBLIC + SetCoveringSolver_milp_cbc) +endif() +if(SETCOVERINGSOLVER_USE_GUROBI) + target_compile_definitions(SetCoveringSolver_main PUBLIC + GUROBI_FOUND=1) + target_link_libraries(SetCoveringSolver_main PUBLIC + SetCoveringSolver_milp_gurobi) +endif() +set_target_properties(SetCoveringSolver_main PROPERTIES OUTPUT_NAME "setcoveringsolver") +install(TARGETS SetCoveringSolver_main) diff --git a/setcoveringsolver/algorithm.cpp b/src/algorithm.cpp similarity index 100% rename from setcoveringsolver/algorithm.cpp rename to src/algorithm.cpp diff --git a/setcoveringsolver/algorithm_formatter.cpp b/src/algorithm_formatter.cpp similarity index 96% rename from setcoveringsolver/algorithm_formatter.cpp rename to src/algorithm_formatter.cpp index 251efb8..60ef311 100644 --- a/setcoveringsolver/algorithm_formatter.cpp +++ b/src/algorithm_formatter.cpp @@ -18,10 +18,6 @@ void AlgorithmFormatter::start( << " SetCoveringSolver " << std::endl << "=====================================" << std::endl << std::endl - << "Problem" << std::endl - << "-------" << std::endl - << "Set covering problem" << std::endl - << std::endl << "Instance" << std::endl << "--------" << std::endl; output_.solution.instance().format(*os_, parameters_.verbosity_level); diff --git a/src/algorithms/CMakeLists.txt b/src/algorithms/CMakeLists.txt new file mode 100644 index 0000000..52f8975 --- /dev/null +++ b/src/algorithms/CMakeLists.txt @@ -0,0 +1,50 @@ +add_library(SetCoveringSolver_greedy) +target_sources(SetCoveringSolver_greedy PRIVATE + greedy.cpp) +target_include_directories(SetCoveringSolver_greedy PUBLIC + ${PROJECT_SOURCE_DIR}/include) +target_link_libraries(SetCoveringSolver_greedy PUBLIC + SetCoveringSolver_set_covering) +add_library(SetCoveringSolver::greedy ALIAS SetCoveringSolver_greedy) + +if(SETCOVERINGSOLVER_USE_CBC) + add_library(SetCoveringSolver_milp_cbc) + target_sources(SetCoveringSolver_milp_cbc PRIVATE + milp_cbc.cpp) + target_include_directories(SetCoveringSolver_milp_cbc PUBLIC + ${PROJECT_SOURCE_DIR}/include) + target_link_libraries(SetCoveringSolver_milp_cbc PUBLIC + SetCoveringSolver_set_covering + MathOptSolversCMake::cbc) + add_library(SetCoveringSolver::milp_cbc ALIAS SetCoveringSolver_milp_cbc) +endif() + +if(SETCOVERINGSOLVER_USE_GUROBI) + add_library(SetCoveringSolver_milp_gurobi) + target_sources(SetCoveringSolver_milp_gurobi PRIVATE + milp_gurobi.cpp) + target_include_directories(SetCoveringSolver_milp_gurobi PUBLIC + ${PROJECT_SOURCE_DIR}/include) + target_link_libraries(SetCoveringSolver_milp_gurobi PUBLIC + SetCoveringSolver_set_covering + MathOptSolversCMake::gurobi) + add_library(SetCoveringSolver::milp_gurobi ALIAS SetCoveringSolver_milp_gurobi) +endif() + +add_library(SetCoveringSolver_local_search_row_weighting) +target_sources(SetCoveringSolver_local_search_row_weighting PRIVATE + local_search_row_weighting.cpp) +target_include_directories(SetCoveringSolver_local_search_row_weighting PUBLIC + ${PROJECT_SOURCE_DIR}/include) +target_link_libraries(SetCoveringSolver_local_search_row_weighting PUBLIC + SetCoveringSolver_set_covering) +add_library(SetCoveringSolver::local_search_row_weighting ALIAS SetCoveringSolver_local_search_row_weighting) + +add_library(SetCoveringSolver_large_neighborhood_search) +target_sources(SetCoveringSolver_large_neighborhood_search PRIVATE + large_neighborhood_search.cpp) +target_include_directories(SetCoveringSolver_large_neighborhood_search PUBLIC + ${PROJECT_SOURCE_DIR}/include) +target_link_libraries(SetCoveringSolver_large_neighborhood_search PUBLIC + SetCoveringSolver_set_covering) +add_library(SetCoveringSolver::large_neighborhood_search ALIAS SetCoveringSolver_large_neighborhood_search) diff --git a/setcoveringsolver/algorithms/greedy.cpp b/src/algorithms/greedy.cpp similarity index 100% rename from setcoveringsolver/algorithms/greedy.cpp rename to src/algorithms/greedy.cpp diff --git a/setcoveringsolver/algorithms/large_neighborhood_search.cpp b/src/algorithms/large_neighborhood_search.cpp similarity index 100% rename from setcoveringsolver/algorithms/large_neighborhood_search.cpp rename to src/algorithms/large_neighborhood_search.cpp diff --git a/setcoveringsolver/algorithms/local_search_row_weighting.cpp b/src/algorithms/local_search_row_weighting.cpp similarity index 100% rename from setcoveringsolver/algorithms/local_search_row_weighting.cpp rename to src/algorithms/local_search_row_weighting.cpp diff --git a/setcoveringsolver/algorithms/milp_cbc.cpp b/src/algorithms/milp_cbc.cpp similarity index 99% rename from setcoveringsolver/algorithms/milp_cbc.cpp rename to src/algorithms/milp_cbc.cpp index 05adf21..fcb0623 100644 --- a/setcoveringsolver/algorithms/milp_cbc.cpp +++ b/src/algorithms/milp_cbc.cpp @@ -1,5 +1,3 @@ -#if CBC_FOUND - #include "setcoveringsolver/algorithms/milp_cbc.hpp" #include "setcoveringsolver/algorithm_formatter.hpp" @@ -281,5 +279,3 @@ const Output setcoveringsolver::milp_cbc( algorithm_formatter.end(); return output; } - -#endif diff --git a/setcoveringsolver/algorithms/milp_gurobi.cpp b/src/algorithms/milp_gurobi.cpp similarity index 99% rename from setcoveringsolver/algorithms/milp_gurobi.cpp rename to src/algorithms/milp_gurobi.cpp index cfe3777..7eed304 100644 --- a/setcoveringsolver/algorithms/milp_gurobi.cpp +++ b/src/algorithms/milp_gurobi.cpp @@ -1,5 +1,3 @@ -#if GUROBI_FOUND - #include "setcoveringsolver/algorithms/milp_gurobi.hpp" #include "setcoveringsolver/algorithm_formatter.hpp" @@ -170,5 +168,3 @@ const Output setcoveringsolver::milp_gurobi( algorithm_formatter.end(); return output; } - -#endif diff --git a/setcoveringsolver/instance.cpp b/src/instance.cpp similarity index 100% rename from setcoveringsolver/instance.cpp rename to src/instance.cpp diff --git a/setcoveringsolver/instance_builder.cpp b/src/instance_builder.cpp similarity index 100% rename from setcoveringsolver/instance_builder.cpp rename to src/instance_builder.cpp diff --git a/setcoveringsolver/main.cpp b/src/main.cpp similarity index 99% rename from setcoveringsolver/main.cpp rename to src/main.cpp index 3fe1039..776c65f 100644 --- a/setcoveringsolver/main.cpp +++ b/src/main.cpp @@ -3,7 +3,9 @@ #include "setcoveringsolver/solution.hpp" #include "setcoveringsolver/algorithms/greedy.hpp" #include "setcoveringsolver/algorithms/milp_cbc.hpp" +#if GUROBI_FOUND #include "setcoveringsolver/algorithms/milp_gurobi.hpp" +#endif #include "setcoveringsolver/algorithms/local_search_row_weighting.hpp" #include "setcoveringsolver/algorithms/large_neighborhood_search.hpp" diff --git a/setcoveringsolver/reduction.cpp b/src/reduction.cpp similarity index 100% rename from setcoveringsolver/reduction.cpp rename to src/reduction.cpp diff --git a/setcoveringsolver/solution.cpp b/src/solution.cpp similarity index 100% rename from setcoveringsolver/solution.cpp rename to src/solution.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..1735d91 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(algorithms) diff --git a/test/algorithms/CMakeLists.txt b/test/algorithms/CMakeLists.txt new file mode 100644 index 0000000..e69de29