3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-24 17:45:32 +00:00

add local search parameters and co-processor mode

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2017-02-27 23:35:50 -08:00
parent 31c68b6e23
commit fb4f6d654a
7 changed files with 33 additions and 5 deletions

View file

@ -36,6 +36,7 @@ namespace sat {
m_glue_psm("glue_psm"),
m_psm_glue("psm_glue") {
m_num_threads = 1;
m_local_search = false;
updt_params(p);
}
@ -79,6 +80,7 @@ namespace sat {
m_max_conflicts = p.max_conflicts();
m_num_threads = p.threads();
m_local_search = p.local_search();
// These parameters are not exposed
m_simplify_mult1 = _p.get_uint("simplify_mult1", 300);

View file

@ -58,6 +58,7 @@ namespace sat {
unsigned m_burst_search;
unsigned m_max_conflicts;
unsigned m_num_threads;
bool m_local_search;
unsigned m_simplify_mult1;
double m_simplify_mult2;

View file

@ -300,8 +300,8 @@ namespace sat {
timer.start();
// ################## start ######################
//std::cout << "Start initialize and local search, restart in every " << max_steps << " steps\n";
unsigned tries, step;
for (tries = 0; ; ++tries) {
unsigned tries, step = 0;
for (tries = 0; m_limit.inc(); ++tries) {
reinit();
for (step = 1; step <= max_steps; ++step) {
// feasible
@ -318,8 +318,10 @@ namespace sat {
}
IF_VERBOSE(1, if (tries % 10 == 0) verbose_stream() << tries << ": " << timer.get_seconds() << '\n';);
if (!m_limit.inc())
break;
// tell the SAT solvers about the phase of variables.
if (m_par && tries % 10 == 0) {
m_par->set_phase(*this);
}
}
IF_VERBOSE(1, verbose_stream() << timer.get_seconds() << " " << (reach_known_best_value ? "reached":"not reached") << "\n";);

View file

@ -139,6 +139,8 @@ namespace sat {
}
}
limit = m_units.size();
_get_phase(s);
}
}
@ -231,6 +233,12 @@ namespace sat {
void parallel::get_phase(solver& s) {
#pragma omp critical (par_solver)
{
_get_phase(s);
}
}
void parallel::_get_phase(solver& s) {
if (!m_phase.empty()) {
m_phase.reserve(s.num_vars(), 0);
for (unsigned i = 0; i < s.num_vars(); ++i) {
if (m_phase[i] < 0) {
@ -243,7 +251,7 @@ namespace sat {
}
}
void parallel::get_phase(local_search& s) {
void parallel::set_phase(local_search& s) {
#pragma omp critical (par_solver)
{
m_phase.reserve(s.num_vars(), 0);
@ -258,6 +266,16 @@ namespace sat {
}
}
void parallel::get_phase(local_search& s) {
#pragma omp critical (par_solver)
{
m_phase.reserve(s.num_vars(), 0);
for (unsigned i = 0; i < s.num_vars(); ++i) {
m_phase[i] += (s.get_phase(i) ? 1 : -1);
}
}
}
};

View file

@ -52,6 +52,7 @@ namespace sat {
bool enable_add(clause const& c) const;
void _get_clauses(solver& s);
void _get_phase(solver& s);
typedef hashtable<unsigned, u_hash, u_eq> index_set;
literal_vector m_units;

View file

@ -28,4 +28,5 @@ def_module_params('sat',
('drat.check', BOOL, False, 'build up internal proof and check'),
('cardinality.solver', BOOL, False, 'use cardinality solver'),
('xor.solver', BOOL, False, 'use xor solver'),
('local_search', BOOL, False, 'add local search co-processor to find satisfiable solution'),
))

View file

@ -782,6 +782,9 @@ namespace sat {
pop_to_base_level();
IF_VERBOSE(2, verbose_stream() << "(sat.sat-solver)\n";);
SASSERT(at_base_lvl());
if (m_config.m_local_search && !m_local_search) {
m_local_search = alloc(local_search, *this);
}
if ((m_config.m_num_threads > 1 || m_local_search) && !m_par) {
return check_par(num_lits, lits);
}