1
0
This repository has been archived on 2025-03-06. You can view files and clone it, but cannot push or open issues or pull requests.
Jip J. Dekker 35a3110598 Squashed 'software/chuffed/' content from commit 2ed0c015
git-subtree-dir: software/chuffed
git-subtree-split: 2ed0c01558d2a5c49c1ce57e048d32c17adf92d3
2021-06-18 09:36:35 +10:00

88 lines
1.9 KiB
C++

#include <chuffed/core/propagator.h>
void bool_rel(BoolView x, BoolRelType t, BoolView y, BoolView z) {
// NOT_SUPPORTED;
BoolView v[3] = {x, y, z};
int u = 0;
for (int l = 1; l <= 3; l++) {
for (int i = 0; i < 8; i++) {
if (bitcount<int>(i) != l) continue;
for (int j = 0; j < 8; j++) {
if (j & ~i) continue;
int flags = 0;
for (int k = 0; k < 8; k++) {
bool pass = true;
for (int m = 0; m < 3; m++) {
if ((i & (1<<m)) == 0) continue;
if (((k^j) & (1<<m)) == 0) pass = false;
}
if (pass) flags |= (1<<k);
}
if (t & flags) continue;
if ((flags & ~u) == 0) continue;
vec<Lit> ps;
for (int m = 0; m < 3; m++) {
if ((i & (1<<m)) == 0) continue;
bool p = (j>>m)&1;
if (l == 1) {
if (v[m].setValNotR(p)) if (!v[m].setVal(p)) TL_FAIL();
}
ps.push(v[m].getLit(p));
}
if (l >= 2) sat.addClause(ps);
u |= flags;
}
}
}
}
//-----
// \/ x_i \/ !y_i
void bool_clause(vec<BoolView>& x, vec<BoolView>& y) {
vec<Lit> ps;
for (int i = 0; i < x.size(); i++) ps.push(x[i]);
for (int i = 0; i < y.size(); i++) ps.push(~y[i]);
sat.addClause(ps);
}
// \/ x_i
void bool_clause(vec<BoolView>& x) {
vec<BoolView> b;
bool_clause(x, b);
}
//-----
// \/ x_i \/ !y_i <-> z
// n+1 clauses
void array_bool_or(vec<BoolView>& x, vec<BoolView>& y, BoolView z) {
for (int i = 0; i < x.size(); i++) sat.addClause(~x[i], z);
for (int i = 0; i < y.size(); i++) sat.addClause(y[i], z);
// Add clause !c \/ a_i \/ !b_i
vec<Lit> ps;
ps.push(~z);
for (int i = 0; i < x.size(); i++) ps.push(x[i]);
for (int i = 0; i < y.size(); i++) ps.push(~y[i]);
sat.addClause(ps);
}
void array_bool_or(vec<BoolView>& x, BoolView z) {
vec<BoolView> y;
array_bool_or(x, y, z);
}
// /\ x_i /\ !y_i <-> z
void array_bool_and(vec<BoolView>& x, vec<BoolView>& y, BoolView z) {
array_bool_or(y, x, ~z);
}
void array_bool_and(vec<BoolView>& x, BoolView z) {
vec<BoolView> y;
array_bool_and(x, y, z);
}