Skip to content

Commit

Permalink
[CP-SAT] revamp python implementation: introduce proper FloatLinearEx…
Browse files Browse the repository at this point in the history
…pr class, move most of the expressions classes to C++
  • Loading branch information
lperron committed Dec 28, 2024
1 parent d68142d commit 11c14cd
Show file tree
Hide file tree
Showing 11 changed files with 2,210 additions and 1,109 deletions.
9 changes: 6 additions & 3 deletions ortools/sat/circuit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,12 @@ void LoadSubcircuitConstraint(int num_nodes, const std::vector<int>& tails,

std::function<void(Model*)> CircuitCovering(
absl::Span<const std::vector<Literal>> graph,
const std::vector<int>& distinguished_nodes) {
return [=, graph = std::vector<std::vector<Literal>>(
graph.begin(), graph.end())](Model* model) {
absl::Span<const int> distinguished_nodes) {
return [=,
distinguished_nodes = std::vector<int>(distinguished_nodes.begin(),
distinguished_nodes.end()),
graph = std::vector<std::vector<Literal>>(
graph.begin(), graph.end())](Model* model) {
CircuitCoveringPropagator* constraint =
new CircuitCoveringPropagator(graph, distinguished_nodes, model);
constraint->RegisterWith(model->GetOrCreate<GenericLiteralWatcher>());
Expand Down
2 changes: 1 addition & 1 deletion ortools/sat/circuit.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ std::function<void(Model*)> ExactlyOnePerRowAndPerColumn(
absl::Span<const std::vector<Literal>> graph);
std::function<void(Model*)> CircuitCovering(
absl::Span<const std::vector<Literal>> graph,
const std::vector<int>& distinguished_nodes);
absl::Span<const int> distinguished_nodes);

} // namespace sat
} // namespace operations_research
Expand Down
16 changes: 16 additions & 0 deletions ortools/sat/python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,27 @@ load("@pip_deps//:requirements.bzl", "requirement")
load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")
load("@rules_python//python:defs.bzl", "py_library", "py_test")

cc_library(
name = "linear_expr",
srcs = ["linear_expr.cc"],
hdrs = ["linear_expr.h"],
deps = [
"//ortools/sat:cp_model_cc_proto",
"//ortools/util:sorted_interval_list",
"@com_google_absl//absl/container:btree",
"@com_google_absl//absl/container:fixed_array",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/strings",
],
)

pybind_extension(
name = "swig_helper",
srcs = ["swig_helper.cc"],
visibility = ["//visibility:public"],
deps = [
":linear_expr",
"//ortools/sat:cp_model_cc_proto",
"//ortools/sat:sat_parameters_cc_proto",
"//ortools/sat:swig_helper",
Expand Down
Loading

0 comments on commit 11c14cd

Please sign in to comment.