My algo is as following
Code: Select all
procedure 2SAT()
{
For var = 1 to total of variables
if var found in Clauses then
val(var) = true
val(var') = false
if not contradiction with val(var') then
remove Clauses containing var
else
val(var) = false
val(var') = true
if contradiction with val(var) return false
remove Clauses containing var'
end if
if set of Clauses is empty return true;
end if
end for
return true
}
function contradiction(var_false)
{
for clause = 1 to total of Clauses
if var_false is found in clause
w = clause - var_false;
if (val(w) = false) return true
if (val(w) = none)
{
val(w) = true
val(w')= false
stack.push(w)
}
end if
undo the values of the var's found in stack
return false
}