Merge branch 'main' of github.com:google/or-tools

This commit is contained in:
Laurent Perron
2023-11-07 09:45:48 +01:00
4 changed files with 46 additions and 10 deletions

View File

@@ -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})

View File

@@ -13,6 +13,8 @@
#include "ortools/base/filesystem.h"
#include <filesystem> // NOLINT(build/c++17)
#include "absl/status/status.h"
namespace file {
@@ -21,4 +23,15 @@ absl::Status Match(std::string_view pattern, std::vector<std::string>* 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

View File

@@ -19,7 +19,6 @@
#include <vector>
#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<std::string>* result,
const file::Options& options);
absl::Status IsDirectory(std::string_view path, const file::Options& options);
} // namespace file
#endif // OR_TOOLS_BASE_FILESYSTEM_H_

15
ortools/packing/README.md Normal file
View File

@@ -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).