diff --git a/ortools/sat/BUILD.bazel b/ortools/sat/BUILD.bazel index 9d5082b04c..aa4865f8a8 100644 --- a/ortools/sat/BUILD.bazel +++ b/ortools/sat/BUILD.bazel @@ -121,6 +121,7 @@ cc_library( "//ortools/port:proto_utils", "//ortools/util:saturated_arithmetic", "//ortools/util:sorted_interval_list", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/strings", @@ -224,6 +225,7 @@ cc_library( "//ortools/util:strong_integers", "//ortools/util:time_limit", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", @@ -295,6 +297,7 @@ cc_library( "//ortools/util:sorted_interval_list", "//ortools/util:strong_integers", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_protobuf//:protobuf", @@ -342,6 +345,7 @@ cc_library( "//ortools/util:sorted_interval_list", "//ortools/util:strong_integers", "//ortools/util:time_limit", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_map", ], ) @@ -380,6 +384,7 @@ cc_library( "//ortools/util:sorted_interval_list", "//ortools/util:time_limit", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/strings", @@ -413,6 +418,7 @@ cc_library( "//ortools/base:hash", "//ortools/base:map_util", "//ortools/util:saturated_arithmetic", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/strings", ], @@ -465,6 +471,7 @@ cc_library( "//ortools/util:stats", "//ortools/util:strong_integers", "//ortools/util:time_limit", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/types:span", @@ -587,6 +594,7 @@ cc_library( "//ortools/util:logging", "//ortools/util:strong_integers", "//ortools/util:time_limit", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/memory", "@com_google_absl//absl/types:span", ], @@ -680,6 +688,7 @@ cc_library( "//ortools/util:strong_integers", "//ortools/util:time_limit", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:inlined_vector", "@com_google_absl//absl/strings", @@ -775,6 +784,7 @@ cc_library( "//ortools/base:strong_vector", "//ortools/util:bitset", "//ortools/util:strong_integers", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:inlined_vector", ], ) @@ -840,6 +850,7 @@ cc_library( "//ortools/util:sort", "//ortools/util:sorted_interval_list", "//ortools/util:strong_integers", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", ], @@ -995,6 +1006,7 @@ cc_library( ":scheduling_cuts", "//ortools/base", "//ortools/base:iterator_adaptors", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_set", ], ) @@ -1056,6 +1068,7 @@ cc_library( ":sat_parameters_cc_proto", "//ortools/glop:revised_simplex", "//ortools/util:logging", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", ], @@ -1165,6 +1178,7 @@ cc_library( "//ortools/port:proto_utils", "//ortools/util:strong_integers", "//ortools/util:time_limit", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", ], @@ -1216,6 +1230,7 @@ cc_library( "//ortools/util:random_engine", "//ortools/util:saturated_arithmetic", "//ortools/util:time_limit", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/numeric:int128", "@com_google_absl//absl/random", @@ -1326,6 +1341,7 @@ cc_library( "//ortools/base:map_util", "//ortools/util:rev", "//ortools/util:strong_integers", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_map", ], ) diff --git a/ortools/sat/all_different.cc b/ortools/sat/all_different.cc index f417102a9e..377987b566 100644 --- a/ortools/sat/all_different.cc +++ b/ortools/sat/all_different.cc @@ -17,10 +17,10 @@ #include #include #include -#include #include #include +#include "absl/container/btree_map.h" #include "absl/types/span.h" #include "ortools/base/logging.h" #include "ortools/graph/strongly_connected_components.h" @@ -41,7 +41,7 @@ std::function AllDifferentBinary( // List of literal each indicating that a given variable takes this value. // // Note that we use a map to always add the constraints in the same order. - std::map> value_to_literals; + absl::btree_map> value_to_literals; IntegerEncoder* encoder = model->GetOrCreate(); for (const IntegerVariable var : vars) { model->Add(FullyEncodeVariable(var)); diff --git a/ortools/sat/circuit.h b/ortools/sat/circuit.h index 897075313d..2a0f3689b3 100644 --- a/ortools/sat/circuit.h +++ b/ortools/sat/circuit.h @@ -16,10 +16,10 @@ #include #include -#include #include #include +#include "absl/container/btree_set.h" #include "absl/container/flat_hash_map.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" @@ -172,7 +172,7 @@ int ReindexArcs(IntContainer* tails, IntContainer* heads) { if (num_arcs == 0) return 0; // Put all nodes in a set. - std::set nodes; + absl::btree_set nodes; for (int arc = 0; arc < num_arcs; ++arc) { nodes.insert((*tails)[arc]); nodes.insert((*heads)[arc]); diff --git a/ortools/sat/cp_model_checker.cc b/ortools/sat/cp_model_checker.cc index 7dcf42a6ca..5145a082d6 100644 --- a/ortools/sat/cp_model_checker.cc +++ b/ortools/sat/cp_model_checker.cc @@ -18,11 +18,11 @@ #include #include #include -#include #include #include #include +#include "absl/container/btree_map.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/meta/type_traits.h" @@ -1447,7 +1447,7 @@ class ConstraintChecker { const int num_variables = ct.reservoir().time_exprs_size(); const int64_t min_level = ct.reservoir().min_level(); const int64_t max_level = ct.reservoir().max_level(); - std::map deltas; + absl::btree_map deltas; const bool has_active_variables = ct.reservoir().active_literals_size() > 0; for (int i = 0; i < num_variables; i++) { const int64_t time = LinearExpressionValue(ct.reservoir().time_exprs(i)); diff --git a/ortools/sat/cp_model_expand.cc b/ortools/sat/cp_model_expand.cc index 198964aef9..da58fd0f21 100644 --- a/ortools/sat/cp_model_expand.cc +++ b/ortools/sat/cp_model_expand.cc @@ -16,11 +16,11 @@ #include #include #include -#include #include #include #include +#include "absl/container/btree_map.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/meta/type_traits.h" @@ -576,7 +576,7 @@ void LinkLiteralsAndValues(const std::vector& literals, // // TODO(user): Make sure this does not appear in the profile. We could use // the same code as in ProcessOneVariable() otherwise. - std::map> encoding_lit_to_support; + absl::btree_map> encoding_lit_to_support; // If a value is false (i.e not possible), then the tuple with this // value is false too (i.e not possible). Conversely, if the tuple is @@ -1061,8 +1061,8 @@ void AddSizeTwoTable( return; } - std::map> left_to_right; - std::map> right_to_left; + absl::btree_map> left_to_right; + absl::btree_map> right_to_left; for (const auto& tuple : tuples) { const int64_t left_value(tuple[0]); diff --git a/ortools/sat/cp_model_loader.cc b/ortools/sat/cp_model_loader.cc index 4eaa3e63a5..4ef2b8e956 100644 --- a/ortools/sat/cp_model_loader.cc +++ b/ortools/sat/cp_model_loader.cc @@ -17,11 +17,11 @@ #include #include #include -#include #include #include #include +#include "absl/container/btree_set.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/memory/memory.h" @@ -784,7 +784,7 @@ void DetectOptionalVariables(const CpModelProto& model_proto, Model* m) { // Boolean implication (once the presolve remove cycles). Not sure if we can // properly exploit that afterwards though. Do some research! std::vector> enforcement_intersection(num_proto_variables); - std::set literals_set; + absl::btree_set literals_set; for (int c = 0; c < model_proto.constraints_size(); ++c) { const ConstraintProto& ct = model_proto.constraints(c); if (ct.enforcement_literal().empty()) { diff --git a/ortools/sat/cp_model_presolve.cc b/ortools/sat/cp_model_presolve.cc index 07f55b7257..32f84b7824 100644 --- a/ortools/sat/cp_model_presolve.cc +++ b/ortools/sat/cp_model_presolve.cc @@ -19,14 +19,14 @@ #include #include #include -#include -#include #include #include #include #include #include "absl/base/attributes.h" +#include "absl/container/btree_map.h" +#include "absl/container/btree_set.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/hash/hash.h" @@ -1509,7 +1509,7 @@ bool CpModelPresolver::RemoveSingletonInLinear(ConstraintProto* ct) { return false; } - std::set index_to_erase; + absl::btree_set index_to_erase; const int num_vars = ct->linear().vars().size(); Domain rhs = ReadDomainFromProto(ct->linear()); @@ -4242,7 +4242,7 @@ bool CpModelPresolver::PresolveCumulative(ConstraintProto* ct) { // separate function to unit test it more properly. { // Build max load profiles. - std::map time_to_demand_deltas; + absl::btree_map time_to_demand_deltas; const int64_t capacity_min = context_->MinOf(proto->capacity()); for (int i = 0; i < proto->intervals_size(); ++i) { const int interval_index = proto->intervals(i); @@ -4844,7 +4844,7 @@ bool CpModelPresolver::PresolveAutomaton(ConstraintProto* ct) { const std::vector vars = {proto.vars().begin(), proto.vars().end()}; // Compute the set of reachable state at each time point. - std::vector> reachable_states(n + 1); + std::vector> reachable_states(n + 1); reachable_states[0].insert(proto.starting_state()); reachable_states[n] = {proto.final_states().begin(), proto.final_states().end()}; @@ -4861,11 +4861,11 @@ bool CpModelPresolver::PresolveAutomaton(ConstraintProto* ct) { } } - std::vector> reached_values(n); + std::vector> reached_values(n); // Backward. for (int time = n - 1; time >= 0; --time) { - std::set new_set; + absl::btree_set new_set; for (int t = 0; t < proto.transition_tail_size(); ++t) { const int64_t tail = proto.transition_tail(t); const int64_t label = proto.transition_label(t); @@ -5378,7 +5378,7 @@ void CpModelPresolver::ExpandObjective() { } } - std::set var_to_process; + absl::btree_set var_to_process; for (const auto entry : context_->ObjectiveMap()) { const int var = entry.first; CHECK(RefIsPositive(var)); @@ -6211,7 +6211,7 @@ bool CpModelPresolver::ProcessEncodingFromLinear( // Extract the encoding. std::vector all_values; - std::map> value_to_refs; + absl::btree_map> value_to_refs; for (const auto& [ref, coeff] : ref_to_coeffs) { const int64_t value = rhs - coeff; all_values.push_back(value); diff --git a/ortools/sat/cp_model_solver.cc b/ortools/sat/cp_model_solver.cc index b888726721..236ee2a818 100644 --- a/ortools/sat/cp_model_solver.cc +++ b/ortools/sat/cp_model_solver.cc @@ -20,10 +20,8 @@ #include #include #include -#include #include #include -#include #include #include #include @@ -36,6 +34,8 @@ #include "ortools/base/file.h" #endif // __PORTABLE_PLATFORM__ #include "absl/base/thread_annotations.h" +#include "absl/container/btree_map.h" +#include "absl/container/btree_set.h" #include "absl/container/flat_hash_set.h" #include "absl/flags/flag.h" #include "absl/memory/memory.h" @@ -175,11 +175,11 @@ std::string Summarize(const std::string& input) { // ============================================================================= std::string CpModelStats(const CpModelProto& model_proto) { - std::map num_constraints_by_name; - std::map num_reif_constraints_by_name; - std::map name_to_num_literals; - std::map name_to_num_terms; - std::map name_to_num_complex_domain; + absl::btree_map num_constraints_by_name; + absl::btree_map num_reif_constraints_by_name; + absl::btree_map name_to_num_literals; + absl::btree_map name_to_num_terms; + absl::btree_map name_to_num_complex_domain; int no_overlap_2d_num_rectangles = 0; int no_overlap_2d_num_optional_rectangles = 0; @@ -310,8 +310,8 @@ std::string CpModelStats(const CpModelProto& model_proto) { } int num_constants = 0; - std::set constant_values; - std::map num_vars_per_domains; + absl::btree_set constant_values; + absl::btree_map num_vars_per_domains; for (const IntegerVariableProto& var : model_proto.variables()) { if (var.domain_size() == 2 && var.domain(0) == var.domain(1)) { ++num_constants; @@ -1147,7 +1147,7 @@ void LoadBaseModel(const CpModelProto& model_proto, Model* model) { AddFullEncodingFromSearchBranching(model_proto, model); // Load the constraints. - std::set unsupported_types; + absl::btree_set unsupported_types; int num_ignored_constraints = 0; for (const ConstraintProto& ct : model_proto.constraints()) { if (mapping->ConstraintIsAlreadyLoaded(&ct)) { diff --git a/ortools/sat/cuts.cc b/ortools/sat/cuts.cc index e6f3b08731..0d2f8511a9 100644 --- a/ortools/sat/cuts.cc +++ b/ortools/sat/cuts.cc @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -191,7 +190,7 @@ bool LiftKnapsackCut( const std::vector& cut_vars_original_coefficients, const IntegerTrail& integer_trail, TimeLimit* time_limit, LinearConstraint* cut) { - std::set vars_in_cut; + absl::btree_set vars_in_cut; for (IntegerVariable var : cut->vars) { vars_in_cut.insert(var); } @@ -588,7 +587,7 @@ CutGenerator CreateKnapsackCoverCutGenerator( // Constraint is eligible for the cover. IntegerValue constraint_ub_for_cut = preprocessed_constraint.ub; - std::set vars_in_cut; + absl::btree_set vars_in_cut; for (int i = 0; i < preprocessed_constraint.vars.size(); ++i) { const IntegerVariable var = preprocessed_constraint.vars[i]; const IntegerValue coefficient = preprocessed_constraint.coeffs[i]; diff --git a/ortools/sat/integer.cc b/ortools/sat/integer.cc index a0b7cf0d7b..6295fe826c 100644 --- a/ortools/sat/integer.cc +++ b/ortools/sat/integer.cc @@ -18,11 +18,11 @@ #include #include #include -#include #include #include #include +#include "absl/container/btree_map.h" #include "absl/container/flat_hash_map.h" #include "absl/meta/type_traits.h" #include "absl/strings/str_cat.h" @@ -177,8 +177,8 @@ std::vector IntegerEncoder::RawDomainEncoding( // use twice as much implication (2 by literals) instead of only one between // consecutive literals. void IntegerEncoder::AddImplications( - const std::map& map, - std::map::const_iterator it, + const absl::btree_map& map, + absl::btree_map::const_iterator it, Literal associated_lit) { if (!add_implications_) return; DCHECK_EQ(it->second, associated_lit); @@ -203,7 +203,8 @@ void IntegerEncoder::AddImplications( void IntegerEncoder::AddAllImplicationsBetweenAssociatedLiterals() { CHECK_EQ(0, sat_solver_->CurrentDecisionLevel()); add_implications_ = true; - for (const std::map& encoding : encoding_by_var_) { + for (const absl::btree_map& encoding : + encoding_by_var_) { LiteralIndex previous = kNoLiteralIndex; for (const auto value_literal : encoding) { const Literal lit = value_literal.second; @@ -480,13 +481,15 @@ void IntegerEncoder::HalfAssociateGivenLiteral(IntegerLiteral i_lit, bool IntegerEncoder::LiteralIsAssociated(IntegerLiteral i) const { if (i.var >= encoding_by_var_.size()) return false; - const std::map& encoding = encoding_by_var_[i.var]; + const absl::btree_map& encoding = + encoding_by_var_[i.var]; return encoding.find(i.bound) != encoding.end(); } LiteralIndex IntegerEncoder::GetAssociatedLiteral(IntegerLiteral i) const { if (i.var >= encoding_by_var_.size()) return kNoLiteralIndex; - const std::map& encoding = encoding_by_var_[i.var]; + const absl::btree_map& encoding = + encoding_by_var_[i.var]; const auto result = encoding.find(i.bound); if (result == encoding.end()) return kNoLiteralIndex; return result->second.Index(); @@ -497,7 +500,8 @@ LiteralIndex IntegerEncoder::SearchForLiteralAtOrBefore( // We take the element before the upper_bound() which is either the encoding // of i if it already exists, or the encoding just before it. if (i.var >= encoding_by_var_.size()) return kNoLiteralIndex; - const std::map& encoding = encoding_by_var_[i.var]; + const absl::btree_map& encoding = + encoding_by_var_[i.var]; auto after_it = encoding.upper_bound(i.bound); if (after_it == encoding.begin()) return kNoLiteralIndex; --after_it; diff --git a/ortools/sat/integer.h b/ortools/sat/integer.h index 448f2e053c..fb39df428f 100644 --- a/ortools/sat/integer.h +++ b/ortools/sat/integer.h @@ -21,13 +21,13 @@ #include #include #include -#include #include #include #include #include #include "absl/base/attributes.h" +#include "absl/container/btree_map.h" #include "absl/container/flat_hash_map.h" #include "absl/container/inlined_vector.h" #include "absl/strings/str_cat.h" @@ -535,10 +535,10 @@ class IntegerEncoder { // Returns the set of Literal associated to IntegerLiteral of the form var >= // value. We make a copy, because this can be easily invalidated when calling // any function of this class. So it is less efficient but safer. - std::map PartialGreaterThanEncoding( + absl::btree_map PartialGreaterThanEncoding( IntegerVariable var) const { if (var >= encoding_by_var_.size()) { - return std::map(); + return absl::btree_map(); } return encoding_by_var_[var]; } @@ -556,9 +556,10 @@ class IntegerEncoder { // slight optimization. // - 'it' is the current position of associated_lit in map, i.e. we must have // it->second == associated_lit. - void AddImplications(const std::map& map, - std::map::const_iterator it, - Literal associated_lit); + void AddImplications( + const absl::btree_map& map, + absl::btree_map::const_iterator it, + Literal associated_lit); SatSolver* sat_solver_; IntegerDomains* domains_; @@ -572,7 +573,7 @@ class IntegerEncoder { // // TODO(user): Remove the entry no longer needed because of level zero // propagations. - absl::StrongVector> + absl::StrongVector> encoding_by_var_; // Store for a given LiteralIndex the list of its associated IntegerLiterals. diff --git a/ortools/sat/linear_constraint_manager.cc b/ortools/sat/linear_constraint_manager.cc index 02eb260a74..e4e58dbb5d 100644 --- a/ortools/sat/linear_constraint_manager.cc +++ b/ortools/sat/linear_constraint_manager.cc @@ -18,11 +18,11 @@ #include #include #include -#include #include #include #include +#include "absl/container/btree_map.h" #include "absl/container/flat_hash_map.h" #include "absl/meta/type_traits.h" #include "absl/strings/str_cat.h" diff --git a/ortools/sat/linear_constraint_manager.h b/ortools/sat/linear_constraint_manager.h index bf21d66588..36e2e39191 100644 --- a/ortools/sat/linear_constraint_manager.h +++ b/ortools/sat/linear_constraint_manager.h @@ -17,11 +17,11 @@ #include #include #include -#include #include #include #include +#include "absl/container/btree_map.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/strings/string_view.h" @@ -206,7 +206,7 @@ class LinearConstraintManager { int64_t num_cuts_ = 0; int64_t num_add_cut_calls_ = 0; - std::map type_to_num_cuts_; + absl::btree_map type_to_num_cuts_; bool objective_is_defined_ = false; bool objective_norm_computed_ = false; diff --git a/ortools/sat/linear_relaxation.cc b/ortools/sat/linear_relaxation.cc index f976bdc2f7..d0982786b7 100644 --- a/ortools/sat/linear_relaxation.cc +++ b/ortools/sat/linear_relaxation.cc @@ -16,11 +16,11 @@ #include #include #include -#include #include #include #include "absl/base/attributes.h" +#include "absl/container/btree_map.h" #include "absl/container/flat_hash_set.h" #include "ortools/base/logging.h" #include "ortools/base/stl_util.h" @@ -281,7 +281,7 @@ void AppendPartialGreaterThanEncodingRelaxation(IntegerVariable var, const auto* encoder = model.Get(); if (integer_trail == nullptr || encoder == nullptr) return; - const std::map& greater_than_encoding = + const absl::btree_map& greater_than_encoding = encoder->PartialGreaterThanEncoding(var); if (greater_than_encoding.empty()) return; @@ -531,8 +531,8 @@ void AppendCircuitRelaxation(const ConstraintProto& ct, Model* model, // Each node must have exactly one incoming and one outgoing arc (note // that it can be the unique self-arc of this node too). - std::map> incoming_arc_constraints; - std::map> outgoing_arc_constraints; + absl::btree_map> incoming_arc_constraints; + absl::btree_map> outgoing_arc_constraints; for (int i = 0; i < num_arcs; i++) { const Literal arc = mapping->Literal(ct.circuit().literals(i)); const int tail = ct.circuit().tails(i); @@ -574,8 +574,8 @@ void AppendRoutesRelaxation(const ConstraintProto& ct, Model* model, // arc (note that it can be the unique self-arc of this node too). For node // zero, the number of incoming arcs should be the same as the number of // outgoing arcs. - std::map> incoming_arc_constraints; - std::map> outgoing_arc_constraints; + absl::btree_map> incoming_arc_constraints; + absl::btree_map> outgoing_arc_constraints; for (int i = 0; i < num_arcs; i++) { const Literal arc = mapping->Literal(ct.routes().literals(i)); const int tail = ct.routes().tails(i); diff --git a/ortools/sat/model.h b/ortools/sat/model.h index 8500ef5b4e..7da55570b5 100644 --- a/ortools/sat/model.h +++ b/ortools/sat/model.h @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include diff --git a/ortools/sat/optimization.cc b/ortools/sat/optimization.cc index aebcf2264f..e15d8e4d33 100644 --- a/ortools/sat/optimization.cc +++ b/ortools/sat/optimization.cc @@ -20,12 +20,12 @@ #include #include #include -#include -#include #include #include #include +#include "absl/container/btree_map.h" +#include "absl/container/btree_set.h" #include "absl/container/flat_hash_set.h" #include "absl/random/bit_gen_ref.h" #include "absl/random/random.h" @@ -223,7 +223,7 @@ class FuMalikSymmetryBreaker { void MinimizeCoreWithPropagation(TimeLimit* limit, SatSolver* solver, std::vector* core) { if (solver->IsModelUnsat()) return; - std::set moved_last; + absl::btree_set moved_last; std::vector candidate(core->begin(), core->end()); solver->Backtrack(0); @@ -1253,7 +1253,7 @@ SatSolver::Status FindCores(std::vector assumptions, // core. std::vector indices; { - std::set temp(core.begin(), core.end()); + absl::btree_set temp(core.begin(), core.end()); for (int i = 0; i < assumptions.size(); ++i) { if (gtl::ContainsKey(temp, assumptions[i])) { indices.push_back(i); @@ -1814,7 +1814,7 @@ SatSolver::Status CoreBasedOptimizer::Optimize() { // so we don't really need this map, we could just do a linear scan to // recover which node are part of the core. This however needs to be properly // unit tested before usage. - std::map literal_to_term_index; + absl::btree_map literal_to_term_index; // Start the algorithm. stop_ = false; diff --git a/ortools/sat/precedences.cc b/ortools/sat/precedences.cc index b163094cf5..094da91e0d 100644 --- a/ortools/sat/precedences.cc +++ b/ortools/sat/precedences.cc @@ -15,9 +15,9 @@ #include #include -#include #include +#include "absl/container/btree_set.h" #include "absl/container/inlined_vector.h" #include "absl/types/span.h" #include "ortools/base/cleanup.h" @@ -876,7 +876,7 @@ int PrecedencesPropagator:: if (clause.size() > 1) { // Extract the set of arc for which at least one must be present. - const std::set clause_set(clause.begin(), clause.end()); + const absl::btree_set clause_set(clause.begin(), clause.end()); std::vector arcs_in_clause; for (const ArcIndex arc_index : incoming_arcs_[target]) { const Literal literal(arcs_[arc_index].presence_literals.front()); diff --git a/ortools/sat/presolve_context.cc b/ortools/sat/presolve_context.cc index ee012939de..ef9d73ac3d 100644 --- a/ortools/sat/presolve_context.cc +++ b/ortools/sat/presolve_context.cc @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -25,6 +24,7 @@ #include #include "absl/base/attributes.h" +#include "absl/container/btree_map.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/meta/type_traits.h" @@ -2004,8 +2004,8 @@ void PresolveContext::LogInfo() { SOLVER_LOG(logger_, "Presolve summary:"); SOLVER_LOG(logger_, " - ", NumAffineRelations(), " affine relations were detected."); - std::map sorted_rules(stats_by_rule_name_.begin(), - stats_by_rule_name_.end()); + absl::btree_map sorted_rules(stats_by_rule_name_.begin(), + stats_by_rule_name_.end()); for (const auto& entry : sorted_rules) { if (entry.second == 1) { SOLVER_LOG(logger_, " - rule '", entry.first, "' was applied 1 time."); diff --git a/ortools/sat/sat_solver.cc b/ortools/sat/sat_solver.cc index a5f3c68cc4..3b1e9246d3 100644 --- a/ortools/sat/sat_solver.cc +++ b/ortools/sat/sat_solver.cc @@ -19,12 +19,12 @@ #include #include #include -#include #include #include #include #include "absl/base/attributes.h" +#include "absl/container/btree_set.h" #include "absl/container/flat_hash_map.h" #include "absl/meta/type_traits.h" #include "absl/strings/str_cat.h" @@ -1110,7 +1110,7 @@ void SatSolver::TryToMinimizeClause(SatClause* clause) { CHECK_EQ(CurrentDecisionLevel(), 0); ++counters_.minimization_num_clauses; - std::set moved_last; + absl::btree_set moved_last; std::vector candidate(clause->begin(), clause->end()); while (!model_is_unsat_) { // We want each literal in candidate to appear last once in our propagation @@ -1919,7 +1919,7 @@ void SatSolver::ComputeFirstUIPConflict( if (highest_level == 0) return; // To find the 1-UIP conflict clause, we start by the failing_clause, and - // expand each of its literal using the reason for this literal assignement to + // expand each of its literal using the reason for this literal assignment to // false. The is_marked_ set allow us to never expand the same literal twice. // // The expansion is not done (i.e. stop) for literals that were assigned at a @@ -2225,9 +2225,9 @@ void SatSolver::MinimizeConflict( // other literals of the conflict. It is directly infered if the literals of its // reason clause are either from level 0 or from the conflict itself. // -// Note that because of the assignement structure, there is no need to process +// Note that because of the assignment structure, there is no need to process // the literals of the conflict in order. While exploring the reason for a -// literal assignement, there will be no cycles. +// literal assignment, there will be no cycles. void SatSolver::MinimizeConflictSimple(std::vector* conflict) { SCOPED_TIME_STAT(&stats_); const int current_level = CurrentDecisionLevel(); @@ -2262,7 +2262,7 @@ void SatSolver::MinimizeConflictSimple(std::vector* conflict) { // This is similar to MinimizeConflictSimple() except that for each literal of // the conflict, the literals of its reason are recursively expanded using their -// reason and so on. The recusion stop until we show that the initial literal +// reason and so on. The recursion loops until we show that the initial literal // can be infered from the conflict variables alone, or if we show that this is // not the case. The result of any variable expansion will be cached in order // not to be expended again. diff --git a/ortools/sat/simplification.cc b/ortools/sat/simplification.cc index 5a07a9c6ea..13e65ce492 100644 --- a/ortools/sat/simplification.cc +++ b/ortools/sat/simplification.cc @@ -18,10 +18,10 @@ #include #include #include -#include #include #include +#include "absl/container/btree_set.h" #include "absl/memory/memory.h" #include "absl/types/span.h" #include "ortools/algorithms/dynamic_partition.h" diff --git a/ortools/sat/simplification.h b/ortools/sat/simplification.h index 9688bd2002..ba59f8a11e 100644 --- a/ortools/sat/simplification.h +++ b/ortools/sat/simplification.h @@ -22,10 +22,10 @@ #include #include #include -#include #include #include +#include "absl/container/btree_set.h" #include "absl/types/span.h" #include "ortools/base/adjustable_priority_queue.h" #include "ortools/base/integral_types.h" @@ -325,7 +325,7 @@ class SatPresolver { AdjustablePriorityQueue bva_pq_; // Temporary data for SimpleBva(). - std::set m_lit_; + absl::btree_set m_lit_; std::vector m_cls_; absl::StrongVector literal_to_p_size_; std::vector> flattened_p_; diff --git a/ortools/sat/synchronization.cc b/ortools/sat/synchronization.cc index 3b7e597c81..5861b42a6a 100644 --- a/ortools/sat/synchronization.cc +++ b/ortools/sat/synchronization.cc @@ -21,11 +21,11 @@ #include #include #include -#include #include #include #include +#include "absl/container/btree_map.h" #include "ortools/base/logging.h" #include "ortools/base/timer.h" #if !defined(__PORTABLE_PLATFORM__) diff --git a/ortools/sat/synchronization.h b/ortools/sat/synchronization.h index a85f780cf2..3decbd958e 100644 --- a/ortools/sat/synchronization.h +++ b/ortools/sat/synchronization.h @@ -18,12 +18,12 @@ #include #include #include -#include #include #include #include #include "absl/base/thread_annotations.h" +#include "absl/container/btree_map.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/random/bit_gen_ref.h" @@ -412,8 +412,10 @@ class SharedResponseManager { std::string dump_prefix_; // Used for statistics of the improvements found by workers. - std::map primal_improvements_count_ ABSL_GUARDED_BY(mutex_); - std::map dual_improvements_count_ ABSL_GUARDED_BY(mutex_); + absl::btree_map primal_improvements_count_ + ABSL_GUARDED_BY(mutex_); + absl::btree_map dual_improvements_count_ + ABSL_GUARDED_BY(mutex_); SolverLogger* logger_; }; @@ -478,7 +480,7 @@ class SharedBoundsManager { std::vector synchronized_upper_bounds_ ABSL_GUARDED_BY(mutex_); std::deque> id_to_changed_variables_ ABSL_GUARDED_BY(mutex_); - std::map bounds_exported_ ABSL_GUARDED_BY(mutex_); + absl::btree_map bounds_exported_ ABSL_GUARDED_BY(mutex_); }; // This class holds all the binary clauses that were found and shared by the diff --git a/ortools/sat/util.cc b/ortools/sat/util.cc index aaeab61e56..3a600734c9 100644 --- a/ortools/sat/util.cc +++ b/ortools/sat/util.cc @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -29,6 +28,7 @@ #if !defined(__PORTABLE_PLATFORM__) #include "google/protobuf/descriptor.h" #endif // __PORTABLE_PLATFORM__ +#include "absl/container/btree_set.h" #include "absl/container/flat_hash_map.h" #include "absl/numeric/int128.h" #include "absl/random/bit_gen_ref.h" @@ -279,9 +279,9 @@ bool LinearInequalityCanBeReducedWithClosestMultiple( return *new_rhs < infeasibility_bound; } -int MoveOneUnprocessedLiteralLast(const std::set& processed, - int relevant_prefix_size, - std::vector* literals) { +int MoveOneUnprocessedLiteralLast( + const absl::btree_set& processed, int relevant_prefix_size, + std::vector* literals) { if (literals->empty()) return -1; if (!gtl::ContainsKey(processed, literals->back().Index())) { return std::min(relevant_prefix_size, literals->size()); diff --git a/ortools/sat/util.h b/ortools/sat/util.h index e019cf925e..1f783f6cd2 100644 --- a/ortools/sat/util.h +++ b/ortools/sat/util.h @@ -16,13 +16,13 @@ #include #include -#include #include #include "ortools/base/logging.h" #if !defined(__PORTABLE_PLATFORM__) #include "google/protobuf/descriptor.h" #endif // __PORTABLE_PLATFORM__ +#include "absl/container/btree_set.h" #include "absl/random/bit_gen_ref.h" #include "absl/random/random.h" #include "absl/types/span.h" @@ -171,9 +171,9 @@ void RandomizeDecisionHeuristic(absl::BitGenRef random, // relevant_prefix_size is used as a hint when keeping more that this prefix // size do not matter. The returned value will always be lower or equal to // relevant_prefix_size. -int MoveOneUnprocessedLiteralLast(const std::set& processed, - int relevant_prefix_size, - std::vector* literals); +int MoveOneUnprocessedLiteralLast( + const absl::btree_set& processed, int relevant_prefix_size, + std::vector* literals); // ============================================================================ // Implementation.