diff --git a/ortools/sat/cp_model_lns.h b/ortools/sat/cp_model_lns.h index 3a9efd35fd..dfbe9bcbe1 100644 --- a/ortools/sat/cp_model_lns.h +++ b/ortools/sat/cp_model_lns.h @@ -575,7 +575,7 @@ class ConstraintGraphNeighborhoodGenerator : public NeighborhoodGenerator { class DecompositionGraphNeighborhoodGenerator : public NeighborhoodGenerator { public: explicit DecompositionGraphNeighborhoodGenerator( - NeighborhoodGeneratorHelper const* helper, const std::string& name) + NeighborhoodGeneratorHelper const* helper, absl::string_view name) : NeighborhoodGenerator(name, helper) {} Neighborhood Generate(const CpSolverResponse& initial_solution, double difficulty, absl::BitGenRef random) final; @@ -734,7 +734,7 @@ class SlicePackingNeighborhoodGenerator : public NeighborhoodGenerator { class RoutingRandomNeighborhoodGenerator : public NeighborhoodGenerator { public: RoutingRandomNeighborhoodGenerator(NeighborhoodGeneratorHelper const* helper, - const std::string& name) + absl::string_view name) : NeighborhoodGenerator(name, helper) {} Neighborhood Generate(const CpSolverResponse& initial_solution, @@ -746,7 +746,7 @@ class RoutingRandomNeighborhoodGenerator : public NeighborhoodGenerator { class RoutingPathNeighborhoodGenerator : public NeighborhoodGenerator { public: RoutingPathNeighborhoodGenerator(NeighborhoodGeneratorHelper const* helper, - const std::string& name) + absl::string_view name) : NeighborhoodGenerator(name, helper) {} Neighborhood Generate(const CpSolverResponse& initial_solution, diff --git a/ortools/sat/cp_model_solver.cc b/ortools/sat/cp_model_solver.cc index 66de7650e4..25250f9856 100644 --- a/ortools/sat/cp_model_solver.cc +++ b/ortools/sat/cp_model_solver.cc @@ -3452,13 +3452,16 @@ void SolveCpModelParallel(const CpModelProto& model_proto, shared.incomplete_solutions.get(), "rins/rens"), params, helper, &shared)); } - + const int num_incomplete_solvers = + params.num_workers() - num_full_problem_solvers; const LinearModel* linear_model = global_model->Get(); - if (params.num_violation_ls() > 0 && !params.interleave_search() && - model_proto.has_objective()) { - const int num_violation_ls = params.test_feasibility_jump() - ? params.num_workers() - : params.num_violation_ls(); + if (!params.interleave_search() && model_proto.has_objective()) { + int num_violation_ls = params.has_num_violation_ls() + ? params.num_violation_ls() + : num_incomplete_solvers / 8 + 1; + if (params.test_feasibility_jump()) { + num_violation_ls = params.num_workers(); + } for (int i = 0; i < num_violation_ls; ++i) { SatParameters local_params = params; local_params.set_random_seed(ValidSumSeed(params.random_seed(), i)); diff --git a/ortools/sat/diffn_cuts.cc b/ortools/sat/diffn_cuts.cc index 2020d6128b..fbf6bba488 100644 --- a/ortools/sat/diffn_cuts.cc +++ b/ortools/sat/diffn_cuts.cc @@ -24,6 +24,7 @@ #include "absl/base/attributes.h" #include "absl/log/check.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "absl/types/span.h" #include "ortools/base/stl_util.h" #include "ortools/base/strong_vector.h" @@ -136,7 +137,7 @@ struct DiffnEnergyEvent : DiffnBaseEvent { void GenerateNoOverlap2dEnergyCut( const std::vector>& energies, - absl::Span rectangles, const std::string& cut_name, Model* model, + absl::Span rectangles, absl::string_view cut_name, Model* model, LinearConstraintManager* manager, SchedulingConstraintHelper* x_helper, SchedulingConstraintHelper* y_helper, SchedulingDemandHelper* y_demands_helper) { @@ -295,7 +296,7 @@ void GenerateNoOverlap2dEnergyCut( add_energy_to_name = true; } } - std::string full_name = cut_name; + std::string full_name(cut_name); if (add_opt_to_name) full_name.append("_optional"); if (add_quadratic_to_name) full_name.append("_quadratic"); if (add_energy_to_name) full_name.append("_energy"); @@ -401,7 +402,7 @@ std::string DiffnCtEvent::DebugString() const { // // TODO(user): merge with Packing cuts. void GenerateNoOvelap2dCompletionTimeCutsWithEnergy( - const std::string& cut_name, std::vector events, + absl::string_view cut_name, std::vector events, bool use_lifting, bool skip_low_sizes, Model* model, LinearConstraintManager* manager) { TopNCuts top_n_cuts(5); @@ -548,7 +549,7 @@ void GenerateNoOvelap2dCompletionTimeCutsWithEnergy( add_energy_to_name |= event.use_energy; cut.AddTerm(event.x_end, event.energy_min * best_capacity); } - std::string full_name = cut_name; + std::string full_name(cut_name); if (is_lifted) full_name.append("_lifted"); if (add_energy_to_name) full_name.append("_energy"); top_n_cuts.AddCut(cut.Build(), full_name, manager->LpValues()); diff --git a/ortools/sat/precedences.h b/ortools/sat/precedences.h index c56bb9e17c..bd10f33328 100644 --- a/ortools/sat/precedences.h +++ b/ortools/sat/precedences.h @@ -14,9 +14,11 @@ #ifndef OR_TOOLS_SAT_PRECEDENCES_H_ #define OR_TOOLS_SAT_PRECEDENCES_H_ +#include #include #include #include +#include #include #include "absl/container/inlined_vector.h"