Update linear solver build (#4945)
This commit is contained in:
committed by
Corentin Le Molgat
parent
6d76575f3d
commit
69dc22f35d
@@ -11,36 +11,11 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
|
||||
load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
||||
load("@rules_cc//cc:cc_test.bzl", "cc_test")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
# Description:
|
||||
# Home of algorithms used in OR solvers
|
||||
|
||||
# OSS solvers
|
||||
bool_flag(
|
||||
name = "with_cbc",
|
||||
build_setting_default = False,
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "use_cbc",
|
||||
flag_values = {":with_cbc": "true"},
|
||||
)
|
||||
|
||||
bool_flag(
|
||||
name = "with_scip",
|
||||
build_setting_default = True,
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "use_scip",
|
||||
flag_values = {":with_scip": "true"},
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "binary_search",
|
||||
srcs = [],
|
||||
@@ -190,14 +165,8 @@ cc_library(
|
||||
name = "knapsack_solver_lib",
|
||||
srcs = ["knapsack_solver.cc"],
|
||||
hdrs = ["knapsack_solver.h"],
|
||||
copts = [] + select({
|
||||
":use_cbc": ["-DUSE_CBC"],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
":use_scip": ["-DUSE_SCIP"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
deps = [
|
||||
"@abseil-cpp//absl/log",
|
||||
"@abseil-cpp//absl/log:check",
|
||||
"@abseil-cpp//absl/strings",
|
||||
"@abseil-cpp//absl/time",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/log/check.h"
|
||||
#include "absl/log/log.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "ortools/base/stl_util.h"
|
||||
@@ -1071,7 +1072,7 @@ class KnapsackDivideAndConquerSolver : public BaseKnapsackSolver {
|
||||
}
|
||||
|
||||
private:
|
||||
// 'DP 2' computes solution 'z' for 0 up to capacitiy
|
||||
// 'DP 2' computes solution 'z' for 0 up to capacity
|
||||
void SolveSubProblem(bool first_storage, int64_t capacity, int start_item,
|
||||
int end_item);
|
||||
|
||||
@@ -1411,30 +1412,22 @@ KnapsackSolver::KnapsackSolver(SolverType solver_type,
|
||||
case KNAPSACK_DIVIDE_AND_CONQUER_SOLVER:
|
||||
solver_ = std::make_unique<KnapsackDivideAndConquerSolver>(solver_name);
|
||||
break;
|
||||
#if defined(USE_CBC)
|
||||
case KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER:
|
||||
solver_ = std::make_unique<KnapsackMIPSolver>(
|
||||
MPSolver::CBC_MIXED_INTEGER_PROGRAMMING, solver_name);
|
||||
break;
|
||||
#endif // USE_CBC
|
||||
#if defined(USE_SCIP)
|
||||
case KNAPSACK_MULTIDIMENSION_SCIP_MIP_SOLVER:
|
||||
solver_ = std::make_unique<KnapsackMIPSolver>(
|
||||
MPSolver::SCIP_MIXED_INTEGER_PROGRAMMING, solver_name);
|
||||
break;
|
||||
#endif // USE_SCIP
|
||||
#if defined(USE_XPRESS)
|
||||
case KNAPSACK_MULTIDIMENSION_XPRESS_MIP_SOLVER:
|
||||
solver_ = std::make_unique<KnapsackMIPSolver>(
|
||||
MPSolver::XPRESS_MIXED_INTEGER_PROGRAMMING, solver_name);
|
||||
break;
|
||||
#endif
|
||||
#if defined(USE_CPLEX)
|
||||
case KNAPSACK_MULTIDIMENSION_CPLEX_MIP_SOLVER:
|
||||
solver_ = std::make_unique<KnapsackMIPSolver>(
|
||||
MPSolver::CPLEX_MIXED_INTEGER_PROGRAMMING, solver_name);
|
||||
break;
|
||||
#endif
|
||||
case KNAPSACK_MULTIDIMENSION_CP_SAT_SOLVER:
|
||||
solver_ = std::make_unique<KnapsackCpSat>(solver_name);
|
||||
break;
|
||||
|
||||
@@ -130,14 +130,12 @@ class KnapsackSolver {
|
||||
*/
|
||||
KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER = 2,
|
||||
|
||||
#if defined(USE_CBC)
|
||||
/** 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.
|
||||
*/
|
||||
KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER = 3,
|
||||
#endif // USE_CBC
|
||||
|
||||
/** Generic Solver.
|
||||
*
|
||||
@@ -146,32 +144,27 @@ class KnapsackSolver {
|
||||
*/
|
||||
KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER = 5,
|
||||
|
||||
#if defined(USE_SCIP)
|
||||
/** 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.
|
||||
*/
|
||||
KNAPSACK_MULTIDIMENSION_SCIP_MIP_SOLVER = 6,
|
||||
#endif // USE_SCIP
|
||||
|
||||
#if defined(USE_XPRESS)
|
||||
/** XPRESS based solver
|
||||
*
|
||||
* This solver can deal with both large number of items and several
|
||||
* dimensions. This solver is based on Integer Programming solver XPRESS.
|
||||
*/
|
||||
KNAPSACK_MULTIDIMENSION_XPRESS_MIP_SOLVER = 7,
|
||||
#endif
|
||||
|
||||
#if defined(USE_CPLEX)
|
||||
/** CPLEX based solver
|
||||
*
|
||||
* This solver can deal with both large number of items and several
|
||||
* dimensions. This solver is based on Integer Programming solver CPLEX.
|
||||
*/
|
||||
KNAPSACK_MULTIDIMENSION_CPLEX_MIP_SOLVER = 8,
|
||||
#endif
|
||||
|
||||
/** Divide and Conquer approach for single dimension problems
|
||||
*
|
||||
* Limited to one dimension, this solver is based on a divide and conquer
|
||||
@@ -180,6 +173,7 @@ class KnapsackSolver {
|
||||
* space complexity is O(capacity + number_of_items).
|
||||
*/
|
||||
KNAPSACK_DIVIDE_AND_CONQUER_SOLVER = 9,
|
||||
|
||||
/** CP-SAT based solver
|
||||
*
|
||||
* This solver can deal with both large number of items and several
|
||||
|
||||
@@ -13,33 +13,11 @@
|
||||
|
||||
# Description: python wrapping of the libraries in ../
|
||||
|
||||
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
|
||||
load("@pip_deps//:requirements.bzl", "requirement")
|
||||
load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")
|
||||
load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
||||
load("@rules_python//python:py_test.bzl", "py_test")
|
||||
|
||||
# OSS solvers
|
||||
bool_flag(
|
||||
name = "with_cbc",
|
||||
build_setting_default = False,
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "use_cbc",
|
||||
flag_values = {":with_cbc": "true"},
|
||||
)
|
||||
|
||||
bool_flag(
|
||||
name = "with_scip",
|
||||
build_setting_default = True,
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "use_scip",
|
||||
flag_values = {":with_scip": "true"},
|
||||
)
|
||||
|
||||
# knapsack_solver
|
||||
cc_library(
|
||||
name = "knapsack_solver_doc",
|
||||
@@ -50,13 +28,6 @@ cc_library(
|
||||
pybind_extension(
|
||||
name = "knapsack_solver",
|
||||
srcs = ["knapsack_solver.cc"],
|
||||
copts = select({
|
||||
":use_cbc": ["-DUSE_CBC"],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
":use_scip": ["-DUSE_SCIP"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":knapsack_solver_doc",
|
||||
|
||||
@@ -67,19 +67,15 @@ PYBIND11_MODULE(knapsack_solver, m) {
|
||||
KnapsackSolver::SolverType::KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER,
|
||||
DOC(operations_research, KnapsackSolver, SolverType,
|
||||
KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER))
|
||||
#if defined(USE_CBC)
|
||||
.value("KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER",
|
||||
KnapsackSolver::SolverType::KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER,
|
||||
DOC(operations_research, KnapsackSolver, SolverType,
|
||||
KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER))
|
||||
#endif // USE_CBC
|
||||
#if defined(USE_SCIP)
|
||||
.value(
|
||||
"KNAPSACK_MULTIDIMENSION_SCIP_MIP_SOLVER",
|
||||
KnapsackSolver::SolverType::KNAPSACK_MULTIDIMENSION_SCIP_MIP_SOLVER,
|
||||
DOC(operations_research, KnapsackSolver, SolverType,
|
||||
KNAPSACK_MULTIDIMENSION_SCIP_MIP_SOLVER))
|
||||
#endif // USE_SCIP
|
||||
.value("KNAPSACK_DIVIDE_AND_CONQUER_SOLVER",
|
||||
KnapsackSolver::SolverType::KNAPSACK_DIVIDE_AND_CONQUER_SOLVER,
|
||||
DOC(operations_research, KnapsackSolver, SolverType,
|
||||
|
||||
Reference in New Issue
Block a user