diff --git a/constraint_solver/constraint_solver.h b/constraint_solver/constraint_solver.h index 4993fdd96f..0440e0519e 100644 --- a/constraint_solver/constraint_solver.h +++ b/constraint_solver/constraint_solver.h @@ -227,10 +227,15 @@ struct DefaultPhaseParameters { // Seed used to initialize the random part in some heuristics. int random_seed; // Automatic Restart Size. When diving down, the size of the search - // space disminishes. If the current log of the search space is - // greater than the the minimal value encountered + + // space disminishes. We maintain the minimal log of the size of the search + // space with the following behavior: + // - A failure is ignored (no null size). + // - A solution has a size of 1 (and a log of 0). + // Then when backtracking, if the current log of the size of the + // search space is greater than the minimizal log size recorded + // 'restart_log_size', then the search is restarted from scratch. A - // parameter < 0 means no restart. + // parameter < 0 means no restart. A parameter of 0 indicates that + // we restart after each failure. double restart_log_size; }; diff --git a/constraint_solver/default_search.cc b/constraint_solver/default_search.cc index 61bae66011..e45cf5fbb6 100644 --- a/constraint_solver/default_search.cc +++ b/constraint_solver/default_search.cc @@ -516,7 +516,7 @@ class ImpactDecisionBuilder : public DecisionBuilder { runner_(NewPermanentCallback(this, &ImpactDecisionBuilder::RunHeuristics)), heuristic_branch_count_(0), - min_log_search_space_(std::numeric_limits::max()) { + min_log_search_space_(std::numeric_limits::infinity()) { CHECK_GE(size_, 0); if (size_ > 0) { vars_.reset(new IntVar*[size_]); @@ -663,7 +663,7 @@ class ImpactDecisionBuilder : public DecisionBuilder { virtual Decision* Next(Solver* const solver) { if (!init_done_) { - LOG(INFO) << "Init impact based search phase on " << size_ + LOG(INFO) << "Init impact based search phase on " << size_ << " variables, initialization splits = " << parameters_.initialization_splits << ", heuristic_period = " << parameters_.heuristic_period @@ -701,7 +701,7 @@ class ImpactDecisionBuilder : public DecisionBuilder { } else if (min_log_search_space_ + parameters_.restart_log_size < log_search_space_size) { VLOG(2) << "Restarting "; - min_log_search_space_ = std::numeric_limits::max(); + min_log_search_space_ = std::numeric_limits::infinity(); solver->RestartSearch(); } } @@ -735,8 +735,13 @@ class ImpactDecisionBuilder : public DecisionBuilder { name(heuristic_name), runs(heuristic_runs) {} + // The decision builder we are going to use in this dive. DecisionBuilder* const phase; + // A name for logging purposes. const string name; + // How many time we will run this particular heuristic in case the + // parameter run_all_heuristics is true. This is useful for random + // heuristics where it makes sense to run them more than once. const int runs; };