Skip to content

Commit 79aac1f

Browse files
committed
Modifying the method extendGivenModel in SatSolver.cc to accept multiple witnesses from WitnessIterator (CaDiCaL)
1 parent 74b6db8 commit 79aac1f

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

CadicalWrap.h

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -99,34 +99,12 @@ class SimpSolver {
9999
class ExtendIterator : public CaDiCaL::WitnessIterator {
100100
public:
101101
vec<uint32_t> elimCls;
102-
private:
103-
static void mkElimClause(vec<uint32_t>& elimclauses, Var v, const std::vector<int> &cl)
104-
{
105-
size_t first = elimclauses.size();
106-
int v_pos = -1;
107-
108-
// Copy clause to elimclauses-vector. Remember position where the
109-
// variable 'v' occurs:
110-
for (size_t i = 0; i < cl.size(); i++) {
111-
Lit lit = mkLit(abs(cl[i]) - 1, cl[i] < 0);
112-
elimclauses.push(toInt(lit));
113-
if (var(lit) == v) v_pos = int(i + first);
114-
}
115-
assert(v_pos != -1);
116-
117-
// Swap the first literal with the 'v' literal, so that the literal
118-
// containing 'v' will occur first in the clause:
119-
uint32_t tmp = elimclauses[v_pos];
120-
elimclauses[v_pos] = elimclauses[first];
121-
elimclauses[first] = tmp;
122-
123-
// Store the length of the clause last:
124-
elimclauses.push(cl.size());
125-
}
126102
public:
127103
bool witness (const std::vector<int> &cl, const std::vector<int> &witness, uint64_t ) {
128-
Lit l = mkLit(abs(witness[0]) - 1, witness[0] < 0);
129-
mkElimClause(elimCls,var(l), cl);
104+
for (const int w : witness) elimCls.push(toInt(mkLit(abs(w) - 1, w < 0)));
105+
elimCls.push(witness.size());
106+
for (const int c : cl) elimCls.push(toInt(mkLit(abs(c) - 1, c < 0)));
107+
elimCls.push(cl.size());
130108
return true;
131109
}
132110
} extendIt;

SatSolver.cc

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,41 @@ bool ExtSimpSolver::reduceProblem()
5757
return res;
5858
}
5959

60-
#if !defined(CRYPTOMS)
6160
void ExtSimpSolver::extendGivenModel(vec<lbool> &model)
6261
{
62+
#if defined(CADICAL)
63+
for (int i = model.size() - 1; i >= 0; i--)
64+
if (model[i] == l_Undef) model[i] = l_False;
65+
for (int j, i = elimClauses.size()-1; i > 0; i -= j) {
66+
Lit x;
67+
for (j = elimClauses[i--]; j > 0; j--, i--) { // clause processing
68+
x = Minisat::toLit(elimClauses[i]);
69+
if ((model[var(x)] ^ sign(x)) == l_True) { // the clause is satisfied
70+
i -= elimClauses[i-j] + 1; // skip witnesses
71+
goto next; }
72+
}
73+
for (j = elimClauses[i--]; j > 0; j--, i--) { // witnesses processing
74+
x = Minisat::toLit(elimClauses[i]);
75+
if ((model[var(x)] ^ sign(x)) != l_True) // x is not satisfied
76+
model[var(x)] = (model[var(x)] == l_True ? l_False : l_True); // x is flipped
77+
}
78+
next:;
79+
}
80+
#elif !defined(CRYPTOMS)
6381
for (int j, i = elimClauses.size()-1; i > 0; i -= j) {
6482
Lit x;
6583
for (j = elimClauses[i--]; j > 1; j--, i--) {
6684
x = Minisat::toLit(elimClauses[i]);
67-
if ((model[var(x)] ^ sign(x)) != l_False) goto next; // x is no false in the model
85+
if ((model[var(x)] ^ sign(x)) != l_False) goto next; // x is not false in the model
6886
}
6987
x = Minisat::toLit(elimClauses[i]);
7088
model[var(x)] = lbool(!sign(x));
7189
next:;
7290
}
73-
}
7491
#else
75-
void ExtSimpSolver::extendGivenModel(vec<lbool> &) {}
92+
(void)model;
7693
#endif
94+
}
7795

7896
void ExtSimpSolver::printVarsCls(bool encoding, const vec<Pair<weight_t, Minisat::vec<Lit>* > > *soft_cls, int soft_cnt)
7997
{

0 commit comments

Comments
 (0)