mirror of
https://github.com/Z3Prover/z3
synced 2025-07-23 20:58:54 +00:00
fixing local search
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
41e1b9f3fe
commit
352f8b6cb9
5 changed files with 32 additions and 23 deletions
|
@ -70,9 +70,10 @@ namespace sat {
|
|||
|
||||
void local_search::init_cur_solution() {
|
||||
for (unsigned v = 0; v < num_vars(); ++v) {
|
||||
// use bias half the time.
|
||||
if (m_rand() % 100 < 10) {
|
||||
m_vars[v].m_value = ((unsigned)(m_rand() % 100) < m_vars[v].m_bias);
|
||||
// use bias with a small probability
|
||||
if (m_rand() % 100 < 3) {
|
||||
//m_vars[v].m_value = ((unsigned)(m_rand() % 100) < m_vars[v].m_bias);
|
||||
m_vars[v].m_value = (50 < m_vars[v].m_bias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,14 +141,17 @@ namespace sat {
|
|||
// the following methods does NOT converge for pseudo-boolean
|
||||
// can try other way to define "worse" and "better"
|
||||
// the current best noise is below 1000
|
||||
if (best_unsat_rate >= last_best_unsat_rate) {
|
||||
#if 0
|
||||
if (m_best_unsat_rate > m_last_best_unsat_rate) {
|
||||
// worse
|
||||
m_noise -= m_noise * 2 * m_noise_delta;
|
||||
m_best_unsat_rate *= 1000.0;
|
||||
}
|
||||
else {
|
||||
// better
|
||||
m_noise += (10000 - m_noise) * m_noise_delta;
|
||||
}
|
||||
#endif
|
||||
for (unsigned i = 0; i < m_constraints.size(); ++i) {
|
||||
constraint& c = m_constraints[i];
|
||||
c.m_slack = c.m_k;
|
||||
|
@ -178,6 +182,8 @@ namespace sat {
|
|||
init_slack();
|
||||
init_scores();
|
||||
init_goodvars();
|
||||
|
||||
m_best_unsat = m_unsat_stack.size();
|
||||
}
|
||||
|
||||
void local_search::calculate_and_update_ob() {
|
||||
|
@ -382,13 +388,13 @@ namespace sat {
|
|||
IF_VERBOSE(1, verbose_stream() << "(sat-local-search" \
|
||||
<< " :flips " << flips \
|
||||
<< " :noise " << m_noise \
|
||||
<< " :unsat " << /*m_unsat_stack.size()*/ best_unsat \
|
||||
<< " :unsat " << /*m_unsat_stack.size()*/ m_best_unsat \
|
||||
<< " :time " << (timer.get_seconds() < 0.001 ? 0.0 : timer.get_seconds()) << ")\n";); \
|
||||
}
|
||||
|
||||
void local_search::walksat() {
|
||||
best_unsat_rate = 1;
|
||||
last_best_unsat_rate = 1;
|
||||
m_best_unsat_rate = 1;
|
||||
m_last_best_unsat_rate = 1;
|
||||
|
||||
|
||||
reinit();
|
||||
|
@ -398,10 +404,10 @@ namespace sat {
|
|||
PROGRESS(tries, total_flips);
|
||||
|
||||
for (tries = 1; !m_unsat_stack.empty() && m_limit.inc(); ++tries) {
|
||||
if (m_unsat_stack.size() < best_unsat) {
|
||||
best_unsat = m_unsat_stack.size();
|
||||
last_best_unsat_rate = best_unsat_rate;
|
||||
best_unsat_rate = (double)m_unsat_stack.size() / num_constraints();
|
||||
if (m_unsat_stack.size() < m_best_unsat) {
|
||||
m_best_unsat = m_unsat_stack.size();
|
||||
m_last_best_unsat_rate = m_best_unsat_rate;
|
||||
m_best_unsat_rate = (double)m_unsat_stack.size() / num_constraints();
|
||||
}
|
||||
for (step = 0; step < m_max_steps && !m_unsat_stack.empty(); ++step) {
|
||||
pick_flip_walksat();
|
||||
|
@ -506,7 +512,7 @@ namespace sat {
|
|||
SASSERT(c.m_k < constraint_value(c));
|
||||
// TBD: dynamic noise strategy
|
||||
//if (m_rand() % 100 < 98) {
|
||||
if (m_rand() % 10000 >= m_noise) {
|
||||
if (m_rand() % 10000 <= m_noise) {
|
||||
// take this branch with 98% probability.
|
||||
// find the first one, to fast break the rest
|
||||
unsigned best_bsb = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue