std::string -> absl::string_view

This commit is contained in:
Laurent Perron
2023-09-21 13:04:34 +02:00
parent dc499a8358
commit 95c2c3ee29
4 changed files with 24 additions and 14 deletions

View File

@@ -13,6 +13,9 @@
#include "ortools/base/threadpool.h"
#include <functional>
#include <mutex>
#include "absl/log/check.h"
#include "absl/strings/string_view.h"

View File

@@ -157,12 +157,13 @@ void RunBronKerboschAlgorithmUntilCompletion(
TEST(BronKerbosch, CompleteGraph) {
constexpr int kNumNodes[] = {1, 5, 50, 500, 5000};
for (const int num_nodes : kNumNodes) {
ResultCallback2<bool, int, int>* graph = NewPermanentCallback(FullGraph);
auto graph = FullGraph;
CliqueReporter<int> reporter;
auto callback =
absl::bind_front(&CliqueReporter<int>::AppendClique, &reporter);
operations_research::FindCliques(
graph, num_nodes, ::util::functional::ToPermanentCallback(callback));
::util::functional::ToPermanentCallback(graph), num_nodes,
::util::functional::ToPermanentCallback(callback));
const std::vector<std::vector<int>>& all_cliques = reporter.all_cliques();
EXPECT_EQ(1, all_cliques.size());
EXPECT_EQ(num_nodes, all_cliques[0].size());
@@ -236,12 +237,13 @@ TEST(BronKerboschAlgorithmTest, CompleteGraphWithInt64) {
}
TEST(BronKerbosch, EmptyGraph) {
ResultCallback2<bool, int, int>* graph = NewPermanentCallback(EmptyGraph);
auto graph = EmptyGraph;
CliqueReporter<int> reporter;
auto callback =
absl::bind_front(&CliqueReporter<int>::AppendClique, &reporter);
operations_research::FindCliques(
graph, 10, ::util::functional::ToPermanentCallback(callback));
::util::functional::ToPermanentCallback(graph), 10,
::util::functional::ToPermanentCallback(callback));
const std::vector<std::vector<int>>& all_cliques = reporter.all_cliques();
EXPECT_EQ(10, all_cliques.size());
for (int i = 0; i < 10; ++i) {
@@ -328,12 +330,13 @@ TEST(BronKerboschAlgorithmTest, EmptyGraphStopAfterEveryClique) {
}
TEST(BronKerbosch, MatchingGraph) {
ResultCallback2<bool, int, int>* graph = NewPermanentCallback(MatchingGraph);
auto graph = MatchingGraph;
CliqueReporter<int> reporter;
auto callback =
absl::bind_front(&CliqueReporter<int>::AppendClique, &reporter);
operations_research::FindCliques(
graph, 10, ::util::functional::ToPermanentCallback(callback));
::util::functional::ToPermanentCallback(graph), 10,
::util::functional::ToPermanentCallback(callback));
const std::vector<std::vector<int>>& all_cliques = reporter.all_cliques();
EXPECT_EQ(5, all_cliques.size());
for (int i = 0; i < 5; ++i) {
@@ -397,35 +400,38 @@ TEST(BronKerboschAlgorithmTest, ModuloGraph) {
}
TEST(BronKerbosch, CompleteGraphCover) {
ResultCallback2<bool, int, int>* graph = NewPermanentCallback(FullGraph);
auto graph = FullGraph;
CliqueReporter<int> reporter;
auto callback =
absl::bind_front(&CliqueReporter<int>::AppendClique, &reporter);
operations_research::CoverArcsByCliques(
graph, 10, ::util::functional::ToPermanentCallback(callback));
::util::functional::ToPermanentCallback(graph), 10,
::util::functional::ToPermanentCallback(callback));
const std::vector<std::vector<int>>& all_cliques = reporter.all_cliques();
EXPECT_EQ(1, all_cliques.size());
EXPECT_EQ(10, all_cliques[0].size());
}
TEST(BronKerbosch, EmptyGraphCover) {
ResultCallback2<bool, int, int>* graph = NewPermanentCallback(EmptyGraph);
auto graph = EmptyGraph;
CliqueReporter<int> reporter;
auto callback =
absl::bind_front(&CliqueReporter<int>::AppendClique, &reporter);
operations_research::CoverArcsByCliques(
graph, 10, ::util::functional::ToPermanentCallback(callback));
::util::functional::ToPermanentCallback(graph), 10,
::util::functional::ToPermanentCallback(callback));
const std::vector<std::vector<int>>& all_cliques = reporter.all_cliques();
EXPECT_EQ(0, all_cliques.size());
}
TEST(BronKerbosch, MatchingGraphCover) {
ResultCallback2<bool, int, int>* graph = NewPermanentCallback(MatchingGraph);
auto graph = MatchingGraph;
CliqueReporter<int> reporter;
auto callback =
absl::bind_front(&CliqueReporter<int>::AppendClique, &reporter);
operations_research::CoverArcsByCliques(
graph, 10, ::util::functional::ToPermanentCallback(callback));
::util::functional::ToPermanentCallback(graph), 10,
::util::functional::ToPermanentCallback(callback));
const std::vector<std::vector<int>>& all_cliques = reporter.all_cliques();
EXPECT_EQ(5, all_cliques.size());
for (int i = 0; i < 5; ++i) {

View File

@@ -33,6 +33,7 @@
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/strings/string_view.h"
#include "ortools/base/hash.h"
#include "ortools/base/logging.h" // for CHECK*
#include "ortools/glop/parameters.pb.h"
@@ -75,7 +76,7 @@ class LinearProgram {
void Clear();
// Name setter and getter.
void SetName(const std::string& name) { name_ = name; }
void SetName(absl::string_view name) { name_ = name; }
const std::string& name() const { return name_; }
// Creates a new variable and returns its index.

View File

@@ -51,7 +51,7 @@ class DataWrapper<LinearProgram> {
data_->Clear();
}
void SetName(absl::string_view name) { data_->SetName(std::string(name)); }
void SetName(absl::string_view name) { data_->SetName(name); }
void SetObjectiveDirection(bool maximize) {
data_->SetMaximizationProblem(maximize);