Skip to content

Commit 11c14cd

Browse files
committed
[CP-SAT] revamp python implementation: introduce proper FloatLinearExpr class, move most of the expressions classes to C++
1 parent d68142d commit 11c14cd

File tree

11 files changed

+2210
-1109
lines changed

11 files changed

+2210
-1109
lines changed

ortools/sat/circuit.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,9 +698,12 @@ void LoadSubcircuitConstraint(int num_nodes, const std::vector<int>& tails,
698698

699699
std::function<void(Model*)> CircuitCovering(
700700
absl::Span<const std::vector<Literal>> graph,
701-
const std::vector<int>& distinguished_nodes) {
702-
return [=, graph = std::vector<std::vector<Literal>>(
703-
graph.begin(), graph.end())](Model* model) {
701+
absl::Span<const int> distinguished_nodes) {
702+
return [=,
703+
distinguished_nodes = std::vector<int>(distinguished_nodes.begin(),
704+
distinguished_nodes.end()),
705+
graph = std::vector<std::vector<Literal>>(
706+
graph.begin(), graph.end())](Model* model) {
704707
CircuitCoveringPropagator* constraint =
705708
new CircuitCoveringPropagator(graph, distinguished_nodes, model);
706709
constraint->RegisterWith(model->GetOrCreate<GenericLiteralWatcher>());

ortools/sat/circuit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ std::function<void(Model*)> ExactlyOnePerRowAndPerColumn(
255255
absl::Span<const std::vector<Literal>> graph);
256256
std::function<void(Model*)> CircuitCovering(
257257
absl::Span<const std::vector<Literal>> graph,
258-
const std::vector<int>& distinguished_nodes);
258+
absl::Span<const int> distinguished_nodes);
259259

260260
} // namespace sat
261261
} // namespace operations_research

ortools/sat/python/BUILD.bazel

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,27 @@ load("@pip_deps//:requirements.bzl", "requirement")
1717
load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")
1818
load("@rules_python//python:defs.bzl", "py_library", "py_test")
1919

20+
cc_library(
21+
name = "linear_expr",
22+
srcs = ["linear_expr.cc"],
23+
hdrs = ["linear_expr.h"],
24+
deps = [
25+
"//ortools/sat:cp_model_cc_proto",
26+
"//ortools/util:sorted_interval_list",
27+
"@com_google_absl//absl/container:btree",
28+
"@com_google_absl//absl/container:fixed_array",
29+
"@com_google_absl//absl/container:flat_hash_map",
30+
"@com_google_absl//absl/log:check",
31+
"@com_google_absl//absl/strings",
32+
],
33+
)
34+
2035
pybind_extension(
2136
name = "swig_helper",
2237
srcs = ["swig_helper.cc"],
2338
visibility = ["//visibility:public"],
2439
deps = [
40+
":linear_expr",
2541
"//ortools/sat:cp_model_cc_proto",
2642
"//ortools/sat:sat_parameters_cc_proto",
2743
"//ortools/sat:swig_helper",

0 commit comments

Comments
 (0)