fixed v2 bug
This commit is contained in:
parent
a011f8ed53
commit
50258db84d
@ -110,14 +110,15 @@ bool preprocess::preprocess_resolution() {
|
|||||||
for (int i = 1; i <= vars; i++) {
|
for (int i = 1; i <= vars; i++) {
|
||||||
occurn[i].clear();
|
occurn[i].clear();
|
||||||
occurp[i].clear();
|
occurp[i].clear();
|
||||||
resseen[i] = resseen[i + vars] = clean[i] = seen[i] = 0;
|
resseen[i - 1] = resseen[i + vars - 1] = clean[i] = seen[i] = 0;
|
||||||
}
|
}
|
||||||
for (int i = 1; i <= clauses; i++) {
|
for (int i = 1; i <= clauses; i++) {
|
||||||
int l = clause[i].size();
|
int l = clause[i].size();
|
||||||
clause_delete[i] = 0;
|
clause_delete[i] = 0;
|
||||||
for (int j = 0; j < l; j++)
|
for (int j = 0; j < l; j++) {
|
||||||
if (clause[i][j] > 0) occurp[abs(clause[i][j])].push(i);
|
if (clause[i][j] > 0) occurp[abs(clause[i][j])].push(i);
|
||||||
else occurn[abs(clause[i][j])].push(i);
|
else occurn[abs(clause[i][j])].push(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (int i = 1; i <= vars; i++)
|
for (int i = 1; i <= vars; i++)
|
||||||
if (occurn[i].size() == 0 && occurp[i].size() == 0) clean[i] = 1;
|
if (occurn[i].size() == 0 && occurp[i].size() == 0) clean[i] = 1;
|
||||||
@ -204,12 +205,13 @@ bool preprocess::preprocess_resolution() {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
int count = 0;
|
||||||
void preprocess::update_var_clause_label() {
|
void preprocess::update_var_clause_label() {
|
||||||
|
++count;
|
||||||
int remain_var = 0;
|
int remain_var = 0;
|
||||||
for (int i = 1; i <= vars; i++) color[i] = 0;
|
for (int i = 1; i <= vars; i++) color[i] = 0;
|
||||||
for (int i = 1; i <= clauses; i++) {
|
for (int i = 1; i <= clauses; i++) {
|
||||||
if (clause_delete[i]) continue;
|
if (clause_delete[i]) {continue;}
|
||||||
int l = clause[i].size();
|
int l = clause[i].size();
|
||||||
for (int j = 0; j < l; j++) {
|
for (int j = 0; j < l; j++) {
|
||||||
if (color[abs(clause[i][j])] == 0) color[abs(clause[i][j])] = ++remain_var;
|
if (color[abs(clause[i][j])] == 0) color[abs(clause[i][j])] = ++remain_var;
|
||||||
@ -243,48 +245,49 @@ bool preprocess::preprocess_binary() {
|
|||||||
C = new HashMap();
|
C = new HashMap();
|
||||||
for (int i = 1; i <= clauses; i++) {
|
for (int i = 1; i <= clauses; i++) {
|
||||||
int l = clause[i].size();
|
int l = clause[i].size();
|
||||||
for (int j = 0; j < l; j++)
|
for (int j = 0; j < l; j++) {
|
||||||
clause[i][j] = tolit(clause[i][j]);
|
clause[i][j] = tolit(clause[i][j]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
nlit = (vars << 1) + 2;
|
nlit = (vars << 1) + 2;
|
||||||
for (int i = 1; i <= vars; i++) f[i] = i, val[i] = 1, color[i] = 0;
|
for (int i = 1; i <= vars; i++) f[i] = i, val[i] = 1, color[i] = 0;
|
||||||
for (int i = 1; i <= clauses; i++) clause_delete[i] = 0;
|
for (int i = 1; i <= clauses; i++) clause_delete[i] = 0;
|
||||||
int len = 0;
|
// int len = 0;
|
||||||
for (int i = 1; i <= clauses; i++) {
|
// for (int i = 1; i <= clauses; i++) {
|
||||||
if (clause[i].size() != 2) continue;
|
// if (clause[i].size() != 2) continue;
|
||||||
nxtc[++len] = i;
|
// nxtc[++len] = i;
|
||||||
ll id1 = mapv(clause[i][0], clause[i][1]),
|
// ll id1 = mapv(clause[i][0], clause[i][1]),
|
||||||
id2 = mapv(clause[i][1], clause[i][0]);
|
// id2 = mapv(clause[i][1], clause[i][0]);
|
||||||
C->insert(id1, i);
|
// C->insert(id1, i);
|
||||||
C->insert(id2, i);
|
// C->insert(id2, i);
|
||||||
}
|
// }
|
||||||
|
|
||||||
for (int k = 1; k <= len; k++) {
|
// for (int k = 1; k <= len; k++) {
|
||||||
int i = nxtc[k];
|
// int i = nxtc[k];
|
||||||
if (clause[i].size() != 2 || clause_delete[i]) continue;
|
// if (clause[i].size() != 2 || clause_delete[i]) continue;
|
||||||
int r = C->get(mapv(negative(clause[i][0]), negative(clause[i][1])), 0);
|
// int r = C->get(mapv(negative(clause[i][0]), negative(clause[i][1])), 0);
|
||||||
if (r) {
|
// if (r) {
|
||||||
clause_delete[r] = clause_delete[i] = 1;
|
// clause_delete[r] = clause_delete[i] = 1;
|
||||||
int u = toiidx(clause[i][0]), v = toiidx(clause[i][1]);
|
// int u = toiidx(clause[i][0]), v = toiidx(clause[i][1]);
|
||||||
int fa = find(u), fb = find(v);
|
// int fa = find(u), fb = find(v);
|
||||||
int sig = sign(clause[i][0]) * sign(clause[i][1]) * (-1);
|
// int sig = sign(clause[i][0]) * sign(clause[i][1]) * (-1);
|
||||||
//sig == 1 : a = b -1 : a = -b
|
// //sig == 1 : a = b -1 : a = -b
|
||||||
if (fa != fb) {
|
// if (fa != fb) {
|
||||||
if (fa < fb) {
|
// if (fa < fb) {
|
||||||
f[fa] = fb;
|
// f[fa] = fb;
|
||||||
val[fa] = sig / (val[u] * val[v]);
|
// val[fa] = sig / (val[u] * val[v]);
|
||||||
}
|
// }
|
||||||
else if (fa > fb) {
|
// else if (fa > fb) {
|
||||||
f[fb] = fa;
|
// f[fb] = fa;
|
||||||
val[fb] = sig / (val[u] * val[v]);
|
// val[fb] = sig / (val[u] * val[v]);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if (sig != val[u] * val[v])
|
// else if (sig != val[u] * val[v])
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
for (int i = 1; i <= vars; i++) find(i);
|
// for (int i = 1; i <= vars; i++) find(i);
|
||||||
|
|
||||||
for (int i = 1; i <= clauses; i++) {
|
for (int i = 1; i <= clauses; i++) {
|
||||||
if (clause_delete[i]) continue;
|
if (clause_delete[i]) continue;
|
||||||
@ -319,12 +322,12 @@ bool preprocess::preprocess_binary() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update_var_clause_label();
|
update_var_clause_label();
|
||||||
for (int i = 1; i <= orivars; i++) {
|
// for (int i = 1; i <= orivars; i++) {
|
||||||
if (mapval[i]) continue;
|
// if (mapval[i]) continue;
|
||||||
int v = mapto[i], fa = find(v);
|
// int v = mapto[i], fa = find(v);
|
||||||
if (color[fa]) mapto[i] = color[fa] * val[v];
|
// if (color[fa]) mapto[i] = color[fa] * val[v];
|
||||||
else {puts("why happened"); mapval[i] = val[v], mapto[i] = 0;}
|
// else {puts("why happened"); mapval[i] = val[v], mapto[i] = 0;}
|
||||||
}
|
// }
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
BIN
preprocess.o
BIN
preprocess.o
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user