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
|
||||
|
||||
Abstract:
|
||||
Abstract:
|
||||
|
||||
Local search module for cardinality clauses.
|
||||
|
||||
Author:
|
||||
Author:
|
||||
|
||||
Sixue Liu 2017-2-21
|
||||
|
||||
Notes:
|
||||
Notes:
|
||||
|
||||
--*/
|
||||
--*/
|
||||
|
||||
#include "sat_local_search.h"
|
||||
|
||||
|
@ -231,12 +231,15 @@ namespace sat {
|
|||
int org_flipvar_sscore = sscore[flipvar];
|
||||
|
||||
// update related clauses and neighbor vars
|
||||
for (unsigned i = 0; i < var_term[flipvar].size(); ++i) {
|
||||
c = var_term[flipvar][i].constraint_id;
|
||||
if (cur_solution[flipvar] == var_term[flipvar][i].sense) {
|
||||
svector<term> const& constraints = var_term[flipvar];
|
||||
unsigned num_constraints = constraints.size();
|
||||
for (unsigned i = 0; i < num_constraints; ++i) {
|
||||
c = constraints[i].constraint_id;
|
||||
if (cur_solution[flipvar] == constraints[i].sense) {
|
||||
//++true_terms_count[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) {
|
||||
v = constraint_term[c][j].var_id;
|
||||
// flipping the slack increasing var will no long sat this constraint
|
||||
|
@ -244,8 +247,8 @@ namespace sat {
|
|||
//score[v] -= constraint_weight[c];
|
||||
--score[v];
|
||||
}
|
||||
}
|
||||
else if (constraint_slack[c] == -1) { // from 0 to -1: sat -> unsat
|
||||
break;
|
||||
case -1: // from 0 to -1: sat -> unsat
|
||||
for (unsigned j = 0; j < constraint_term[c].size(); ++j) {
|
||||
v = constraint_term[c][j].var_id;
|
||||
++cscc[v];
|
||||
|
@ -256,8 +259,8 @@ namespace sat {
|
|||
++sscore[v];
|
||||
}
|
||||
unsat(c);
|
||||
}
|
||||
else if (constraint_slack[c] == 0) { // from 1 to 0
|
||||
break;
|
||||
case 0: // from 1 to 0
|
||||
for (unsigned j = 0; j < constraint_term[c].size(); ++j) {
|
||||
v = constraint_term[c][j].var_id;
|
||||
// flip the slack decreasing var will falsify this constraint
|
||||
|
@ -267,12 +270,16 @@ namespace sat {
|
|||
--sscore[v];
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else { // if (cur_solution[flipvar] != var_term[i].sense)
|
||||
//--true_terms_count[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) {
|
||||
v = constraint_term[c][j].var_id;
|
||||
// flip the slack decreasing var will no long falsify this constraint
|
||||
|
@ -282,8 +289,8 @@ namespace sat {
|
|||
++sscore[v];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (constraint_slack[c] == 0) { // from -1 to 0: unsat -> sat
|
||||
break;
|
||||
case 0: // from -1 to 0: unsat -> sat
|
||||
for (unsigned j = 0; j < constraint_term[c].size(); ++j) {
|
||||
v = constraint_term[c][j].var_id;
|
||||
++cscc[v];
|
||||
|
@ -294,8 +301,8 @@ namespace sat {
|
|||
--sscore[v];
|
||||
}
|
||||
sat(c);
|
||||
}
|
||||
else if (constraint_slack[c] == -1) { // from -2 to -1
|
||||
break;
|
||||
case -1: // from -2 to -1
|
||||
for (unsigned j = 0; j < constraint_term[c].size(); ++j) {
|
||||
v = constraint_term[c][j].var_id;
|
||||
// flip the slack increasing var will satisfy this constraint
|
||||
|
@ -303,6 +310,9 @@ namespace sat {
|
|||
//score[v] += constraint_weight[c];
|
||||
++score[v];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue