From 16afc12ca82d18fd57f84430deb482d89c772023 Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Mon, 9 Sep 2024 14:11:41 +0200 Subject: [PATCH] algorithms: export from google3 --- ortools/algorithms/BUILD.bazel | 1 + ortools/algorithms/set_cover_invariant.cc | 2 +- ortools/algorithms/set_cover_mip.cc | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ortools/algorithms/BUILD.bazel b/ortools/algorithms/BUILD.bazel index 3eec4c7601..be5f372620 100644 --- a/ortools/algorithms/BUILD.bazel +++ b/ortools/algorithms/BUILD.bazel @@ -334,6 +334,7 @@ cc_library( "//ortools/linear_solver", "//ortools/lp_data:base", "@com_google_absl//absl/log", + "@com_google_absl//absl/log:check", "@com_google_absl//absl/types:span", ], ) diff --git a/ortools/algorithms/set_cover_invariant.cc b/ortools/algorithms/set_cover_invariant.cc index b377c8ab4e..128dff78a8 100644 --- a/ortools/algorithms/set_cover_invariant.cc +++ b/ortools/algorithms/set_cover_invariant.cc @@ -124,7 +124,7 @@ std::tuple SetCoverInvariant::ComputeCostAndCoverage( ElementToIntVector SetCoverInvariant::ComputeCoverageInFocus( const absl::Span focus) const { - ElementToIntVector coverage; + ElementToIntVector coverage(coverage_.size()); for (const SubsetIndex subset : focus) { if (is_selected_[subset]) { for (const ElementIndex element : model_->columns()[subset]) { diff --git a/ortools/algorithms/set_cover_mip.cc b/ortools/algorithms/set_cover_mip.cc index 03e38d5fde..00dec965d2 100644 --- a/ortools/algorithms/set_cover_mip.cc +++ b/ortools/algorithms/set_cover_mip.cc @@ -16,6 +16,7 @@ #include #include +#include "absl/log/check.h" #include "absl/types/span.h" #include "ortools/algorithms/set_cover_invariant.h" #include "ortools/algorithms/set_cover_model.h" @@ -29,7 +30,8 @@ namespace { // Returns the vector a - b. ElementToIntVector Subtract(const ElementToIntVector& a, const ElementToIntVector& b) { - ElementToIntVector delta; + ElementToIntVector delta(a.size()); + DCHECK_EQ(a.size(), b.size()); for (const ElementIndex i : a.index_range()) { delta[i] = a[i] - b[i]; }