From 8d44f5f5246a9ccf3309c612cdb03bd95a9f0585 Mon Sep 17 00:00:00 2001 From: Laurent Perron Date: Thu, 3 Aug 2023 10:12:38 -0700 Subject: [PATCH] fix race and subsequent crash --- ortools/sat/cp_model_lns.cc | 12 +++++------- ortools/sat/cp_model_lns.h | 1 - 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/ortools/sat/cp_model_lns.cc b/ortools/sat/cp_model_lns.cc index cc4e3af004..875aa061e9 100644 --- a/ortools/sat/cp_model_lns.cc +++ b/ortools/sat/cp_model_lns.cc @@ -2028,21 +2028,19 @@ Neighborhood SchedulingTimeWindowNeighborhoodGenerator::Generate( Neighborhood SchedulingResourceWindowsNeighborhoodGenerator::Generate( const CpSolverResponse& initial_solution, double difficulty, absl::BitGenRef random) { - intervals_to_relax_.clear(); + std::vector intervals_to_relax; for (const std::vector& intervals : intervals_in_constraints_) { const std::vector selected_indices = SelectIndicesInRandomTimeWindow( intervals, helper_.ModelProto(), initial_solution, difficulty, random); for (const int index : selected_indices) { - intervals_to_relax_.insert(intervals[index]); + intervals_to_relax.push_back(intervals[index]); } } - if (intervals_to_relax_.empty()) return helper_.FullNeighborhood(); - - const std::vector intervals( - {intervals_to_relax_.begin(), intervals_to_relax_.end()}); + if (intervals_to_relax.empty()) return helper_.FullNeighborhood(); + gtl::STLSortAndRemoveDuplicates(&intervals_to_relax); return GenerateSchedulingNeighborhoodFromRelaxedIntervals( - intervals, initial_solution, random, helper_); + intervals_to_relax, initial_solution, random, helper_); } Neighborhood RandomRectanglesPackingNeighborhoodGenerator::Generate( diff --git a/ortools/sat/cp_model_lns.h b/ortools/sat/cp_model_lns.h index 23fb5fff8b..f478bdf08d 100644 --- a/ortools/sat/cp_model_lns.h +++ b/ortools/sat/cp_model_lns.h @@ -679,7 +679,6 @@ class SchedulingResourceWindowsNeighborhoodGenerator private: const std::vector> intervals_in_constraints_; - absl::flat_hash_set intervals_to_relax_; }; // Only make sense for problems with no_overlap_2d constraints. This select a