algorithms: backport from main

This commit is contained in:
Corentin Le Molgat
2024-11-15 09:57:51 +01:00
parent 2d8f157098
commit e443a46fa2
4 changed files with 11 additions and 9 deletions

View File

@@ -290,6 +290,7 @@ cc_library(
"//ortools/base:strong_vector",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/numeric:bits",
"@com_google_absl//absl/random",
"@com_google_absl//absl/random:distributions",
"@com_google_absl//absl/strings",
@@ -368,8 +369,8 @@ cc_test(
":set_cover_invariant",
":set_cover_mip",
":set_cover_model",
"//ortools/base:parse_text_proto",
"//ortools/base:gmock_main",
"//ortools/base:parse_text_proto",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/strings",

View File

@@ -103,7 +103,8 @@ void SetCoverInvariant::LoadSolution(const SubsetBoolVector& solution) {
is_selected_ = solution;
ClearTrace();
ClearRemovabilityInformation();
for (SubsetIndex subset(0); bool b : solution) {
SubsetIndex subset(0);
for (const bool b : solution) {
if (b) {
trace_.push_back(SetCoverDecision(subset, true));
}
@@ -167,7 +168,8 @@ std::tuple<Cost, ElementToIntVector> SetCoverInvariant::ComputeCostAndCoverage(
// Initialize coverage, update cost, and compute the coverage for
// all the elements covered by the selected subsets.
const SubsetCostVector& subset_costs = model_->subset_costs();
for (SubsetIndex subset(0); bool b : choices) {
SubsetIndex subset(0);
for (const bool b : choices) {
if (b) {
cst += subset_costs[subset];
for (const ElementIndex element : columns[subset]) {

View File

@@ -14,18 +14,17 @@
#include "ortools/algorithms/set_cover_model.h"
#include <algorithm>
#include <bit>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <numeric>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include "absl/log/check.h"
#include "absl/numeric/bits.h"
#include "absl/random/discrete_distribution.h"
#include "absl/random/distributions.h"
#include "absl/random/random.h"

View File

@@ -44,9 +44,9 @@
// - its columns are such that M(i, j) = 1 iff the i-th element of E is present
// in S_j.
//
// We alse use m to denote |E|, the number of elements, and n to denote |S|, the
// We also use m to denote |E|, the number of elements, and n to denote |S|, the
// number of subsets.
// Finally, nnz or #nz denotes the numbers of non-zeros, i.e. the sum of the
// Finally, NNZ denotes the numbers of non-zeros, i.e. the sum of the
// cardinalities of all the subsets.
namespace operations_research {
@@ -290,11 +290,11 @@ class SetCoverModel {
// Vector of columns. Each column corresponds to a subset and contains the
// elements of the given subset.
// This takes nnz (number of non-zeros) BaseInts, or |E| * |S| * fill_rate.
// This takes NNZ (number of non-zeros) BaseInts, or |E| * |S| * fill_rate.
// On classical benchmarks, the fill rate is in the 2 to 5% range.
// Some synthetic benchmarks have fill rates of 20%, while benchmarks for
// rail rotations have a fill rate of 0.2 to 0.4%.
// TODO(user): try using a compressed representation like Protocol Buffers,
// TODO(user): try using a compressed representation like VarInt or LEB128,
// since the data is only iterated upon.
SparseColumnView columns_;