From fe0e77dd2f62daed1a1409be94a4e8dbd17768ea Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Mon, 6 Nov 2023 11:08:39 +0100 Subject: [PATCH 1/3] base: add IsDirectory() --- ortools/base/filesystem.cc | 13 +++++++++++++ ortools/base/filesystem.h | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ortools/base/filesystem.cc b/ortools/base/filesystem.cc index 0650ad25e3..fa973ba352 100644 --- a/ortools/base/filesystem.cc +++ b/ortools/base/filesystem.cc @@ -13,6 +13,8 @@ #include "ortools/base/filesystem.h" +#include // NOLINT(build/c++17) + #include "absl/status/status.h" namespace file { @@ -21,4 +23,15 @@ absl::Status Match(std::string_view pattern, std::vector* result, const file::Options& options) { return absl::Status(); } + +absl::Status IsDirectory(std::string_view path, const file::Options& options) { + (void)options; + if (std::filesystem::is_directory(std::filesystem::path(path))) { + return absl::OkStatus(); + } else { + return absl::Status(absl::StatusCode::kFailedPrecondition, + absl::StrCat(path, " exists, but is not a directory")); + } +} + } // namespace file diff --git a/ortools/base/filesystem.h b/ortools/base/filesystem.h index 40b1aadfdb..edca8ddc26 100644 --- a/ortools/base/filesystem.h +++ b/ortools/base/filesystem.h @@ -19,7 +19,6 @@ #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "ortools/base/file.h" namespace file { @@ -27,6 +26,8 @@ namespace file { absl::Status Match(std::string_view pattern, std::vector* result, const file::Options& options); +absl::Status IsDirectory(std::string_view path, const file::Options& options); + } // namespace file #endif // OR_TOOLS_BASE_FILESYSTEM_H_ From 95a6f84bc6da2f91b824b2c97d572053414f847f Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Mon, 6 Nov 2023 11:19:29 +0100 Subject: [PATCH 2/3] packing: Add README.md --- ortools/packing/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ortools/packing/README.md diff --git a/ortools/packing/README.md b/ortools/packing/README.md new file mode 100644 index 0000000000..027a57638d --- /dev/null +++ b/ortools/packing/README.md @@ -0,0 +1,15 @@ +# Packing + +This folder contains utilities and solvers for several packing problems: +knapsack and bin packing, including generalizations. The solvers take as input a +problem description in ProtoBuf. + +## Knapsack + +A typical knapsack problem considers a single container (the knapsack) and many +items. The container has a maximum capacity, items have both a weight and a +value. The goal is to find the subset of items that respects the capacity +constraint and has the maximum value. There can be only one container. More +generally, the knapsack problem models resource allocation. + +More information on [Wikipedia](https://en.wikipedia.org/wiki/Knapsack_problem). From a33bf9a8d80711f4bb80199aa88d64506cfb8812 Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Mon, 6 Nov 2023 14:59:27 +0100 Subject: [PATCH 3/3] cmake: Rework add_cxx_test --- cmake/cpp.cmake | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/cmake/cpp.cmake b/cmake/cpp.cmake index 4d8478c95a..9cd60d87e4 100644 --- a/cmake/cpp.cmake +++ b/cmake/cpp.cmake @@ -590,24 +590,31 @@ endfunction() # Parameters: # the C++ filename # e.g.: -# add_cxx_test(foo.cc) +# add_cxx_test(foo_test.cc) function(add_cxx_test FILE_NAME) message(STATUS "Configuring test ${FILE_NAME}: ...") get_filename_component(TEST_NAME ${FILE_NAME} NAME_WE) get_filename_component(COMPONENT_DIR ${FILE_NAME} DIRECTORY) get_filename_component(COMPONENT_NAME ${COMPONENT_DIR} NAME) - if(APPLE) - set(CMAKE_INSTALL_RPATH - "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path") - elseif(UNIX) - set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN/../lib64:$ORIGIN/../lib:$ORIGIN") - endif() - add_executable(${TEST_NAME} ${FILE_NAME}) target_include_directories(${TEST_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_features(${TEST_NAME} PRIVATE cxx_std_17) - target_link_libraries(${TEST_NAME} PRIVATE ${PROJECT_NAMESPACE}::ortools) + target_link_libraries(${TEST_NAME} PRIVATE + ${PROJECT_NAMESPACE}::ortools + ) + + include(GNUInstallDirs) + if(APPLE) + set_target_properties(${TEST_NAME} PROPERTIES INSTALL_RPATH + "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path") + elseif(UNIX) + cmake_path(RELATIVE_PATH CMAKE_INSTALL_FULL_LIBDIR + BASE_DIRECTORY ${CMAKE_INSTALL_FULL_BINDIR} + OUTPUT_VARIABLE libdir_relative_path) + set_target_properties(${TEST_NAME} PROPERTIES + INSTALL_RPATH "$ORIGIN/${libdir_relative_path}") + endif() if(BUILD_TESTING) add_test(NAME cxx_${COMPONENT_NAME}_${TEST_NAME} COMMAND ${TEST_NAME})