mirror of
https://github.com/Z3Prover/z3
synced 2025-06-20 12:53:38 +00:00
porting more code
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
eec1d9ef84
commit
eec10c6e32
1 changed files with 168 additions and 158 deletions
|
@ -1,21 +1,21 @@
|
||||||
/*++
|
/*++
|
||||||
Copyright (c) 2017 Microsoft Corporation
|
Copyright (c) 2017 Microsoft Corporation
|
||||||
|
|
||||||
Module Name:
|
Module Name:
|
||||||
|
|
||||||
sat_local_search.cpp
|
sat_local_search.cpp
|
||||||
|
|
||||||
Abstract:
|
Abstract:
|
||||||
|
|
||||||
Local search module for cardinality clauses.
|
Local search module for cardinality clauses.
|
||||||
|
|
||||||
Author:
|
Author:
|
||||||
|
|
||||||
Sixue Liu 2017-2-21
|
Sixue Liu 2017-2-21
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
--*/
|
--*/
|
||||||
|
|
||||||
#include "sat_local_search.h"
|
#include "sat_local_search.h"
|
||||||
|
|
||||||
|
@ -231,12 +231,15 @@ namespace sat {
|
||||||
int org_flipvar_sscore = sscore[flipvar];
|
int org_flipvar_sscore = sscore[flipvar];
|
||||||
|
|
||||||
// update related clauses and neighbor vars
|
// update related clauses and neighbor vars
|
||||||
for (unsigned i = 0; i < var_term[flipvar].size(); ++i) {
|
svector<term> const& constraints = var_term[flipvar];
|
||||||
c = var_term[flipvar][i].constraint_id;
|
unsigned num_constraints = constraints.size();
|
||||||
if (cur_solution[flipvar] == var_term[flipvar][i].sense) {
|
for (unsigned i = 0; i < num_constraints; ++i) {
|
||||||
|
c = constraints[i].constraint_id;
|
||||||
|
if (cur_solution[flipvar] == constraints[i].sense) {
|
||||||
//++true_terms_count[c];
|
//++true_terms_count[c];
|
||||||
--constraint_slack[c];
|
--constraint_slack[c];
|
||||||
if (constraint_slack[c] == -2) { // from -1 to -2
|
switch (constraint_slack[c]) {
|
||||||
|
case -2: // from -1 to -2
|
||||||
for (unsigned j = 0; j < constraint_term[c].size(); ++j) {
|
for (unsigned j = 0; j < constraint_term[c].size(); ++j) {
|
||||||
v = constraint_term[c][j].var_id;
|
v = constraint_term[c][j].var_id;
|
||||||
// flipping the slack increasing var will no long sat this constraint
|
// flipping the slack increasing var will no long sat this constraint
|
||||||
|
@ -244,8 +247,8 @@ namespace sat {
|
||||||
//score[v] -= constraint_weight[c];
|
//score[v] -= constraint_weight[c];
|
||||||
--score[v];
|
--score[v];
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
else if (constraint_slack[c] == -1) { // from 0 to -1: sat -> unsat
|
case -1: // from 0 to -1: sat -> unsat
|
||||||
for (unsigned j = 0; j < constraint_term[c].size(); ++j) {
|
for (unsigned j = 0; j < constraint_term[c].size(); ++j) {
|
||||||
v = constraint_term[c][j].var_id;
|
v = constraint_term[c][j].var_id;
|
||||||
++cscc[v];
|
++cscc[v];
|
||||||
|
@ -256,8 +259,8 @@ namespace sat {
|
||||||
++sscore[v];
|
++sscore[v];
|
||||||
}
|
}
|
||||||
unsat(c);
|
unsat(c);
|
||||||
}
|
break;
|
||||||
else if (constraint_slack[c] == 0) { // from 1 to 0
|
case 0: // from 1 to 0
|
||||||
for (unsigned j = 0; j < constraint_term[c].size(); ++j) {
|
for (unsigned j = 0; j < constraint_term[c].size(); ++j) {
|
||||||
v = constraint_term[c][j].var_id;
|
v = constraint_term[c][j].var_id;
|
||||||
// flip the slack decreasing var will falsify this constraint
|
// flip the slack decreasing var will falsify this constraint
|
||||||
|
@ -267,12 +270,16 @@ namespace sat {
|
||||||
--sscore[v];
|
--sscore[v];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { // if (cur_solution[flipvar] != var_term[i].sense)
|
else { // if (cur_solution[flipvar] != var_term[i].sense)
|
||||||
//--true_terms_count[c];
|
//--true_terms_count[c];
|
||||||
++constraint_slack[c];
|
++constraint_slack[c];
|
||||||
if (constraint_slack[c] == 1) { // from 0 to 1
|
switch (constraint_slack[c]) {
|
||||||
|
case 1: // from 0 to 1
|
||||||
for (unsigned j = 0; j < constraint_term[c].size(); ++j) {
|
for (unsigned j = 0; j < constraint_term[c].size(); ++j) {
|
||||||
v = constraint_term[c][j].var_id;
|
v = constraint_term[c][j].var_id;
|
||||||
// flip the slack decreasing var will no long falsify this constraint
|
// flip the slack decreasing var will no long falsify this constraint
|
||||||
|
@ -282,8 +289,8 @@ namespace sat {
|
||||||
++sscore[v];
|
++sscore[v];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
else if (constraint_slack[c] == 0) { // from -1 to 0: unsat -> sat
|
case 0: // from -1 to 0: unsat -> sat
|
||||||
for (unsigned j = 0; j < constraint_term[c].size(); ++j) {
|
for (unsigned j = 0; j < constraint_term[c].size(); ++j) {
|
||||||
v = constraint_term[c][j].var_id;
|
v = constraint_term[c][j].var_id;
|
||||||
++cscc[v];
|
++cscc[v];
|
||||||
|
@ -294,8 +301,8 @@ namespace sat {
|
||||||
--sscore[v];
|
--sscore[v];
|
||||||
}
|
}
|
||||||
sat(c);
|
sat(c);
|
||||||
}
|
break;
|
||||||
else if (constraint_slack[c] == -1) { // from -2 to -1
|
case -1: // from -2 to -1
|
||||||
for (unsigned j = 0; j < constraint_term[c].size(); ++j) {
|
for (unsigned j = 0; j < constraint_term[c].size(); ++j) {
|
||||||
v = constraint_term[c][j].var_id;
|
v = constraint_term[c][j].var_id;
|
||||||
// flip the slack increasing var will satisfy this constraint
|
// flip the slack increasing var will satisfy this constraint
|
||||||
|
@ -303,6 +310,9 @@ namespace sat {
|
||||||
//score[v] += constraint_weight[c];
|
//score[v] += constraint_weight[c];
|
||||||
++score[v];
|
++score[v];
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue