minor cosmetic changes

This commit is contained in:
Laurent Perron
2021-02-09 14:06:14 +01:00
parent 5359e31e46
commit c5cddcaca1
4 changed files with 95 additions and 22 deletions

View File

@@ -1680,7 +1680,7 @@ void QuickSolveWithHint(const CpModelProto& model_proto,
if (status == SatSolver::Status::FEASIBLE) {
CpSolverResponse response;
FillSolutionInResponse(model_proto, *model, &response);
response.set_solution_info(absl::StrCat(solution_info, " [hint]"));
response.set_solution_info(absl::StrCat(solution_info, "[hint]"));
shared_response_manager->NewSolution(response, model);
if (!model_proto.has_objective()) {
@@ -1699,7 +1699,7 @@ void QuickSolveWithHint(const CpModelProto& model_proto,
shared_response_manager->GetInnerObjectiveUpperBound()),
{}, {})) {
shared_response_manager->NotifyThatImprovingProblemIsInfeasible(
absl::StrCat(solution_info, " [hint]"));
absl::StrCat(solution_info, "[hint]"));
shared_response_manager->SetStatsFromModel(model);
return;
}
@@ -2515,7 +2515,7 @@ class LnsSolver : public SubSolver {
local_response.set_solution_info(solution_info);
} else {
local_response.set_solution_info(
absl::StrCat(local_response.solution_info(), " ", solution_info));
absl::StrCat(solution_info, " ", local_response.solution_info()));
}
// TODO(user): we actually do not need to postsolve if the solution is
@@ -3248,6 +3248,9 @@ CpSolverResponse SolveCpModel(const CpModelProto& model_proto, Model* model) {
*final_response.mutable_sufficient_assumptions_for_infeasibility() =
model_proto.assumptions();
}
if (log_search && params.num_search_workers() > 1) {
shared_response_manager.DisplayImprovementStatistics();
}
return final_response;
}

View File

@@ -60,10 +60,14 @@ LinearConstraintManager::~LinearConstraintManager() {
LOG(INFO) << "Total cuts added: " << num_cuts_ << " (out of "
<< num_add_cut_calls_ << " calls) worker: '" << model_->Name()
<< "'";
LOG(INFO) << "Num simplifications: " << num_simplifications_;
LOG(INFO) << " - num simplifications: " << num_simplifications_;
for (const auto& entry : type_to_num_cuts_) {
LOG(INFO) << "Added " << entry.second << " cuts of type '" << entry.first
<< "'.";
if (entry.second == 1) {
LOG(INFO) << " - added 1 cut of type '" << entry.first << "'.";
} else {
LOG(INFO) << " - added " << entry.second << " cuts of type '"
<< entry.first << "'.";
}
}
}
}

View File

@@ -113,9 +113,9 @@ SharedResponseManager::SharedResponseManager(bool log_updates,
namespace {
void LogNewSolution(const std::string& event_or_solution_count,
double time_in_seconds, double obj_best, double obj_lb,
double obj_ub, const std::string& solution_info) {
void LogProgress(const std::string& event_or_solution_count,
double time_in_seconds, double obj_best, double obj_lb,
double obj_ub, const std::string& solution_info) {
const std::string obj_next =
absl::StrFormat("next:[%.9g,%.9g]", obj_lb, obj_ub);
LOG(INFO) << absl::StrFormat("#%-5s %6.2fs best:%-5.9g %-15s %s",
@@ -123,9 +123,8 @@ void LogNewSolution(const std::string& event_or_solution_count,
obj_best, obj_next, solution_info);
}
void LogNewSatSolution(const std::string& event_or_solution_count,
double time_in_seconds,
const std::string& solution_info) {
void LogSatProgress(const std::string& event_or_solution_count,
double time_in_seconds, const std::string& solution_info) {
LOG(INFO) << absl::StrFormat("#%-5s %6.2fs %s", event_or_solution_count,
time_in_seconds, solution_info);
}
@@ -211,7 +210,7 @@ void SharedResponseManager::TestGapLimitsIfNeeded() {
}
void SharedResponseManager::UpdateInnerObjectiveBounds(
const std::string& worker_info, IntegerValue lb, IntegerValue ub) {
const std::string& update_info, IntegerValue lb, IntegerValue ub) {
absl::MutexLock mutex_lock(&mutex_);
CHECK(model_proto_.has_objective());
@@ -246,7 +245,7 @@ void SharedResponseManager::UpdateInnerObjectiveBounds(
best_response_.set_status(CpSolverStatus::INFEASIBLE);
}
if (update_integral_on_each_change_) UpdatePrimalIntegralInternal();
if (log_updates_) LogNewSatSolution("Done", wall_timer_.Get(), worker_info);
if (log_updates_) LogSatProgress("Done", wall_timer_.Get(), update_info);
return;
}
if (log_updates_ && change) {
@@ -258,8 +257,8 @@ void SharedResponseManager::UpdateInnerObjectiveBounds(
if (model_proto_.objective().scaling_factor() < 0) {
std::swap(new_lb, new_ub);
}
LogNewSolution("Bound", wall_timer_.Get(), best, new_lb, new_ub,
worker_info);
RegisterObjectiveBoundImprovement(update_info);
LogProgress("Bound", wall_timer_.Get(), best, new_lb, new_ub, update_info);
}
if (change) TestGapLimitsIfNeeded();
}
@@ -287,7 +286,7 @@ void SharedResponseManager::NotifyThatImprovingProblemIsInfeasible(
CHECK_EQ(num_solutions_, 0);
best_response_.set_status(CpSolverStatus::INFEASIBLE);
}
if (log_updates_) LogNewSatSolution("Done", wall_timer_.Get(), worker_info);
if (log_updates_) LogSatProgress("Done", wall_timer_.Get(), worker_info);
}
void SharedResponseManager::AddUnsatCore(const std::vector<int>& core) {
@@ -463,11 +462,12 @@ void SharedResponseManager::NewSolution(const CpSolverResponse& response,
if (model_proto_.objective().scaling_factor() < 0) {
std::swap(lb, ub);
}
LogNewSolution(absl::StrCat(num_solutions_), wall_timer_.Get(), best, lb,
ub, solution_info);
RegisterSolutionFound(solution_info);
LogProgress(absl::StrCat(num_solutions_), wall_timer_.Get(), best, lb, ub,
solution_info);
} else {
LogNewSatSolution(absl::StrCat(num_solutions_), wall_timer_.Get(),
solution_info);
LogSatProgress(absl::StrCat(num_solutions_), wall_timer_.Get(),
solution_info);
}
}
@@ -564,6 +564,60 @@ bool SharedResponseManager::ProblemIsSolved() const {
best_response_.status() == CpSolverStatus::INFEASIBLE;
}
std::string ExtractWorkerName(const std::string& improvement_info) {
if (improvement_info.empty()) return "";
std::string worker_name = improvement_info;
// Remove ' [hint]' suffix.
const auto& hint_suffix = worker_name.find(" [");
if (hint_suffix != std::string::npos) {
worker_name.erase(hint_suffix);
}
// Remove lns info suffix.
const auto& lns_suffix = worker_name.find('(');
if (lns_suffix != std::string::npos) {
worker_name.erase(lns_suffix);
}
// Remove fixed_bools suffix.
const auto fixed_suffix = worker_name.find(" fixed_bools:");
if (fixed_suffix != std::string::npos) {
worker_name.erase(fixed_suffix);
}
return worker_name;
}
void SharedResponseManager::RegisterSolutionFound(
const std::string& improvement_info) {
if (improvement_info.empty()) return;
primal_improvements_count_[ExtractWorkerName(improvement_info)]++;
}
void SharedResponseManager::RegisterObjectiveBoundImprovement(
const std::string& improvement_info) {
if (improvement_info.empty() || improvement_info == "initial domain") return;
dual_improvements_count_[ExtractWorkerName(improvement_info)]++;
}
void SharedResponseManager::DisplayImprovementStatistics() {
absl::MutexLock mutex_lock(&mutex_);
if (!primal_improvements_count_.empty()) {
LOG(INFO) << "Solutions found per subsolver:";
for (const auto& entry : primal_improvements_count_) {
LOG(INFO) << " '" << entry.first << "': " << entry.second;
}
}
if (!dual_improvements_count_.empty()) {
LOG(INFO) << "Objective bounds found per subsolver:";
for (const auto& entry : dual_improvements_count_) {
LOG(INFO) << " '" << entry.first << "': " << entry.second;
}
}
}
SharedBoundsManager::SharedBoundsManager(const CpModelProto& model_proto)
: num_variables_(model_proto.variables_size()),
model_proto_(model_proto),

View File

@@ -234,7 +234,7 @@ class SharedResponseManager {
void SetUpdatePrimalIntegralOnEachChange(bool set);
// Updates the inner objective bounds.
void UpdateInnerObjectiveBounds(const std::string& worker_info,
void UpdateInnerObjectiveBounds(const std::string& update_info,
IntegerValue lb, IntegerValue ub);
// Reads the new solution from the response and update our state. For an
@@ -293,6 +293,9 @@ class SharedResponseManager {
dump_prefix_ = dump_prefix;
}
// Display improvement stats.
void DisplayImprovementStatistics();
private:
void TestGapLimitsIfNeeded() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void FillObjectiveValuesInBestResponse()
@@ -301,6 +304,11 @@ class SharedResponseManager {
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void UpdatePrimalIntegralInternal() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void RegisterSolutionFound(const std::string& improvement_info)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void RegisterObjectiveBoundImprovement(const std::string& improvement_info)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
const bool log_updates_;
const bool enumerate_all_solutions_;
const CpModelProto& model_proto_;
@@ -337,6 +345,10 @@ class SharedResponseManager {
// Dump prefix.
std::string dump_prefix_;
// Used for statistics of the improvements found by workers.
std::map<std::string, int> primal_improvements_count_ ABSL_GUARDED_BY(mutex_);
std::map<std::string, int> dual_improvements_count_ ABSL_GUARDED_BY(mutex_);
};
// This class manages a pool of lower and upper bounds on a set of variables in