Skip to content

Commit a42049b

Browse files
committed
cleanup
1 parent 84a61d5 commit a42049b

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

ortools/graph/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ cc_library(
144144
hdrs = ["cliques.h"],
145145
visibility = ["//visibility:public"],
146146
deps = [
147-
"//ortools/base",
148-
"//ortools/base:int_type",
147+
"//ortools/base:intops",
149148
"//ortools/base:strong_vector",
150149
"//ortools/util:bitset",
151150
"//ortools/util:time_limit",
152151
"@abseil-cpp//absl/container:flat_hash_set",
152+
"@abseil-cpp//absl/log",
153153
"@abseil-cpp//absl/log:check",
154154
"@abseil-cpp//absl/strings",
155155
],

ortools/graph/cliques.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,9 @@ void Search(std::function<bool(int, int)> graph,
188188

189189
class FindAndEliminate {
190190
public:
191-
FindAndEliminate(std::function<bool(int, int)> graph, int node_count,
191+
FindAndEliminate(std::function<bool(int, int)> graph,
192192
std::function<bool(const std::vector<int>&)> callback)
193-
: graph_(std::move(graph)),
194-
node_count_(node_count),
195-
callback_(std::move(callback)) {}
193+
: graph_(std::move(graph)), callback_(std::move(callback)) {}
196194

197195
bool GraphCallback(int node1, int node2) {
198196
if (visited_.find(
@@ -219,7 +217,6 @@ class FindAndEliminate {
219217

220218
private:
221219
std::function<bool(int, int)> graph_;
222-
int node_count_;
223220
std::function<bool(const std::vector<int>&)> callback_;
224221
absl::flat_hash_set<std::pair<int, int>> visited_;
225222
};
@@ -243,7 +240,7 @@ void FindCliques(std::function<bool(int, int)> graph, int node_count,
243240

244241
void CoverArcsByCliques(std::function<bool(int, int)> graph, int node_count,
245242
std::function<bool(const std::vector<int>&)> callback) {
246-
FindAndEliminate cache(std::move(graph), node_count, std::move(callback));
243+
FindAndEliminate cache(std::move(graph), std::move(callback));
247244
std::unique_ptr<int[]> initial_candidates(new int[node_count]);
248245
std::vector<int> actual;
249246

ortools/graph/cliques.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
#include <utility>
3333
#include <vector>
3434

35+
#include "absl/log/check.h"
36+
#include "absl/log/log.h"
3537
#include "absl/strings/str_cat.h"
36-
#include "ortools/base/int_type.h"
37-
#include "ortools/base/logging.h"
38+
#include "ortools/base/strong_int.h"
3839
#include "ortools/base/strong_vector.h"
3940
#include "ortools/util/bitset.h"
4041
#include "ortools/util/time_limit.h"
@@ -211,7 +212,7 @@ class BronKerboschAlgorithm {
211212
}
212213

213214
private:
214-
DEFINE_INT_TYPE(CandidateIndex, ptrdiff_t);
215+
DEFINE_STRONG_INT_TYPE(CandidateIndex, ptrdiff_t);
215216

216217
// A data structure that maintains the variables of one "iteration" of the
217218
// search algorithm. These are the variables that would normally be allocated
@@ -253,8 +254,8 @@ class BronKerboschAlgorithm {
253254
absl::StrAppend(&buffer, "pivot = ", pivot,
254255
"\nnum_remaining_candidates = ", num_remaining_candidates,
255256
"\ncandidates = [");
256-
for (CandidateIndex i(0); i < candidates.size(); ++i) {
257-
if (i > 0) buffer += ", ";
257+
for (CandidateIndex i(0); i < CandidateIndex(candidates.size()); ++i) {
258+
if (i > CandidateIndex(0)) buffer += ", ";
258259
absl::StrAppend(&buffer, candidates[i]);
259260
}
260261
absl::StrAppend(
@@ -443,8 +444,9 @@ class WeightedBronKerboschBitsetAlgorithm {
443444
template <typename NodeIndex>
444445
void BronKerboschAlgorithm<NodeIndex>::InitializeState(State* state) {
445446
DCHECK(state != nullptr);
446-
const int num_candidates = state->candidates.size();
447-
int num_disconnected_candidates = num_candidates;
447+
const CandidateIndex num_candidates =
448+
CandidateIndex(state->candidates.size());
449+
int num_disconnected_candidates = num_candidates.value();
448450
state->pivot = 0;
449451
CandidateIndex pivot_index(-1);
450452
for (CandidateIndex pivot_candidate_index(0);
@@ -480,7 +482,7 @@ BronKerboschAlgorithm<NodeIndex>::SelectCandidateIndexForRecursion(
480482
DCHECK(state != nullptr);
481483
CandidateIndex disconnected_node_index =
482484
std::max(state->first_candidate_index, state->candidate_for_recursion);
483-
while (disconnected_node_index < state->candidates.size() &&
485+
while (disconnected_node_index < CandidateIndex(state->candidates.size()) &&
484486
state->candidates[disconnected_node_index] != state->pivot &&
485487
IsArc(state->pivot, state->candidates[disconnected_node_index])) {
486488
++disconnected_node_index;
@@ -496,8 +498,8 @@ void BronKerboschAlgorithm<NodeIndex>::Initialize() {
496498
states_.emplace_back();
497499

498500
State* const root_state = &states_.back();
499-
root_state->first_candidate_index = 0;
500-
root_state->candidate_for_recursion = 0;
501+
root_state->first_candidate_index = CandidateIndex(0);
502+
root_state->candidate_for_recursion = CandidateIndex(0);
501503
root_state->candidates.resize(num_nodes_, 0);
502504
std::iota(root_state->candidates.begin(), root_state->candidates.end(), 0);
503505
root_state->num_remaining_candidates = num_nodes_;
@@ -555,8 +557,9 @@ void BronKerboschAlgorithm<NodeIndex>::PushState(NodeIndex selected) {
555557
}
556558
}
557559
const CandidateIndex new_first_candidate_index(new_candidates.size());
558-
for (CandidateIndex i = previous_state->first_candidate_index + 1;
559-
i < previous_state->candidates.size(); ++i) {
560+
for (CandidateIndex i =
561+
previous_state->first_candidate_index + CandidateIndex(1);
562+
i < CandidateIndex(previous_state->candidates.size()); ++i) {
560563
const NodeIndex candidate = previous_state->candidates[i];
561564
if (IsArc(selected, candidate)) {
562565
new_candidates.push_back(candidate);

0 commit comments

Comments
 (0)