From c41dbb8e43b4b0b6245911293302b7e4de75cc66 Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Mon, 7 Oct 2024 11:08:38 +0200 Subject: [PATCH] st: Fixup export from google3 --- ortools/base/parse_text_proto.h | 27 ++++++++++++++++++++++++ ortools/sat/cp_model_expand.cc | 3 ++- ortools/sat/cp_model_lns.cc | 4 ++-- ortools/sat/feasibility_jump.cc | 3 ++- ortools/sat/linear_constraint_manager.cc | 3 ++- ortools/sat/lp_utils.cc | 4 ++-- ortools/sat/precedences.cc | 5 +++-- ortools/sat/probing.cc | 5 +++-- ortools/sat/sat_base.h | 5 +++-- ortools/sat/sat_inprocessing.cc | 7 +++--- ortools/sat/var_domination.cc | 4 ++-- ortools/sat/work_assignment_test.cc | 2 +- 12 files changed, 53 insertions(+), 19 deletions(-) diff --git a/ortools/base/parse_text_proto.h b/ortools/base/parse_text_proto.h index 625ad29ad16..5e78d3dfc37 100644 --- a/ortools/base/parse_text_proto.h +++ b/ortools/base/parse_text_proto.h @@ -14,6 +14,8 @@ #ifndef OR_TOOLS_BASE_PARSE_TEXT_PROTO_H_ #define OR_TOOLS_BASE_PARSE_TEXT_PROTO_H_ +#include + #include "absl/log/absl_check.h" #include "google/protobuf/message.h" #include "google/protobuf/text_format.h" @@ -32,6 +34,31 @@ T ParseTextOrDie(const std::string& input) { return result; } +namespace text_proto_internal { + +class ParseProtoHelper { + public: + explicit ParseProtoHelper(std::string_view asciipb) : asciipb_(asciipb) {} + template + operator T() { // NOLINT(runtime/explicit) + T result; + const bool ok = ::google::protobuf::TextFormat::TextFormat::ParseFromString( + asciipb_, &result); + CHECK(ok) << "Failed to parse text proto: " << asciipb_; + return result; + } + + private: + const std::string asciipb_; +}; + +} // namespace text_proto_internal + +text_proto_internal::ParseProtoHelper ParseTextProtoOrDie( + std::string_view input) { + return text_proto_internal::ParseProtoHelper(input); +} + } // namespace google::protobuf::contrib::parse_proto #endif // OR_TOOLS_BASE_PARSE_TEXT_PROTO_H_ diff --git a/ortools/sat/cp_model_expand.cc b/ortools/sat/cp_model_expand.cc index e9cceb9d4dd..eaa97cdc807 100644 --- a/ortools/sat/cp_model_expand.cc +++ b/ortools/sat/cp_model_expand.cc @@ -1768,7 +1768,8 @@ void CompressAndExpandPositiveTable(ConstraintProto* ct, } } - VLOG(2) << "Table compression" << " var=" << vars.size() + VLOG(2) << "Table compression" + << " var=" << vars.size() << " cost=" << domain_sizes.size() - vars.size() << " tuples= " << num_tuples_before_compression << " -> " << num_tuples_after_first_compression << " -> " diff --git a/ortools/sat/cp_model_lns.cc b/ortools/sat/cp_model_lns.cc index 436d65d68d0..48404abdfdd 100644 --- a/ortools/sat/cp_model_lns.cc +++ b/ortools/sat/cp_model_lns.cc @@ -1726,8 +1726,8 @@ Neighborhood DecompositionGraphNeighborhoodGenerator::Generate( VLOG(2) << "#relaxed " << relaxed_variables.size() << " #zero_score " << num_zero_score << " max_width " << max_width << " (size,min_width)_after_100 (" << size_at_min_width_after_100 - << "," << min_width_after_100 << ") " << " final_width " - << pq.Size(); + << "," << min_width_after_100 << ") " + << " final_width " << pq.Size(); } return helper_.RelaxGivenVariables(initial_solution, relaxed_variables); diff --git a/ortools/sat/feasibility_jump.cc b/ortools/sat/feasibility_jump.cc index 8219baf393d..1083b3e6e01 100644 --- a/ortools/sat/feasibility_jump.cc +++ b/ortools/sat/feasibility_jump.cc @@ -86,7 +86,8 @@ bool JumpTable::JumpIsUpToDate(int var) const { if (abs(score - scores_[var]) / std::max(abs(score), 1.0) > 1e-2) { score_ok = false; LOG(ERROR) << "Incorrect score for var " << var << ": " << scores_[var] - << " (should be " << score << ") " << " delta = " << delta; + << " (should be " << score << ") " + << " delta = " << delta; } return delta == deltas_[var] && score_ok; } diff --git a/ortools/sat/linear_constraint_manager.cc b/ortools/sat/linear_constraint_manager.cc index c0524551ac0..ec2d67e595c 100644 --- a/ortools/sat/linear_constraint_manager.cc +++ b/ortools/sat/linear_constraint_manager.cc @@ -254,7 +254,8 @@ bool LinearConstraintManager::AddCut(LinearConstraint ct, std::string type_name, // Only add cut with sufficient efficacy. if (violation / l2_norm < 1e-4) { - VLOG(3) << "BAD Cut '" << type_name << "'" << " size=" << ct.num_terms + VLOG(3) << "BAD Cut '" << type_name << "'" + << " size=" << ct.num_terms << " max_magnitude=" << ComputeInfinityNorm(ct) << " norm=" << l2_norm << " violation=" << violation << " eff=" << violation / l2_norm << " " << extra_info; diff --git a/ortools/sat/lp_utils.cc b/ortools/sat/lp_utils.cc index 847d64cf082..a95b8b70b16 100644 --- a/ortools/sat/lp_utils.cc +++ b/ortools/sat/lp_utils.cc @@ -1507,8 +1507,8 @@ bool ConvertBinaryMPModelProtoToBooleanProblem(const MPModelProto& mp_model, // Abort if the variable is not binary. if (!is_binary) { LOG(WARNING) << "The variable #" << var_id << " with name " - << mp_var.name() << " is not binary. " << "lb: " << lb - << " ub: " << ub; + << mp_var.name() << " is not binary. " + << "lb: " << lb << " ub: " << ub; return false; } } diff --git a/ortools/sat/precedences.cc b/ortools/sat/precedences.cc index 34b1559a0df..18b2a363d03 100644 --- a/ortools/sat/precedences.cc +++ b/ortools/sat/precedences.cc @@ -647,8 +647,9 @@ void PrecedencesPropagator::AddArc( // A self-arc is either plain SAT or plain UNSAT or it forces something on // the given offset_var or presence_literal_index. In any case it could be // presolved in something more efficient. - VLOG(1) << "Self arc! This could be presolved. " << "var:" << tail - << " offset:" << offset << " offset_var:" << offset_var + VLOG(1) << "Self arc! This could be presolved. " + << "var:" << tail << " offset:" << offset + << " offset_var:" << offset_var << " conditioned_by:" << presence_literals; } diff --git a/ortools/sat/probing.cc b/ortools/sat/probing.cc index 941c78c8309..37d9b7d9d3d 100644 --- a/ortools/sat/probing.cc +++ b/ortools/sat/probing.cc @@ -890,8 +890,9 @@ bool FailedLiteralProbingRound(ProbingOptions options, Model* model) { const bool limit_reached = time_limit->LimitReached() || time_limit->GetElapsedDeterministicTime() > limit; LOG_IF(INFO, options.log_info) - << "Probing. " << " num_probed: " << num_probed << " num_fixed: +" - << num_newly_fixed << " (" << num_fixed << "/" << num_variables << ")" + << "Probing. " + << " num_probed: " << num_probed << " num_fixed: +" << num_newly_fixed + << " (" << num_fixed << "/" << num_variables << ")" << " explicit_fix:" << num_explicit_fix << " num_conflicts:" << num_conflicts << " new_binary_clauses: " << num_new_binary diff --git a/ortools/sat/sat_base.h b/ortools/sat/sat_base.h index c342af7105f..ced510384bd 100644 --- a/ortools/sat/sat_base.h +++ b/ortools/sat/sat_base.h @@ -625,8 +625,9 @@ inline bool SatPropagator::PropagatePreconditionsAreSatisfied( if (propagation_trail_index_ < trail.Index() && trail.Info(trail[propagation_trail_index_].Variable()).level != trail.CurrentDecisionLevel()) { - LOG(INFO) << "Issue in '" << name_ << "':" << " propagation_trail_index_=" - << propagation_trail_index_ << " trail_.Index()=" << trail.Index() + LOG(INFO) << "Issue in '" << name_ << "':" + << " propagation_trail_index_=" << propagation_trail_index_ + << " trail_.Index()=" << trail.Index() << " level_at_propagation_index=" << trail.Info(trail[propagation_trail_index_].Variable()).level << " current_decision_level=" << trail.CurrentDecisionLevel(); diff --git a/ortools/sat/sat_inprocessing.cc b/ortools/sat/sat_inprocessing.cc index 1d6dd85cd28..24a7de25b86 100644 --- a/ortools/sat/sat_inprocessing.cc +++ b/ortools/sat/sat_inprocessing.cc @@ -704,8 +704,8 @@ bool StampingSimplifier::ComputeStampsForNextRound(bool log_info) { // TODO(user): compute some dtime, it is always zero currently. time_limit_->AdvanceDeterministicTime(dtime_); - LOG_IF(INFO, log_info) << "Prestamping." << " num_fixed: " << num_fixed_ - << " dtime: " << dtime_ + LOG_IF(INFO, log_info) << "Prestamping." + << " num_fixed: " << num_fixed_ << " dtime: " << dtime_ << " wtime: " << wall_timer.Get(); return true; } @@ -1259,7 +1259,8 @@ bool BoundedVariableElimination::DoOneRound(bool log_info) { dtime_ += 1e-8 * num_inspected_literals_; time_limit_->AdvanceDeterministicTime(dtime_); log_info |= VLOG_IS_ON(1); - LOG_IF(INFO, log_info) << "BVE." << " num_fixed: " + LOG_IF(INFO, log_info) << "BVE." + << " num_fixed: " << trail_->Index() - saved_trail_index << " num_simplified_literals: " << num_simplifications_ << " num_blocked_clauses_: " << num_blocked_clauses_ diff --git a/ortools/sat/var_domination.cc b/ortools/sat/var_domination.cc index f4368db2d57..ae589ac3e7c 100644 --- a/ortools/sat/var_domination.cc +++ b/ortools/sat/var_domination.cc @@ -1304,8 +1304,8 @@ void ScanModelForDominanceDetection(PresolveContext& context, } } if (num_unconstrained_refs == 0 && num_dominated_refs == 0) return; - VLOG(1) << "Dominance:" << " num_unconstrained_refs=" - << num_unconstrained_refs + VLOG(1) << "Dominance:" + << " num_unconstrained_refs=" << num_unconstrained_refs << " num_dominated_refs=" << num_dominated_refs << " num_dominance_relations=" << num_dominance_relations; } diff --git a/ortools/sat/work_assignment_test.cc b/ortools/sat/work_assignment_test.cc index 2236c3d0124..ba4a6d95334 100644 --- a/ortools/sat/work_assignment_test.cc +++ b/ortools/sat/work_assignment_test.cc @@ -17,8 +17,8 @@ #include "absl/strings/string_view.h" #include "gtest/gtest.h" -#include "net/proto2/contrib/parse_proto/parse_text_proto.h" #include "ortools/base/gmock.h" +#include "ortools/base/parse_text_proto.h" #include "ortools/sat/cp_model.h" #include "ortools/sat/cp_model.pb.h" #include "ortools/sat/cp_model_checker.h"