Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Sep 18, 2023
1 parent 5dddb79 commit 6cada61
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
30 changes: 18 additions & 12 deletions ortools/graph/cliques_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions ortools/linear_solver/linear_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
#include <cstdint>
#include <functional>
#include <limits>
#include <map>
#include <memory>
#include <optional>
#include <ostream>
Expand Down
3 changes: 2 additions & 1 deletion ortools/lp_data/lp_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ortools/lp_data/mps_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6cada61

Please sign in to comment.