Skip to content

Commit af0ed60

Browse files
committedNov 26, 2019
Fixed bug where step was not being incremented after deciding on a new literal. Updated test scripts based on new output format
1 parent a8d9b39 commit af0ed60

File tree

13 files changed

+13
-11
lines changed

13 files changed

+13
-11
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
*.swp
22
*.o
3+
solver
4+
test
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

‎benchmarks/benchmarks/groups/group/bench1.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ w=0
99

1010
for i in `cat name1`; do
1111
python dpll.py ../../bench1/sat/$i > results 2>&1
12-
if (grep -q "[^N]SATISFIABLE" results) || (grep -q "^SATISFIABLE" results); then
12+
if (grep -q "[^n]sat" results) || (grep -q "^sat" results); then
1313
echo "$i Pass!"
1414
let "c+=1"
1515
let "s+=1"
@@ -24,7 +24,7 @@ done
2424

2525
for i in `cat name2`; do
2626
python dpll.py ../../bench1/unsat/$i > results 2>&1
27-
if grep -q "UNSATISFIABLE" results; then
27+
if grep -q "unsat" results; then
2828
echo "$i Pass!"
2929
let "c+=1"
3030
let "s+=1"

‎benchmarks/benchmarks/groups/group/bench2.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ w=0
99

1010
for i in `cat name3`; do
1111
python dpll.py ../../bench2/sat/$i > results 2>&1
12-
if (grep -q "[^N]SATISFIABLE" results) || (grep -q "^SATISFIABLE" results); then
12+
if (grep -q "[^n]sat" results) || (grep -q "^sat" results); then
1313
echo "$i Pass!"
1414
let "c+=1"
1515
let "s+=1"
@@ -24,7 +24,7 @@ done
2424

2525
for i in `cat name4`; do
2626
python dpll.py ../../bench2/unsat/$i > results 2>&1
27-
if grep -q "UNSATISFIABLE" results; then
27+
if grep -q "unsat" results; then
2828
echo "$i Pass!"
2929
let "c+=1"
3030
let "s+=1"

‎benchmarks/benchmarks/groups/group/bench3.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ w=0
99

1010
for i in `cat name5`; do
1111
python dpll.py ../../bench3/$i > results 2>&1
12-
if grep -q "UNSATISFIABLE" results; then
12+
if grep -q "unsat" results; then
1313
echo "$i Pass!"
1414
let "c+=1"
1515
let "s+=1"
-852 Bytes
Binary file not shown.

‎solver

-303 KB
Binary file not shown.

‎solver.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ VarAssignment::VarAssignment() : truthVal(false), level(-1), step(0), antecedent
88

99
VarAssignment::~VarAssignment(){}
1010

11-
void VarAssignment::setAssignment(bool tVal, int lvl, int stp, int ant){
11+
void VarAssignment::setAssignment(bool tVal, int lvl, int stp, unsigned int ant){
1212
this->truthVal = tVal;
1313
this->level = lvl;
1414
this->step = stp;
@@ -151,7 +151,8 @@ vector<int> CDCL(vector<Clause>& f, const unsigned int numVars, int& sat){
151151
int step = 0;
152152
int guessedLit = vsids.decide(assignment);
153153
bool truthVal = guessedLit > 0 ? true : false;
154-
setAssignment(assignment, abs(guessedLit), truthVal, level, step, -1, numAssigned);
154+
setAssignment(assignment, abs(guessedLit), truthVal, level, step, 0, numAssigned);
155+
++step;
155156

156157
queue<int> q(deque<int>{guessedLit});
157158
tuple<int, unsigned int, int> conflict; //(isConflict, clause number, conflicting variable) tuple
@@ -270,7 +271,7 @@ tuple<int, unsigned int, int> bcp(vector<Clause>& f, vector<VarAssignment>& a, q
270271
return make_tuple(0,0,0);
271272
}
272273

273-
void setAssignment(vector<VarAssignment>& a, int var, bool truthVal, int level, int step, int antecedent, unsigned int& numAssigned){
274+
void setAssignment(vector<VarAssignment>& a, int var, bool truthVal, int level, int step, unsigned int antecedent, unsigned int& numAssigned){
274275
a[var].setAssignment(truthVal, level, step, antecedent);
275276
numAssigned++;
276277
}
@@ -300,7 +301,6 @@ pair<int, Clause> analyzeConflict(vector<Clause>& f, vector<VarAssignment>& a, u
300301
maxStep = a[abs(newLits[i])].step;
301302
}
302303
}
303-
304304
unsigned int antecedent = a[lastAssignedVar].antecedent;
305305
resolve(newLits, f[antecedent].getLits(), conflictVar);
306306
}

‎solver.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class VarAssignment {
1616
public:
1717
VarAssignment();
1818
~VarAssignment();
19-
void setAssignment(bool tVal, int lvl, int stp, int ant);
19+
void setAssignment(bool tVal, int lvl, int stp, unsigned int ant);
2020
void unsetAssignment();
2121
bool truthVal;
2222
int level; //-1 if not assigned truthVal
@@ -67,7 +67,7 @@ map<int, unordered_set<unsigned int>> initWatchLists(vector<Clause>& f);
6767
int initialCheck(vector<Clause>& f, vector<VarAssignment>& a, map<int, unordered_set<unsigned int>> watchLists, int level, unsigned int& numAssigned);
6868
tuple<int, unsigned int, int> bcp(vector<Clause>& f, vector<VarAssignment>& a, queue<int> q, map<int, unordered_set<unsigned int>> watchLists,
6969
int& level, int& step, unsigned int& numAssigned);
70-
void setAssignment(vector<VarAssignment>& a, int var, bool truthVal, int level, int step, int antecedent, unsigned int& numAssigned);
70+
void setAssignment(vector<VarAssignment>& a, int var, bool truthVal, int level, int step, unsigned int antecedent, unsigned int& numAssigned);
7171
void unsetAssignment(vector<VarAssignment>& a, int var, unsigned int& numAssigned);
7272
pair<int, Clause> analyzeConflict(vector<Clause>& f, vector<VarAssignment>& a, unsigned int clauseNum, int conflictVar);
7373
unsigned int numLitsAtLvl(vector<int>& lits, int level, const vector<VarAssignment>& a);

‎test

-313 KB
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.