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 " \n num_remaining_candidates = " , num_remaining_candidates,
255256 " \n candidates = [" );
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 {
443444template <typename NodeIndex>
444445void 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