From 58f5531cfff1324aa001cd1da6c750669510a87b Mon Sep 17 00:00:00 2001 From: Nikolaj Bjorner Date: Tue, 29 Jan 2019 08:18:03 -0800 Subject: [PATCH] fix #2114 introduced while working on #2095 Signed-off-by: Nikolaj Bjorner --- src/sat/sat_solver.cpp | 125 ++++++++++++++++++++++------------------- src/sat/sat_solver.h | 1 + src/solver/solver.cpp | 7 ++- 3 files changed, 72 insertions(+), 61 deletions(-) diff --git a/src/sat/sat_solver.cpp b/src/sat/sat_solver.cpp index fa1d9352d..dd25c9d2b 100644 --- a/src/sat/sat_solver.cpp +++ b/src/sat/sat_solver.cpp @@ -1664,6 +1664,7 @@ namespace sat { if (m_conflicts_since_init < m_next_simplify) { return; } + log_stats(); m_simplifications++; IF_VERBOSE(2, verbose_stream() << "(sat.simplify :simplifications " << m_simplifications << ")\n";); @@ -1890,75 +1891,81 @@ namespace sat { m_config.m_restart_margin * m_slow_glue_avg <= m_fast_glue_avg; } + void solver::log_stats() { + m_restart_logs++; + + std::stringstream strm; + strm << "(sat.stats " << std::setw(6) << m_stats.m_conflict << " " + << std::setw(6) << m_stats.m_decision << " " + << std::setw(4) << m_stats.m_restart + << mk_stat(*this) + << " " << std::setw(6) << std::setprecision(2) << m_stopwatch.get_current_seconds() << ")\n"; + std::string str(strm.str()); + svector nums; + for (size_t i = 0; i < str.size(); ++i) { + while (i < str.size() && str[i] != ' ') ++i; + while (i < str.size() && str[i] == ' ') ++i; + // position of first character after space + if (i < str.size()) { + nums.push_back(i); + } + } + bool same = m_last_positions.size() == nums.size(); + size_t diff = 0; + for (unsigned i = 0; i < nums.size() && same; ++i) { + if (m_last_positions[i] > nums[i]) diff += m_last_positions[i] - nums[i]; + if (m_last_positions[i] < nums[i]) diff += nums[i] - m_last_positions[i]; + } + if (m_last_positions.empty() || + m_restart_logs >= 20 + m_last_position_log || + (m_restart_logs >= 6 + m_last_position_log && (!same || diff > 3))) { + m_last_position_log = m_restart_logs; + // conflicts restarts learned gc time + // decisions clauses units memory + int adjust[9] = { -3, -3, -3, -1, -3, -2, -1, -2, -1 }; + char const* tag[9] = { ":conflicts ", ":decisions ", ":restarts ", ":clauses/bin ", ":learned/bin ", ":units ", ":gc ", ":memory ", ":time" }; + std::stringstream l1, l2; + l1 << "(sat.stats "; + l2 << "(sat.stats "; + size_t p1 = 11, p2 = 11; + SASSERT(nums.size() == 9); + for (unsigned i = 0; i < 9 && i < nums.size(); ++i) { + size_t p = nums[i]; + if (i & 0x1) { + // odd positions + for (; p2 < p + adjust[i]; ++p2) l2 << " "; + p2 += strlen(tag[i]); + l2 << tag[i]; + } + else { + // even positions + for (; p1 < p + adjust[i]; ++p1) l1 << " "; + p1 += strlen(tag[i]); + l1 << tag[i]; + } + } + for (; p1 + 2 < str.size(); ++p1) l1 << " "; + for (; p2 + 2 < str.size(); ++p2) l2 << " "; + l1 << ")\n"; + l2 << ")\n"; + IF_VERBOSE(1, verbose_stream() << l1.str() << l2.str()); + m_last_positions.reset(); + m_last_positions.append(nums); + } + IF_VERBOSE(1, verbose_stream() << str); + } + void solver::restart(bool to_base) { m_stats.m_restart++; m_restarts++; if (m_conflicts_since_init >= m_restart_next_out && get_verbosity_level() >= 1) { - m_restart_logs++; if (0 == m_restart_next_out) { m_restart_next_out = 1; } else { m_restart_next_out = (3*m_restart_next_out)/2 + 1; } - - std::stringstream strm; - strm << "(sat.stats " << std::setw(6) << m_stats.m_conflict << " " - << std::setw(6) << m_stats.m_decision << " " - << std::setw(4) << m_stats.m_restart - << mk_stat(*this) - << " " << std::setw(6) << std::setprecision(2) << m_stopwatch.get_current_seconds() << ")\n"; - std::string str(strm.str()); - svector nums; - for (size_t i = 0; i < str.size(); ++i) { - while (i < str.size() && str[i] != ' ') ++i; - while (i < str.size() && str[i] == ' ') ++i; - // position of first character after space - if (i < str.size()) { - nums.push_back(i); - } - } - bool same = m_last_positions.size() == nums.size(); - size_t diff = 0; - for (unsigned i = 0; i < nums.size() && same; ++i) { - if (m_last_positions[i] > nums[i]) diff += m_last_positions[i] - nums[i]; - if (m_last_positions[i] < nums[i]) diff += nums[i] - m_last_positions[i]; - } - if (m_last_positions.empty() || m_restart_logs >= 20 + m_last_position_log || (m_restart_logs >= 6 + m_last_position_log && (!same || diff > 3))) { - m_last_position_log = m_restart_logs; - // conflicts restarts learned gc time - // decisions clauses units memory - int adjust[9] = { -3, -3, -3, -1, -3, -2, -1, -2, -1 }; - char const* tag[9] = { ":conflicts ", ":decisions ", ":restarts ", ":clauses/bin ", ":learned/bin ", ":units ", ":gc ", ":memory ", ":time" }; - std::stringstream l1, l2; - l1 << "(sat.stats "; - l2 << "(sat.stats "; - size_t p1 = 11, p2 = 11; - SASSERT(nums.size() == 9); - for (unsigned i = 0; i < 9 && i < nums.size(); ++i) { - size_t p = nums[i]; - if (i & 0x1) { - // odd positions - for (; p2 < p + adjust[i]; ++p2) l2 << " "; - p2 += strlen(tag[i]); - l2 << tag[i]; - } - else { - // even positions - for (; p1 < p + adjust[i]; ++p1) l1 << " "; - p1 += strlen(tag[i]); - l1 << tag[i]; - } - } - for (; p1 + 2 < str.size(); ++p1) l1 << " "; - for (; p2 + 2 < str.size(); ++p2) l2 << " "; - l1 << ")\n"; - l2 << ")\n"; - IF_VERBOSE(1, verbose_stream() << l1.str() << l2.str()); - m_last_positions.reset(); - m_last_positions.append(nums); - } - IF_VERBOSE(1, verbose_stream() << str); + log_stats(); } IF_VERBOSE(30, display_status(verbose_stream());); pop_reinit(restart_level(to_base)); diff --git a/src/sat/sat_solver.h b/src/sat/sat_solver.h index 48fc54598..96cc53b4a 100644 --- a/src/sat/sat_solver.h +++ b/src/sat/sat_solver.h @@ -425,6 +425,7 @@ namespace sat { unsigned m_last_position_log; unsigned m_restart_logs; unsigned restart_level(bool to_base); + void log_stats(); bool should_restart() const; void set_next_restart(); bool reached_max_conflicts(); diff --git a/src/solver/solver.cpp b/src/solver/solver.cpp index 6f4880d38..9126ab1a2 100644 --- a/src/solver/solver.cpp +++ b/src/solver/solver.cpp @@ -338,8 +338,11 @@ lbool solver::check_sat(unsigned num_assumptions, expr * const * assumptions) { } void solver::dump_state(unsigned sz, expr* const* assumptions) { - std::string file = m_cancel_backup_file.str(); - if (file != "") { + if ((symbol::null != m_cancel_backup_file) && + !m_cancel_backup_file.is_numerical() && + m_cancel_backup_file.c_ptr() && + m_cancel_backup_file.bare_str()[0]) { + std::string file = m_cancel_backup_file.str(); std::ofstream ous(file); display(ous, sz, assumptions); }