remove pywrap prefix for pybind11 generated modules
This commit is contained in:
@@ -318,8 +318,8 @@ add_custom_command(
|
||||
COMMAND ${CMAKE_COMMAND} -E $<IF:$<STREQUAL:$<TARGET_PROPERTY:ortools,TYPE>,SHARED_LIBRARY>,copy,true>
|
||||
$<$<STREQUAL:$<TARGET_PROPERTY:ortools,TYPE>,SHARED_LIBRARY>:$<TARGET_SONAME_FILE:ortools>>
|
||||
${PYTHON_PROJECT}/.libs
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pywrapinit> ${PYTHON_PROJECT}/init/python
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pywrapknapsack_solver> ${PYTHON_PROJECT}/algorithms/python
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:init> ${PYTHON_PROJECT}/init/python
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:knapsack_solver> ${PYTHON_PROJECT}/algorithms/python
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:linear_sum_assignment_pybind11> ${PYTHON_PROJECT}/graph/python
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:max_flow_pybind11> ${PYTHON_PROJECT}/graph/python
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:min_cost_flow_pybind11> ${PYTHON_PROJECT}/graph/python
|
||||
@@ -328,7 +328,7 @@ add_custom_command(
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pywrap_model_builder_helper> ${PYTHON_PROJECT}/linear_solver/python
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pywrap_pdlp_pybind11> ${PYTHON_PROJECT}/pdlp/python
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:swig_helper> ${PYTHON_PROJECT}/sat/python
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pywrap_rcpsp> ${PYTHON_PROJECT}/scheduling/python
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:rcpsp> ${PYTHON_PROJECT}/scheduling/python
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:sorted_interval_list> ${PYTHON_PROJECT}/util/python
|
||||
#COMMAND ${Python3_EXECUTABLE} setup.py bdist_egg bdist_wheel
|
||||
COMMAND ${Python3_EXECUTABLE} setup.py bdist_wheel
|
||||
@@ -339,8 +339,8 @@ add_custom_command(
|
||||
python/setup.py
|
||||
Py${PROJECT_NAME}_proto
|
||||
${PROJECT_NAMESPACE}::ortools
|
||||
pywrapinit
|
||||
pywrapknapsack_solver
|
||||
init
|
||||
knapsack_solver
|
||||
linear_sum_assignment_pybind11
|
||||
max_flow_pybind11
|
||||
min_cost_flow_pybind11
|
||||
@@ -349,7 +349,7 @@ add_custom_command(
|
||||
pywrap_model_builder_helper
|
||||
pywrap_pdlp_pybind11
|
||||
swig_helper
|
||||
pywrap_rcpsp
|
||||
rcpsp
|
||||
sorted_interval_list
|
||||
BYPRODUCTS
|
||||
python/${PYTHON_PROJECT}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
"""Sample to test or-tools installation."""
|
||||
import ortools
|
||||
# from ortools.algorithms import pywrapknapsack_solver
|
||||
# from ortools.algorithms import knapsack_solver
|
||||
from ortools.constraint_solver import pywrapcp
|
||||
# from ortools.graph.python import linear_sum_assignment
|
||||
# from ortools.graph.python import max_flow
|
||||
@@ -23,7 +23,7 @@ from ortools.linear_solver import pywraplp
|
||||
# from ortools.linear_solver import linear_solver_pb2
|
||||
# from ortools.sat.python import swig_helper
|
||||
# from ortools.sat.python import cp_model
|
||||
# from ortools.scheduling import pywraprcpsp
|
||||
# from ortools.scheduling import rcpsp
|
||||
# from ortools.util.python import sorted_interval_list
|
||||
|
||||
|
||||
|
||||
@@ -16,11 +16,12 @@
|
||||
load("@pip_deps//:requirements.bzl", "requirement")
|
||||
|
||||
PYTHON_DEPS = [
|
||||
"//ortools/init/python:init",
|
||||
"//ortools/linear_solver/python:model_builder",
|
||||
"//ortools/sat/python:cp_model",
|
||||
"//ortools/sat/colab:visualization",
|
||||
"//ortools/scheduling:rcpsp_py_proto",
|
||||
"//ortools/scheduling/python:pywrap_rcpsp",
|
||||
"//ortools/scheduling/python:rcpsp",
|
||||
requirement("absl-py"),
|
||||
requirement("numpy"),
|
||||
requirement("pandas"),
|
||||
|
||||
@@ -30,7 +30,7 @@ from absl import flags
|
||||
from google.protobuf import text_format
|
||||
from ortools.sat.python import cp_model
|
||||
from ortools.scheduling import rcpsp_pb2
|
||||
from ortools.scheduling.python import pywrap_rcpsp
|
||||
from ortools.scheduling.python import rcpsp
|
||||
|
||||
_INPUT = flags.DEFINE_string("input", "", "Input file to parse and solve.")
|
||||
_OUTPUT_PROTO = flags.DEFINE_string(
|
||||
@@ -741,7 +741,7 @@ def ComputePreemptiveLowerBound(problem, after, lower_bound):
|
||||
|
||||
|
||||
def main(_):
|
||||
rcpsp_parser = pywrap_rcpsp.RcpspParser()
|
||||
rcpsp_parser = rcpsp.RcpspParser()
|
||||
rcpsp_parser.parse_file(_INPUT.value)
|
||||
|
||||
problem = rcpsp_parser.problem()
|
||||
|
||||
@@ -72,8 +72,8 @@ class BaseKnapsackSolver;
|
||||
]
|
||||
capacities = [ 34, 4 ]
|
||||
|
||||
solver = pywrapknapsack_solver.KnapsackSolver(
|
||||
pywrapknapsack_solver.SolverType
|
||||
solver = knapsack_solver.KnapsackSolver(
|
||||
knapsack_solver.SolverType
|
||||
.KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER,
|
||||
'Multi-dimensional solver')
|
||||
solver.init(profits, weights, capacities)
|
||||
|
||||
@@ -44,14 +44,14 @@ config_setting(
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "pywrapknapsack_solver_doc",
|
||||
hdrs = ["pywrapknapsack_solver_doc.h"],
|
||||
name = "knapsack_solver_doc",
|
||||
hdrs = ["knapsack_solver_doc.h"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
pybind_extension(
|
||||
name = "pywrapknapsack_solver",
|
||||
srcs = ["pywrapknapsack_solver.cc"],
|
||||
name = "knapsack_solver",
|
||||
srcs = ["knapsack_solver.cc"],
|
||||
copts = [] + select({
|
||||
":use_cbc": ["-DUSE_CBC"],
|
||||
"//conditions:default": [],
|
||||
@@ -61,18 +61,18 @@ pybind_extension(
|
||||
}),
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":pywrapknapsack_solver_doc",
|
||||
":knapsack_solver_doc",
|
||||
"//ortools/algorithms:knapsack_solver_lib",
|
||||
"@com_google_absl//absl/strings",
|
||||
],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "pywrapknapsack_solver_test",
|
||||
srcs = ["pywrapknapsack_solver_test.py"],
|
||||
name = "knapsack_solver_test",
|
||||
srcs = ["knapsack_solver_test.py"],
|
||||
python_version = "PY3",
|
||||
deps = [
|
||||
":pywrapknapsack_solver",
|
||||
":knapsack_solver",
|
||||
requirement("absl-py"),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -11,23 +11,23 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
pybind11_add_module(pywrapknapsack_solver MODULE pywrapknapsack_solver.cc)
|
||||
pybind11_add_module(knapsack_solver MODULE knapsack_solver.cc)
|
||||
# note: macOS is APPLE and also UNIX !
|
||||
if(APPLE)
|
||||
set_target_properties(pywrapknapsack_solver PROPERTIES
|
||||
set_target_properties(knapsack_solver PROPERTIES
|
||||
SUFFIX ".so"
|
||||
INSTALL_RPATH "@loader_path;@loader_path/../../../${PYTHON_PROJECT}/.libs"
|
||||
)
|
||||
set_property(TARGET pywrapknapsack_solver APPEND PROPERTY
|
||||
set_property(TARGET knapsack_solver APPEND PROPERTY
|
||||
LINK_FLAGS "-flat_namespace -undefined suppress"
|
||||
)
|
||||
elseif(UNIX)
|
||||
set_target_properties(pywrapknapsack_solver PROPERTIES
|
||||
set_target_properties(knapsack_solver PROPERTIES
|
||||
INSTALL_RPATH "$ORIGIN:$ORIGIN/../../../${PYTHON_PROJECT}/.libs"
|
||||
)
|
||||
endif()
|
||||
target_link_libraries(pywrapknapsack_solver PRIVATE ${PROJECT_NAMESPACE}::ortools)
|
||||
add_library(${PROJECT_NAMESPACE}::pywrapknapsack_solver ALIAS pywrapknapsack_solver)
|
||||
target_link_libraries(knapsack_solver PRIVATE ${PROJECT_NAMESPACE}::ortools)
|
||||
add_library(${PROJECT_NAMESPACE}::knapsack_solver ALIAS knapsack_solver)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
file(GLOB PYTHON_SRCS "*_test.py")
|
||||
|
||||
@@ -13,10 +13,11 @@
|
||||
|
||||
// A pybind11 wrapper for knapsack_solver.
|
||||
|
||||
#include "ortools/algorithms/knapsack_solver.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ortools/algorithms/knapsack_solver.h"
|
||||
#include "ortools/algorithms/python/pywrapknapsack_solver_doc.h"
|
||||
#include "ortools/algorithms/python/knapsack_solver_doc.h"
|
||||
#include "pybind11/pybind11.h"
|
||||
#include "pybind11/pytypes.h"
|
||||
#include "pybind11/stl.h"
|
||||
@@ -26,7 +27,7 @@ using ::operations_research::KnapsackSolver;
|
||||
namespace py = pybind11;
|
||||
using ::py::arg;
|
||||
|
||||
PYBIND11_MODULE(pywrapknapsack_solver, m) {
|
||||
PYBIND11_MODULE(knapsack_solver, m) {
|
||||
py::class_<KnapsackSolver>(m, "KnapsackSolver",
|
||||
DOC(operations_research, KnapsackSolver))
|
||||
.def(py::init<KnapsackSolver::SolverType, const std::string&>())
|
||||
@@ -1,238 +1,48 @@
|
||||
// Copyright 2010-2022 Google LLC
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef OR_TOOLS_ALGORITHMS_PYTHON_knapsack_SOLVER_DOC_H_
|
||||
#define OR_TOOLS_ALGORITHMS_PYTHON_knapsack_SOLVER_DOC_H_
|
||||
|
||||
/*
|
||||
This file contains docstrings for use in the Python bindings.
|
||||
Do not edit! They were automatically extracted by pybind11_mkdoc.
|
||||
*/
|
||||
|
||||
#define __EXPAND(x) x
|
||||
#define __COUNT(_1, _2, _3, _4, _5, _6, _7, COUNT, ...) COUNT
|
||||
#define __VA_SIZE(...) __EXPAND(__COUNT(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0))
|
||||
#define __CAT1(a, b) a ## b
|
||||
#define __CAT2(a, b) __CAT1(a, b)
|
||||
#define __DOC1(n1) __doc_##n1
|
||||
#define __DOC2(n1, n2) __doc_##n1##_##n2
|
||||
#define __DOC3(n1, n2, n3) __doc_##n1##_##n2##_##n3
|
||||
#define __DOC4(n1, n2, n3, n4) __doc_##n1##_##n2##_##n3##_##n4
|
||||
#define __DOC5(n1, n2, n3, n4, n5) __doc_##n1##_##n2##_##n3##_##n4##_##n5
|
||||
#define __DOC6(n1, n2, n3, n4, n5, n6) __doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6
|
||||
#define __DOC7(n1, n2, n3, n4, n5, n6, n7) __doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7
|
||||
#define DOC(...) __EXPAND(__EXPAND(__CAT2(__DOC, __VA_SIZE(__VA_ARGS__)))(__VA_ARGS__))
|
||||
#define __EXPAND(x) x
|
||||
#define __COUNT(_1, _2, _3, _4, _5, _6, _7, COUNT, ...) COUNT
|
||||
#define __VA_SIZE(...) __EXPAND(__COUNT(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0))
|
||||
#define __CAT1(a, b) a##b
|
||||
#define __CAT2(a, b) __CAT1(a, b)
|
||||
#define __DOC1(n1) __doc_##n1
|
||||
#define __DOC2(n1, n2) __doc_##n1##_##n2
|
||||
#define __DOC3(n1, n2, n3) __doc_##n1##_##n2##_##n3
|
||||
#define __DOC4(n1, n2, n3, n4) __doc_##n1##_##n2##_##n3##_##n4
|
||||
#define __DOC5(n1, n2, n3, n4, n5) __doc_##n1##_##n2##_##n3##_##n4##_##n5
|
||||
#define __DOC6(n1, n2, n3, n4, n5, n6) \
|
||||
__doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6
|
||||
#define __DOC7(n1, n2, n3, n4, n5, n6, n7) \
|
||||
__doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7
|
||||
#define DOC(...) \
|
||||
__EXPAND(__EXPAND(__CAT2(__DOC, __VA_SIZE(__VA_ARGS__)))(__VA_ARGS__))
|
||||
|
||||
#if defined(__GNUG__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#endif
|
||||
|
||||
|
||||
static const char *__doc_operations_research_BaseKnapsackSolver = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_BaseKnapsackSolver_2 = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_BaseKnapsackSolver_BaseKnapsackSolver = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_BaseKnapsackSolver_GetLowerAndUpperBoundWhenItem = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_BaseKnapsackSolver_GetName = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_BaseKnapsackSolver_Init = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_BaseKnapsackSolver_Solve = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_BaseKnapsackSolver_best_solution = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_BaseKnapsackSolver_solver_name = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackAssignment = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackAssignment_KnapsackAssignment = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackAssignment_is_in = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackAssignment_item_id = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackCapacityPropagator = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackCapacityPropagator_ComputeProfitBounds = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackCapacityPropagator_CopyCurrentStateToSolutionPropagator = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackCapacityPropagator_GetAdditionalProfit = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackCapacityPropagator_GetNextItemId = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackCapacityPropagator_InitPropagator = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackCapacityPropagator_KnapsackCapacityPropagator = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackCapacityPropagator_UpdatePropagator = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackCapacityPropagator_break_item_id = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackCapacityPropagator_capacity = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackCapacityPropagator_consumed_capacity = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackCapacityPropagator_profit_max = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackCapacityPropagator_sorted_items = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_Clear = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_GetAggregatedProfitUpperBound = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_GetCurrentProfit = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_GetLowerAndUpperBoundWhenItem = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_GetNextItemId = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_GetNumberOfItems = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_HasOnePropagator = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_IncrementalUpdate = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_Init = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_KnapsackGenericSolver = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_MakeNewNode = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_Solve = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_UpdateBestSolution = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_UpdatePropagators = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_best_solution = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_best_solution_2 = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_best_solution_profit = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_primary_propagator_id = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_propagators = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_search_nodes = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_set_primary_propagator_id = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackGenericSolver_state = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackItem = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackItem_GetEfficiency = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackItem_KnapsackItem = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackItem_id = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackItem_profit = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackItem_weight = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_ComputeProfitBounds = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_CopyCurrentStateToSolution = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_CopyCurrentStateToSolutionPropagator = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_GetNextItemId = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_Init = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_InitPropagator = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_KnapsackPropagator = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_Update = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_UpdatePropagator = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_current_profit = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_current_profit_2 = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_items = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_items_2 = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_profit_lower_bound = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_profit_lower_bound_2 = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_profit_upper_bound = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_profit_upper_bound_2 = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_set_profit_lower_bound = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_set_profit_upper_bound = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_state = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackPropagator_state_2 = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode_KnapsackSearchNode = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode_assignment = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode_assignment_2 = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode_current_profit = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode_current_profit_2 = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode_depth = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode_depth_2 = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode_next_item_id = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode_next_item_id_2 = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode_parent = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode_parent_2 = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode_profit_upper_bound = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode_profit_upper_bound_2 = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode_set_current_profit = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode_set_next_item_id = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchNode_set_profit_upper_bound = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchPath = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchPath_Init = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchPath_KnapsackSearchPath = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchPath_MoveUpToDepth = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchPath_from = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchPath_from_2 = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchPath_to = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchPath_to_2 = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchPath_via = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSearchPath_via_2 = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver =
|
||||
R"doc(This library solves knapsack problems.
|
||||
static const char* __doc_operations_research_KnapsackSolver =
|
||||
R"doc(This library solves knapsack problems.
|
||||
|
||||
Problems the library solves include: - 0-1 knapsack problems, - Multi-
|
||||
dimensional knapsack problems,
|
||||
@@ -276,12 +86,12 @@ weights = [ [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ],
|
||||
]
|
||||
capacities = [ 34, 4 ]
|
||||
|
||||
solver = pywrapknapsack_solver.KnapsackSolver(
|
||||
pywrapknapsack_solver.KnapsackSolver
|
||||
solver = knapsack_solver.KnapsackSolver(
|
||||
knapsack_solver.KnapsackSolver
|
||||
.KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER,
|
||||
'Multi-dimensional solver')
|
||||
solver.Init(profits, weights, capacities)
|
||||
profit = solver.Solve()
|
||||
solver.init(profits, weights, capacities)
|
||||
profit = solver.solve()
|
||||
```
|
||||
|
||||
**C++:**
|
||||
@@ -317,118 +127,169 @@ solver.init(profits, weights, capacities);
|
||||
final long profit = solver.solve();
|
||||
```)doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_BestSolutionContains = R"doc(Returns true if the item 'item_id' is packed in the optimal knapsack.)doc";
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_BestSolutionContains = // NOLINT
|
||||
R"doc(Returns true if the item 'item_id' is packed in the optimal knapsack.)doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_ComputeAdditionalProfit = R"doc()doc";
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_ComputeAdditionalProfit =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_GetName = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_GetName =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_Init = R"doc(Initializes the solver and enters the problem to be solved.)doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_Init =
|
||||
R"doc(Initializes the solver and enters the problem to be solved.)doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_InitReducedProblem = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_InitReducedProblem =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_IsSolutionOptimal = R"doc(Returns true if the solution was proven optimal.)doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_IsSolutionOptimal =
|
||||
R"doc(Returns true if the solution was proven optimal.)doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_KnapsackSolver = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_KnapsackSolver =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_KnapsackSolver_2 = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_KnapsackSolver_2 =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_ReduceCapacities = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_ReduceCapacities =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_ReduceProblem = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_ReduceProblem =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_Solve = R"doc(Solves the problem and returns the profit of the optimal solution.)doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_Solve =
|
||||
R"doc(Solves the problem and returns the profit of the optimal solution.)doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_SolverType =
|
||||
R"doc(Enum controlling which underlying algorithm is used.
|
||||
static const char* __doc_operations_research_KnapsackSolver_SolverType =
|
||||
R"doc(Enum controlling which underlying algorithm is used.
|
||||
|
||||
This enum is passed to the constructor of the KnapsackSolver object.
|
||||
It selects which solving method will be used.)doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_64ITEMS_SOLVER =
|
||||
R"doc(Optimized method for single dimension small problems
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_64ITEMS_SOLVER = // NOLINT
|
||||
R"doc(Optimized method for single dimension small problems
|
||||
|
||||
Limited to 64 items and one dimension, this solver uses a branch &
|
||||
bound algorithm. This solver is about 4 times faster than
|
||||
KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER.)doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_BRUTE_FORCE_SOLVER =
|
||||
R"doc(Brute force method.
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_BRUTE_FORCE_SOLVER = // NOLINT
|
||||
R"doc(Brute force method.
|
||||
|
||||
Limited to 30 items and one dimension, this solver uses a brute force
|
||||
algorithm, ie. explores all possible states. Experiments show
|
||||
competitive performance for instances with less than 15 items.)doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_DIVIDE_AND_CONQUER_SOLVER =
|
||||
R"doc(Divide and Conquer approach for single dimension problems
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_DIVIDE_AND_CONQUER_SOLVER = // NOLINT
|
||||
R"doc(Divide and Conquer approach for single dimension problems
|
||||
|
||||
Limited to one dimension, this solver is based on a divide and conquer
|
||||
technique and is suitable for larger problems than Dynamic Programming
|
||||
Solver. The time complexity is O(capacity * number_of_items) and the
|
||||
space complexity is O(capacity + number_of_items).)doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER =
|
||||
R"doc(Dynamic Programming approach for single dimension problems
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER = // NOLINT
|
||||
R"doc(Dynamic Programming approach for single dimension problems
|
||||
|
||||
Limited to one dimension, this solver is based on a dynamic
|
||||
programming algorithm. The time and space complexity is O(capacity *
|
||||
number_of_items).)doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER =
|
||||
R"doc(Generic Solver.
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER = // NOLINT
|
||||
R"doc(Generic Solver.
|
||||
|
||||
This solver can deal with both large number of items and several
|
||||
dimensions. This solver is based on branch and bound.)doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_additional_profit = R"doc()doc";
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER = // NOLINT
|
||||
R"doc(CBC Based Solver
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_best_solution = R"doc()doc";
|
||||
This solver can deal with both large number of items and several
|
||||
dimensions. This solver is based on Integer Programming solver CBC.)doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_is_problem_solved = R"doc()doc";
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_MULTIDIMENSION_SCIP_MIP_SOLVER = // NOLINT
|
||||
R"doc(SCIP based solver
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_is_solution_optimal = R"doc()doc";
|
||||
This solver can deal with both large number of items and several
|
||||
dimensions. This solver is based on Integer Programming solver SCIP.)doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_additional_profit =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_known_value = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_best_solution =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_mapping_reduced_item_id = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_is_problem_solved =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_set_time_limit =
|
||||
R"doc(Time limit in seconds.
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_is_solution_optimal = R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_known_value =
|
||||
R"doc()doc";
|
||||
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_mapping_reduced_item_id =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_set_time_limit =
|
||||
R"doc(Time limit in seconds.
|
||||
|
||||
When a finite time limit is set the solution obtained might not be
|
||||
optimal if the limit is reached.)doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_set_use_reduction = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_set_use_reduction =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_solver = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_solver =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_time_limit = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_time_limit =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_time_limit_seconds = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_time_limit_seconds =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_use_reduction = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_use_reduction =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackSolver_use_reduction_2 = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_use_reduction_2 =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackState = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackState = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackState_GetNumberOfItems = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackState_GetNumberOfItems =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackState_Init = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackState_Init = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackState_KnapsackState = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackState_KnapsackState =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackState_UpdateState = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackState_UpdateState =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackState_is_bound = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackState_is_bound =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackState_is_bound_2 = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackState_is_bound_2 =
|
||||
R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackState_is_in = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackState_is_in = R"doc()doc";
|
||||
|
||||
static const char *__doc_operations_research_KnapsackState_is_in_2 = R"doc()doc";
|
||||
static const char* __doc_operations_research_KnapsackState_is_in_2 =
|
||||
R"doc()doc";
|
||||
|
||||
#if defined(__GNUG__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif // OR_TOOLS_ALGORITHMS_PYTHON_knapsack_SOLVER_DOC_H_
|
||||
|
||||
@@ -14,18 +14,18 @@
|
||||
|
||||
# Copyright 2011 Google Inc. All Rights Reserved.
|
||||
|
||||
"""pywrapknapsack_solver unittest file."""
|
||||
"""knapsack_solver unittest file."""
|
||||
|
||||
from absl import app
|
||||
|
||||
import unittest
|
||||
|
||||
from ortools.algorithms.python import pywrapknapsack_solver
|
||||
from ortools.algorithms.python import knapsack_solver
|
||||
|
||||
|
||||
class PyWrapAlgorithmsKnapsackSolverTest(unittest.TestCase):
|
||||
def RealSolve(self, profits, weights, capacities, solver_type, use_reduction):
|
||||
solver = pywrapknapsack_solver.KnapsackSolver(solver_type, "solver")
|
||||
solver = knapsack_solver.KnapsackSolver(solver_type, "solver")
|
||||
solver.set_use_reduction(use_reduction)
|
||||
solver.init(profits, weights, capacities)
|
||||
profit = solver.solve()
|
||||
@@ -61,7 +61,7 @@ class PyWrapAlgorithmsKnapsackSolverTest(unittest.TestCase):
|
||||
profits,
|
||||
weights,
|
||||
capacities,
|
||||
pywrapknapsack_solver.SolverType.KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER,
|
||||
knapsack_solver.SolverType.KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER,
|
||||
)
|
||||
|
||||
if generic_profit == self._invalid_solution:
|
||||
@@ -73,7 +73,7 @@ class PyWrapAlgorithmsKnapsackSolverTest(unittest.TestCase):
|
||||
# profits,
|
||||
# weights,
|
||||
# capacities,
|
||||
# pywrapknapsack_solver.SolverType.
|
||||
# knapsack_solver.SolverType.
|
||||
# KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER)
|
||||
# if cbc_profit != generic_profit:
|
||||
# return self._invalid_solution
|
||||
@@ -82,7 +82,7 @@ class PyWrapAlgorithmsKnapsackSolverTest(unittest.TestCase):
|
||||
profits,
|
||||
weights,
|
||||
capacities,
|
||||
pywrapknapsack_solver.SolverType.KNAPSACK_MULTIDIMENSION_SCIP_MIP_SOLVER,
|
||||
knapsack_solver.SolverType.KNAPSACK_MULTIDIMENSION_SCIP_MIP_SOLVER,
|
||||
)
|
||||
if scip_profit != generic_profit:
|
||||
return self._invalid_solution
|
||||
@@ -95,7 +95,7 @@ class PyWrapAlgorithmsKnapsackSolverTest(unittest.TestCase):
|
||||
profits,
|
||||
weights,
|
||||
capacities,
|
||||
pywrapknapsack_solver.SolverType.KNAPSACK_BRUTE_FORCE_SOLVER,
|
||||
knapsack_solver.SolverType.KNAPSACK_BRUTE_FORCE_SOLVER,
|
||||
)
|
||||
if brute_force_profit != generic_profit:
|
||||
return self._invalid_solution
|
||||
@@ -105,7 +105,7 @@ class PyWrapAlgorithmsKnapsackSolverTest(unittest.TestCase):
|
||||
profits,
|
||||
weights,
|
||||
capacities,
|
||||
pywrapknapsack_solver.SolverType.KNAPSACK_64ITEMS_SOLVER,
|
||||
knapsack_solver.SolverType.KNAPSACK_64ITEMS_SOLVER,
|
||||
)
|
||||
if items64_profit != generic_profit:
|
||||
return self._invalid_solution
|
||||
@@ -115,7 +115,7 @@ class PyWrapAlgorithmsKnapsackSolverTest(unittest.TestCase):
|
||||
profits,
|
||||
weights,
|
||||
capacities,
|
||||
pywrapknapsack_solver.SolverType.KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER,
|
||||
knapsack_solver.SolverType.KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER,
|
||||
)
|
||||
if dynamic_programming_profit != generic_profit:
|
||||
return self._invalid_solution
|
||||
@@ -125,7 +125,7 @@ class PyWrapAlgorithmsKnapsackSolverTest(unittest.TestCase):
|
||||
profits,
|
||||
weights,
|
||||
capacities,
|
||||
pywrapknapsack_solver.SolverType.KNAPSACK_DIVIDE_AND_CONQUER_SOLVER,
|
||||
knapsack_solver.SolverType.KNAPSACK_DIVIDE_AND_CONQUER_SOLVER,
|
||||
)
|
||||
if divide_and_conquer_profit != generic_profit:
|
||||
return self._invalid_solution
|
||||
@@ -1,295 +0,0 @@
|
||||
// Copyright 2010-2022 Google LLC
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef OR_TOOLS_ALGORITHMS_PYTHON_PYWRAPKNAPSACK_SOLVER_DOC_H_
|
||||
#define OR_TOOLS_ALGORITHMS_PYTHON_PYWRAPKNAPSACK_SOLVER_DOC_H_
|
||||
|
||||
/*
|
||||
This file contains docstrings for use in the Python bindings.
|
||||
Do not edit! They were automatically extracted by pybind11_mkdoc.
|
||||
*/
|
||||
|
||||
#define __EXPAND(x) x
|
||||
#define __COUNT(_1, _2, _3, _4, _5, _6, _7, COUNT, ...) COUNT
|
||||
#define __VA_SIZE(...) __EXPAND(__COUNT(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0))
|
||||
#define __CAT1(a, b) a##b
|
||||
#define __CAT2(a, b) __CAT1(a, b)
|
||||
#define __DOC1(n1) __doc_##n1
|
||||
#define __DOC2(n1, n2) __doc_##n1##_##n2
|
||||
#define __DOC3(n1, n2, n3) __doc_##n1##_##n2##_##n3
|
||||
#define __DOC4(n1, n2, n3, n4) __doc_##n1##_##n2##_##n3##_##n4
|
||||
#define __DOC5(n1, n2, n3, n4, n5) __doc_##n1##_##n2##_##n3##_##n4##_##n5
|
||||
#define __DOC6(n1, n2, n3, n4, n5, n6) \
|
||||
__doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6
|
||||
#define __DOC7(n1, n2, n3, n4, n5, n6, n7) \
|
||||
__doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7
|
||||
#define DOC(...) \
|
||||
__EXPAND(__EXPAND(__CAT2(__DOC, __VA_SIZE(__VA_ARGS__)))(__VA_ARGS__))
|
||||
|
||||
#if defined(__GNUG__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#endif
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver =
|
||||
R"doc(This library solves knapsack problems.
|
||||
|
||||
Problems the library solves include: - 0-1 knapsack problems, - Multi-
|
||||
dimensional knapsack problems,
|
||||
|
||||
Given n items, each with a profit and a weight, given a knapsack of
|
||||
capacity c, the goal is to find a subset of items which fits inside c
|
||||
and maximizes the total profit. The knapsack problem can easily be
|
||||
extended from 1 to d dimensions. As an example, this can be useful to
|
||||
constrain the maximum number of items inside the knapsack. Without
|
||||
loss of generality, profits and weights are assumed to be positive.
|
||||
|
||||
From a mathematical point of view, the multi-dimensional knapsack
|
||||
problem can be modeled by d linear constraints:
|
||||
|
||||
ForEach(j:1..d)(Sum(i:1..n)(weight_ij * item_i) <= c_j where item_i is
|
||||
a 0-1 integer variable.
|
||||
|
||||
Then the goal is to maximize:
|
||||
|
||||
Sum(i:1..n)(profit_i * item_i).
|
||||
|
||||
There are several ways to solve knapsack problems. One of the most
|
||||
efficient is based on dynamic programming (mainly when weights,
|
||||
profits and dimensions are small, and the algorithm runs in pseudo
|
||||
polynomial time). Unfortunately, when adding conflict constraints the
|
||||
problem becomes strongly NP-hard, i.e. there is no pseudo-polynomial
|
||||
algorithm to solve it. That's the reason why the most of the following
|
||||
code is based on branch and bound search.
|
||||
|
||||
For instance to solve a 2-dimensional knapsack problem with 9 items,
|
||||
one just has to feed a profit vector with the 9 profits, a vector of 2
|
||||
vectors for weights, and a vector of capacities. E.g.:
|
||||
|
||||
**Python:**
|
||||
|
||||
```
|
||||
{.py}
|
||||
profits = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
|
||||
weights = [ [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ],
|
||||
[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
|
||||
]
|
||||
capacities = [ 34, 4 ]
|
||||
|
||||
solver = pywrapknapsack_solver.KnapsackSolver(
|
||||
pywrapknapsack_solver.KnapsackSolver
|
||||
.KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER,
|
||||
'Multi-dimensional solver')
|
||||
solver.init(profits, weights, capacities)
|
||||
profit = solver.solve()
|
||||
```
|
||||
|
||||
**C++:**
|
||||
|
||||
```
|
||||
{.cpp}
|
||||
const std::vector<int64_t> profits = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
const std::vector<std::vector<int64_t>> weights =
|
||||
{ { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
|
||||
{ 1, 1, 1, 1, 1, 1, 1, 1, 1 } };
|
||||
const std::vector<int64_t> capacities = { 34, 4 };
|
||||
|
||||
KnapsackSolver solver(
|
||||
KnapsackSolver::KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER,
|
||||
"Multi-dimensional solver");
|
||||
solver.Init(profits, weights, capacities);
|
||||
const int64_t profit = solver.Solve();
|
||||
```
|
||||
|
||||
**Java:**
|
||||
|
||||
```
|
||||
{.java}
|
||||
final long[] profits = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
final long[][] weights = { { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
|
||||
{ 1, 1, 1, 1, 1, 1, 1, 1, 1 } };
|
||||
final long[] capacities = { 34, 4 };
|
||||
|
||||
KnapsackSolver solver = new KnapsackSolver(
|
||||
KnapsackSolver.SolverType.KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER,
|
||||
"Multi-dimensional solver");
|
||||
solver.init(profits, weights, capacities);
|
||||
final long profit = solver.solve();
|
||||
```)doc";
|
||||
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_BestSolutionContains = // NOLINT
|
||||
R"doc(Returns true if the item 'item_id' is packed in the optimal knapsack.)doc";
|
||||
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_ComputeAdditionalProfit =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_GetName =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_Init =
|
||||
R"doc(Initializes the solver and enters the problem to be solved.)doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_InitReducedProblem =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_IsSolutionOptimal =
|
||||
R"doc(Returns true if the solution was proven optimal.)doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_KnapsackSolver =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_KnapsackSolver_2 =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_ReduceCapacities =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_ReduceProblem =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_Solve =
|
||||
R"doc(Solves the problem and returns the profit of the optimal solution.)doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_SolverType =
|
||||
R"doc(Enum controlling which underlying algorithm is used.
|
||||
|
||||
This enum is passed to the constructor of the KnapsackSolver object.
|
||||
It selects which solving method will be used.)doc";
|
||||
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_64ITEMS_SOLVER = // NOLINT
|
||||
R"doc(Optimized method for single dimension small problems
|
||||
|
||||
Limited to 64 items and one dimension, this solver uses a branch &
|
||||
bound algorithm. This solver is about 4 times faster than
|
||||
KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER.)doc";
|
||||
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_BRUTE_FORCE_SOLVER = // NOLINT
|
||||
R"doc(Brute force method.
|
||||
|
||||
Limited to 30 items and one dimension, this solver uses a brute force
|
||||
algorithm, ie. explores all possible states. Experiments show
|
||||
competitive performance for instances with less than 15 items.)doc";
|
||||
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_DIVIDE_AND_CONQUER_SOLVER = // NOLINT
|
||||
R"doc(Divide and Conquer approach for single dimension problems
|
||||
|
||||
Limited to one dimension, this solver is based on a divide and conquer
|
||||
technique and is suitable for larger problems than Dynamic Programming
|
||||
Solver. The time complexity is O(capacity * number_of_items) and the
|
||||
space complexity is O(capacity + number_of_items).)doc";
|
||||
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER = // NOLINT
|
||||
R"doc(Dynamic Programming approach for single dimension problems
|
||||
|
||||
Limited to one dimension, this solver is based on a dynamic
|
||||
programming algorithm. The time and space complexity is O(capacity *
|
||||
number_of_items).)doc";
|
||||
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER = // NOLINT
|
||||
R"doc(Generic Solver.
|
||||
|
||||
This solver can deal with both large number of items and several
|
||||
dimensions. This solver is based on branch and bound.)doc";
|
||||
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER = // NOLINT
|
||||
R"doc(CBC Based Solver
|
||||
|
||||
This solver can deal with both large number of items and several
|
||||
dimensions. This solver is based on Integer Programming solver CBC.)doc";
|
||||
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_SolverType_KNAPSACK_MULTIDIMENSION_SCIP_MIP_SOLVER = // NOLINT
|
||||
R"doc(SCIP based solver
|
||||
|
||||
This solver can deal with both large number of items and several
|
||||
dimensions. This solver is based on Integer Programming solver SCIP.)doc";
|
||||
static const char* __doc_operations_research_KnapsackSolver_additional_profit =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_best_solution =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_is_problem_solved =
|
||||
R"doc()doc";
|
||||
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_is_solution_optimal = R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_known_value =
|
||||
R"doc()doc";
|
||||
|
||||
static const char*
|
||||
__doc_operations_research_KnapsackSolver_mapping_reduced_item_id =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_set_time_limit =
|
||||
R"doc(Time limit in seconds.
|
||||
|
||||
When a finite time limit is set the solution obtained might not be
|
||||
optimal if the limit is reached.)doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_set_use_reduction =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_solver =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_time_limit =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_time_limit_seconds =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_use_reduction =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackSolver_use_reduction_2 =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackState = R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackState_GetNumberOfItems =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackState_Init = R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackState_KnapsackState =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackState_UpdateState =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackState_is_bound =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackState_is_bound_2 =
|
||||
R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackState_is_in = R"doc()doc";
|
||||
|
||||
static const char* __doc_operations_research_KnapsackState_is_in_2 =
|
||||
R"doc()doc";
|
||||
|
||||
#if defined(__GNUG__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif // OR_TOOLS_ALGORITHMS_PYTHON_PYWRAPKNAPSACK_SOLVER_DOC_H_
|
||||
@@ -41,7 +41,7 @@ def code_sample_py(name):
|
||||
main = name + ".py",
|
||||
deps = [
|
||||
requirement("absl-py"),
|
||||
"//ortools/algorithms/python:pywrapknapsack_solver",
|
||||
"//ortools/algorithms/python:knapsack_solver",
|
||||
],
|
||||
python_version = "PY3",
|
||||
srcs_version = "PY3",
|
||||
@@ -53,7 +53,7 @@ def code_sample_py(name):
|
||||
srcs = [name + ".py"],
|
||||
main = name + ".py",
|
||||
data = [
|
||||
"//ortools/algorithms/python:pywrapknapsack_solver",
|
||||
"//ortools/algorithms/python:knapsack_solver",
|
||||
],
|
||||
deps = [
|
||||
requirement("absl-py"),
|
||||
|
||||
@@ -15,15 +15,15 @@
|
||||
"""A simple knapsack problem."""
|
||||
# [START program]
|
||||
# [START import]
|
||||
from ortools.algorithms.python import pywrapknapsack_solver
|
||||
from ortools.algorithms.python import knapsack_solver
|
||||
# [END import]
|
||||
|
||||
|
||||
def main():
|
||||
# Create the solver.
|
||||
# [START solver]
|
||||
solver = pywrapknapsack_solver.KnapsackSolver(
|
||||
pywrapknapsack_solver.SolverType.KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER,
|
||||
solver = knapsack_solver.KnapsackSolver(
|
||||
knapsack_solver.SolverType.KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER,
|
||||
"KnapsackExample",
|
||||
)
|
||||
# [END solver]
|
||||
|
||||
@@ -15,15 +15,15 @@
|
||||
# [START program]
|
||||
"""A simple knapsack problem."""
|
||||
# [START import]
|
||||
from ortools.algorithms.python import pywrapknapsack_solver
|
||||
from ortools.algorithms.python import knapsack_solver
|
||||
# [END import]
|
||||
|
||||
|
||||
def main():
|
||||
# Create the solver.
|
||||
# [START solver]
|
||||
solver = pywrapknapsack_solver.KnapsackSolver(
|
||||
pywrapknapsack_solver.SolverType.KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER,
|
||||
solver = knapsack_solver.KnapsackSolver(
|
||||
knapsack_solver.SolverType.KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER,
|
||||
"test",
|
||||
)
|
||||
# [END solver]
|
||||
|
||||
@@ -19,27 +19,27 @@ load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
load("@rules_python//python:defs.bzl", "py_test")
|
||||
|
||||
cc_library(
|
||||
name = "pywrapinit_doc",
|
||||
hdrs = ["pywrapinit_doc.h"],
|
||||
name = "init_doc",
|
||||
hdrs = ["init_doc.h"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
pybind_extension(
|
||||
name = "pywrapinit",
|
||||
srcs = ["pywrapinit.cc"],
|
||||
name = "init",
|
||||
srcs = ["init.cc"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":pywrapinit_doc",
|
||||
":init_doc",
|
||||
"//ortools/init",
|
||||
],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "pywrapinit_test",
|
||||
srcs = ["pywrapinit_test.py"],
|
||||
name = "init_test",
|
||||
srcs = ["init_test.py"],
|
||||
python_version = "PY3",
|
||||
deps = [
|
||||
":pywrapinit",
|
||||
":init",
|
||||
requirement("absl-py"),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -11,23 +11,23 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
pybind11_add_module(pywrapinit MODULE pywrapinit.cc)
|
||||
pybind11_add_module(init MODULE init.cc)
|
||||
# note: macOS is APPLE and also UNIX !
|
||||
if(APPLE)
|
||||
set_target_properties(pywrapinit PROPERTIES
|
||||
set_target_properties(init PROPERTIES
|
||||
SUFFIX ".so"
|
||||
INSTALL_RPATH "@loader_path;@loader_path/../../../${PYTHON_PROJECT}/.libs"
|
||||
)
|
||||
set_property(TARGET pywrapinit APPEND PROPERTY
|
||||
set_property(TARGET init APPEND PROPERTY
|
||||
LINK_FLAGS "-flat_namespace -undefined suppress"
|
||||
)
|
||||
elseif(UNIX)
|
||||
set_target_properties(pywrapinit PROPERTIES
|
||||
set_target_properties(init PROPERTIES
|
||||
INSTALL_RPATH "$ORIGIN:$ORIGIN/../../../${PYTHON_PROJECT}/.libs"
|
||||
)
|
||||
endif()
|
||||
target_link_libraries(pywrapinit PRIVATE ${PROJECT_NAMESPACE}::ortools)
|
||||
add_library(${PROJECT_NAMESPACE}::pywrapinit ALIAS pywrapinit)
|
||||
target_link_libraries(init PRIVATE ${PROJECT_NAMESPACE}::ortools)
|
||||
add_library(${PROJECT_NAMESPACE}::init ALIAS init)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
file(GLOB PYTHON_SRCS "*_test.py")
|
||||
|
||||
@@ -13,10 +13,11 @@
|
||||
|
||||
// A pybind11 wrapper for the init library.
|
||||
|
||||
#include "ortools/init/init.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ortools/init/init.h"
|
||||
#include "ortools/init/python/pywrapinit_doc.h"
|
||||
#include "ortools/init/python/init_doc.h"
|
||||
#include "pybind11/pybind11.h"
|
||||
#include "pybind11/pytypes.h"
|
||||
#include "pybind11/stl.h"
|
||||
@@ -28,7 +29,7 @@ using ::operations_research::OrToolsVersion;
|
||||
namespace py = pybind11;
|
||||
using ::py::arg;
|
||||
|
||||
PYBIND11_MODULE(pywrapinit, m) {
|
||||
PYBIND11_MODULE(init, m) {
|
||||
py::class_<CppFlags>(m, "CppFlags", DOC(operations_research, CppFlags))
|
||||
.def(py::init<>())
|
||||
.def_readwrite("stderrthreshold", &CppFlags::stderrthreshold,
|
||||
@@ -14,36 +14,36 @@
|
||||
|
||||
"""Simple unit tests for python/init.i. Not exhaustive."""
|
||||
|
||||
from ortools.init.python import pywrapinit
|
||||
from absl.testing import absltest
|
||||
from ortools.init.python import init
|
||||
|
||||
|
||||
class PyWrapInit(absltest.TestCase):
|
||||
class InitTest(absltest.TestCase):
|
||||
def test_logging(self):
|
||||
print("test_logging")
|
||||
pywrapinit.CppBridge.init_logging("pywrapinit_test.py")
|
||||
pywrapinit.CppBridge.shutdown_logging()
|
||||
init.CppBridge.init_logging("pywrapinit_test.py")
|
||||
init.CppBridge.shutdown_logging()
|
||||
|
||||
def test_flags(self):
|
||||
print("test_cpp_flags")
|
||||
cpp_flags = pywrapinit.CppFlags()
|
||||
cpp_flags = init.CppFlags()
|
||||
assert hasattr(cpp_flags, "stderrthreshold")
|
||||
assert hasattr(cpp_flags, "log_prefix")
|
||||
assert hasattr(cpp_flags, "cp_model_dump_prefix")
|
||||
assert hasattr(cpp_flags, "cp_model_dump_models")
|
||||
assert hasattr(cpp_flags, "cp_model_dump_lns")
|
||||
assert hasattr(cpp_flags, "cp_model_dump_response")
|
||||
pywrapinit.CppBridge.set_flags(cpp_flags)
|
||||
init.CppBridge.set_flags(cpp_flags)
|
||||
|
||||
def test_version(self):
|
||||
print("test_version")
|
||||
major = pywrapinit.OrToolsVersion.major_number()
|
||||
major = init.OrToolsVersion.major_number()
|
||||
self.assertIsInstance(major, int)
|
||||
minor = pywrapinit.OrToolsVersion.minor_number()
|
||||
minor = init.OrToolsVersion.minor_number()
|
||||
self.assertIsInstance(minor, int)
|
||||
patch = pywrapinit.OrToolsVersion.patch_number()
|
||||
patch = init.OrToolsVersion.patch_number()
|
||||
self.assertIsInstance(patch, int)
|
||||
version = pywrapinit.OrToolsVersion.version_string()
|
||||
version = init.OrToolsVersion.version_string()
|
||||
self.assertIsInstance(version, str)
|
||||
string = f"{major}.{minor}.{patch}"
|
||||
self.assertEqual(version, string)
|
||||
@@ -15,19 +15,19 @@
|
||||
|
||||
import unittest
|
||||
import ortools
|
||||
from ortools.init.python import pywrapinit
|
||||
from ortools.init.python import init
|
||||
|
||||
|
||||
class VersionApi(unittest.TestCase):
|
||||
|
||||
def test_version_api(self):
|
||||
print('test_version_api')
|
||||
self.assertEqual(@PROJECT_VERSION_MAJOR@, pywrapinit.OrToolsVersion.major_number())
|
||||
self.assertEqual(@PROJECT_VERSION_MINOR@, pywrapinit.OrToolsVersion.minor_number())
|
||||
self.assertEqual(@PROJECT_VERSION_PATCH@, pywrapinit.OrToolsVersion.patch_number())
|
||||
print("test_version_api")
|
||||
self.assertEqual(@PROJECT_VERSION_MAJOR@, init.OrToolsVersion.major_number())
|
||||
self.assertEqual(@PROJECT_VERSION_MINOR@, init.OrToolsVersion.minor_number())
|
||||
self.assertEqual(@PROJECT_VERSION_PATCH@, init.OrToolsVersion.patch_number())
|
||||
|
||||
def test_version(self):
|
||||
print('test_version')
|
||||
print("test_version")
|
||||
self.assertEqual("@PROJECT_VERSION@", ortools.__version__)
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import scipy.sparse
|
||||
from ortools.pdlp import solve_log_pb2
|
||||
from ortools.pdlp import solvers_pb2
|
||||
from ortools.pdlp.python import pywrap_pdlp
|
||||
from ortools.init.python import pywrapinit
|
||||
from ortools.init.python import init
|
||||
|
||||
|
||||
def simple_lp() -> pywrap_pdlp.QuadraticProgram:
|
||||
@@ -106,9 +106,9 @@ def main() -> None:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pywrapinit.CppBridge.init_logging("simple_pdlp_program.py")
|
||||
cpp_flags = pywrapinit.CppFlags()
|
||||
init.CppBridge.init_logging("simple_pdlp_program.py")
|
||||
cpp_flags = init.CppFlags()
|
||||
cpp_flags.stderrthreshold = 0
|
||||
cpp_flags.log_prefix = False
|
||||
pywrapinit.CppBridge.set_flags(cpp_flags)
|
||||
init.CppBridge.set_flags(cpp_flags)
|
||||
main()
|
||||
|
||||
@@ -49,8 +49,8 @@ setup(
|
||||
],
|
||||
package_data={
|
||||
'@PYTHON_PROJECT@':[$<$<STREQUAL:$<TARGET_PROPERTY:@PROJECT_NAME@,TYPE>,SHARED_LIBRARY>:'.libs/*','../$<TARGET_SONAME_FILE_NAME:@PROJECT_NAME@>'>],
|
||||
'@PYTHON_PROJECT@.init.python':['$<TARGET_FILE_NAME:pywrapinit>'],
|
||||
'@PYTHON_PROJECT@.algorithms.python':['$<TARGET_FILE_NAME:pywrapknapsack_solver>'],
|
||||
'@PYTHON_PROJECT@.init.python':['$<TARGET_FILE_NAME:init>'],
|
||||
'@PYTHON_PROJECT@.algorithms.python':['$<TARGET_FILE_NAME:knapsack_solver>'],
|
||||
'@PYTHON_PROJECT@.bop':['*.pyi'],
|
||||
'@PYTHON_PROJECT@.glop':['*.pyi'],
|
||||
'@PYTHON_PROJECT@.graph.python':[
|
||||
@@ -66,7 +66,7 @@ setup(
|
||||
'@PYTHON_PROJECT@.pdlp.python':['$<TARGET_FILE_NAME:pywrap_pdlp_pybind11>'],
|
||||
'@PYTHON_PROJECT@.sat':['*.pyi'],
|
||||
'@PYTHON_PROJECT@.sat.python':['$<TARGET_FILE_NAME:swig_helper>', '*.pyi'],
|
||||
'@PYTHON_PROJECT@.scheduling.python':['$<TARGET_FILE_NAME:pywrap_rcpsp>', '*.pyi'],
|
||||
'@PYTHON_PROJECT@.scheduling.python':['$<TARGET_FILE_NAME:rcpsp>', '*.pyi'],
|
||||
'@PYTHON_PROJECT@.util.python':['$<TARGET_FILE_NAME:sorted_interval_list>', '*.pyi'],
|
||||
},
|
||||
include_package_data=True,
|
||||
|
||||
@@ -18,8 +18,8 @@ load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")
|
||||
load("@rules_python//python:defs.bzl", "py_test")
|
||||
|
||||
pybind_extension(
|
||||
name = "pywrap_rcpsp",
|
||||
srcs = ["pywrap_rcpsp.cc"],
|
||||
name = "rcpsp",
|
||||
srcs = ["rcpsp.cc"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//ortools/scheduling:rcpsp_cc_proto",
|
||||
@@ -30,14 +30,14 @@ pybind_extension(
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "pywrap_rcpsp_test",
|
||||
srcs = ["pywrap_rcpsp_test.py"],
|
||||
name = "rcpsp_test",
|
||||
srcs = ["rcpsp_test.py"],
|
||||
data = [
|
||||
"//ortools/scheduling/testdata:j301_1.sm",
|
||||
],
|
||||
python_version = "PY3",
|
||||
deps = [
|
||||
":pywrap_rcpsp",
|
||||
":rcpsp",
|
||||
"//ortools/scheduling:rcpsp_py_proto",
|
||||
requirement("absl-py"),
|
||||
],
|
||||
|
||||
@@ -11,27 +11,27 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
pybind11_add_module(pywrap_rcpsp MODULE pywrap_rcpsp.cc)
|
||||
pybind11_add_module(rcpsp MODULE rcpsp.cc)
|
||||
# note: macOS is APPLE and also UNIX !
|
||||
if(APPLE)
|
||||
set_target_properties(pywrap_rcpsp PROPERTIES
|
||||
set_target_properties(rcpsp PROPERTIES
|
||||
SUFFIX ".so"
|
||||
INSTALL_RPATH "@loader_path;@loader_path/../../../${PYTHON_PROJECT}/.libs"
|
||||
)
|
||||
set_property(TARGET pywrap_rcpsp APPEND PROPERTY
|
||||
set_property(TARGET rcpsp APPEND PROPERTY
|
||||
LINK_FLAGS "-flat_namespace -undefined suppress"
|
||||
)
|
||||
elseif(UNIX)
|
||||
set_target_properties(pywrap_rcpsp PROPERTIES
|
||||
set_target_properties(rcpsp PROPERTIES
|
||||
INSTALL_RPATH "$ORIGIN:$ORIGIN/../../../${PYTHON_PROJECT}/.libs"
|
||||
)
|
||||
endif()
|
||||
target_link_libraries(pywrap_rcpsp PRIVATE
|
||||
target_link_libraries(rcpsp PRIVATE
|
||||
${PROJECT_NAMESPACE}::ortools
|
||||
pybind11_native_proto_caster
|
||||
protobuf::libprotobuf
|
||||
)
|
||||
target_include_directories(pywrap_rcpsp PRIVATE ${protobuf_SOURCE_DIR})
|
||||
target_include_directories(rcpsp PRIVATE ${protobuf_SOURCE_DIR})
|
||||
|
||||
if(BUILD_TESTING)
|
||||
file(GLOB PYTHON_SRCS "*_test.py")
|
||||
|
||||
@@ -23,7 +23,7 @@ using ::operations_research::scheduling::rcpsp::RcpspParser;
|
||||
namespace py = pybind11;
|
||||
using ::py::arg;
|
||||
|
||||
PYBIND11_MODULE(pywrap_rcpsp, m) {
|
||||
PYBIND11_MODULE(rcpsp, m) {
|
||||
pybind11_protobuf::ImportNativeProtoCasters();
|
||||
|
||||
py::class_<RcpspParser>(m, "RcpspParser")
|
||||
@@ -12,19 +12,19 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""Tests for ortools.scheduling.python.pywrap_rcpsp."""
|
||||
"""Tests for ortools.scheduling.python.rcpsp."""
|
||||
|
||||
from absl import app
|
||||
from absl import flags
|
||||
from absl.testing import absltest
|
||||
from ortools.scheduling.python import pywrap_rcpsp
|
||||
from ortools.scheduling.python import rcpsp
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
|
||||
class PywraprcpspTest(absltest.TestCase):
|
||||
class RcpspTest(absltest.TestCase):
|
||||
def testParseAndAccess(self):
|
||||
parser = pywrap_rcpsp.RcpspParser()
|
||||
parser = rcpsp.RcpspParser()
|
||||
data = "ortools/scheduling/testdata/j301_1.sm"
|
||||
try:
|
||||
filename = f"{FLAGS.test_srcdir}/com_google_ortools/{data}"
|
||||
Reference in New Issue
Block a user