16 #include "absl/strings/str_format.h" 17 #include "absl/strings/str_split.h" 25 strategy_counter_ = 0;
26 strategy_change_conflicts_ =
28 conflicts_until_next_strategy_change_ = strategy_change_conflicts_;
45 if (strategies_.empty()) {
46 const std::vector<std::string> string_values = absl::StrSplit(
48 for (
const std::string& string_value : string_values) {
50 #if defined(__PORTABLE_PLATFORM__) 51 if (string_value ==
"NO_RESTART") {
53 }
else if (string_value ==
"LUBY_RESTART") {
55 }
else if (string_value ==
"DL_MOVING_AVERAGE_RESTART") {
57 }
else if (string_value ==
"LBD_MOVING_AVERAGE_RESTART") {
59 }
else if (string_value ==
"FIXED_RESTART") {
62 LOG(
WARNING) <<
"Couldn't parse the RestartAlgorithm name: '" 63 << string_value <<
"'.";
66 #else // __PORTABLE_PLATFORM__ 68 LOG(
WARNING) <<
"Couldn't parse the RestartAlgorithm name: '" 69 << string_value <<
"'.";
72 #endif // !__PORTABLE_PLATFORM__ 73 strategies_.push_back(tmp);
76 if (strategies_.empty()) {
82 bool should_restart =
false;
83 switch (strategies_[strategy_counter_ % strategies_.size()]) {
87 if (conflicts_until_next_restart_ == 0) {
89 should_restart =
true;
97 should_restart =
true;
105 should_restart =
true;
109 if (conflicts_until_next_restart_ == 0) {
110 should_restart =
true;
114 if (should_restart) {
118 if (conflicts_until_next_strategy_change_ == 0) {
120 strategy_change_conflicts_ +=
122 strategy_change_conflicts_);
123 conflicts_until_next_strategy_change_ = strategy_change_conflicts_;
128 strategies_[strategy_counter_ % strategies_.size()] ==
136 if (strategies_[strategy_counter_ % strategies_.size()] ==
138 conflicts_until_next_restart_ *=
SUniv(luby_count_ + 1);
141 return should_restart;
145 int conflict_decision_level,
int conflict_lbd) {
147 if (conflicts_until_next_restart_ > 0) {
148 --conflicts_until_next_restart_;
150 if (conflicts_until_next_strategy_change_ > 0) {
151 --conflicts_until_next_strategy_change_;
154 trail_size_running_average_.
Add(conflict_trail_index);
155 dl_running_average_.
Add(conflict_decision_level);
156 lbd_running_average_.
Add(conflict_lbd);
164 conflict_trail_index >
175 absl::StrFormat(
" num restarts: %d\n", num_restarts_) +
177 " current_strategy: %s\n",
178 ProtoEnumToString<SatParameters::RestartAlgorithm>(
179 strategies_[strategy_counter_ % strategies_.size()])) +
180 absl::StrFormat(
" conflict decision level avg: %f window: %f\n",
183 absl::StrFormat(
" conflict lbd avg: %f window: %f\n",
186 absl::StrFormat(
" conflict trail size avg: %f window: %f\n",
::PROTOBUF_NAMESPACE_ID::int32 blocking_restart_window_size() const
static constexpr RestartAlgorithm FIXED_RESTART
static constexpr RestartAlgorithm LBD_MOVING_AVERAGE_RESTART
const std::string & default_restart_algorithms() const
bool IsWindowFull() const
double restart_lbd_average_ratio() const
SatParameters_RestartAlgorithm
::PROTOBUF_NAMESPACE_ID::int32 restart_period() const
void SetStablePhase(bool is_stable)
::PROTOBUF_NAMESPACE_ID::int32 restart_running_window_size() const
double blocking_restart_multiplier() const
bool use_blocking_restart() const
static constexpr RestartAlgorithm DL_MOVING_AVERAGE_RESTART
double WindowAverage() const
static constexpr RestartAlgorithm LUBY_RESTART
void OnConflict(int conflict_trail_index, int conflict_decision_level, int conflict_lbd)
double restart_dl_average_ratio() const
int restart_algorithms_size() const
double strategy_change_increase_ratio() const
void Reset(int window_size)
static constexpr RestartAlgorithm NO_RESTART
Collection of objects used to extend the Constraint Solver library.
::operations_research::sat::SatParameters_RestartAlgorithm restart_algorithms(int index) const
std::string InfoString() const
double GlobalAverage() const
static bool RestartAlgorithm_Parse(::PROTOBUF_NAMESPACE_ID::ConstStringParam name, RestartAlgorithm *value)
::PROTOBUF_NAMESPACE_ID::int32 num_conflicts_before_strategy_changes() const