16 #include "absl/strings/str_format.h"
17 #include "absl/strings/str_split.h"
25 strategy_counter_ = 0;
26 strategy_change_conflicts_ =
27 parameters_.num_conflicts_before_strategy_changes();
28 conflicts_until_next_strategy_change_ = strategy_change_conflicts_;
31 conflicts_until_next_restart_ = parameters_.restart_period();
33 dl_running_average_.
Reset(parameters_.restart_running_window_size());
34 lbd_running_average_.
Reset(parameters_.restart_running_window_size());
35 trail_size_running_average_.
Reset(parameters_.blocking_restart_window_size());
42 for (
int i = 0; i < parameters_.restart_algorithms_size(); ++i) {
43 strategies_.push_back(parameters_.restart_algorithms(i));
45 if (strategies_.empty()) {
46 const std::vector<std::string> string_values = absl::StrSplit(
47 parameters_.default_restart_algorithms(),
',', absl::SkipEmpty());
48 for (
const std::string& string_value : string_values) {
49 SatParameters::RestartAlgorithm tmp;
50 #if defined(__PORTABLE_PLATFORM__)
51 if (string_value ==
"NO_RESTART") {
52 tmp = SatParameters::NO_RESTART;
53 }
else if (string_value ==
"LUBY_RESTART") {
54 tmp = SatParameters::LUBY_RESTART;
55 }
else if (string_value ==
"DL_MOVING_AVERAGE_RESTART") {
56 tmp = SatParameters::DL_MOVING_AVERAGE_RESTART;
57 }
else if (string_value ==
"LBD_MOVING_AVERAGE_RESTART") {
58 tmp = SatParameters::LBD_MOVING_AVERAGE_RESTART;
59 }
else if (string_value ==
"FIXED_RESTART") {
60 tmp = SatParameters::FIXED_RESTART;
62 LOG(
WARNING) <<
"Couldn't parse the RestartAlgorithm name: '"
63 << string_value <<
"'.";
66 #else // __PORTABLE_PLATFORM__
67 if (!SatParameters::RestartAlgorithm_Parse(string_value, &tmp)) {
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()) {
77 strategies_.push_back(SatParameters::NO_RESTART);
82 bool should_restart =
false;
83 switch (strategies_[strategy_counter_ % strategies_.size()]) {
84 case SatParameters::NO_RESTART:
86 case SatParameters::LUBY_RESTART:
87 if (conflicts_until_next_restart_ == 0) {
89 should_restart =
true;
92 case SatParameters::DL_MOVING_AVERAGE_RESTART:
95 parameters_.restart_dl_average_ratio() *
97 should_restart =
true;
100 case SatParameters::LBD_MOVING_AVERAGE_RESTART:
103 parameters_.restart_lbd_average_ratio() *
105 should_restart =
true;
108 case SatParameters::FIXED_RESTART:
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_ +=
121 static_cast<int>(parameters_.strategy_change_increase_ratio() *
122 strategy_change_conflicts_);
123 conflicts_until_next_strategy_change_ = strategy_change_conflicts_;
128 strategies_[strategy_counter_ % strategies_.size()] ==
129 SatParameters::LUBY_RESTART);
135 conflicts_until_next_restart_ = parameters_.restart_period();
136 if (strategies_[strategy_counter_ % strategies_.size()] ==
137 SatParameters::LUBY_RESTART) {
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);
160 if (parameters_.use_blocking_restart()) {
164 conflict_trail_index >
165 parameters_.blocking_restart_multiplier() *
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",