function DPLL(S) { if (S is empty) { return("satisfiable"); } while (there is some unit clause {p}, or some pure literal p) { if ({p} and {~p} are both in S) { //----The "model" isn't return("unsatisfiable"); } else { S = Simplify(S,p); //----Assign p TRUE in model } } if (S is empty) { return("satisfiable"); } pick some literal p from a shortest clause in S; if (DPLL(Simplify(S,p)) == "satisfiable") { //----Assign p TRUE in model return("satisfiable"); } else { return(DPLL(Simplify(S,~p)); //----Assign p FALSE in model } } function Simplify(S,p) { delete every clause in S containing p; delete every occurrence in S of ~p; return(S); }
Example | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
S1 = { ~n | ~t, m | q | n, l | ~m, l | ~q, ~l | ~p, r | p | n, ~r | ~l, t }
|
Example | |||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
S1 = { p | q | r, p | q | ~r, p | ~q | r, p | ~q | ~r, ~p | q | r, ~p | q | ~r, ~p | ~q | r }
|
function CDCL(S) { if (S is empty) { return("satisfiable"); } while (there is some unit clause {p}, or some pure literal p) { if ({p} and {~p} are both in S) { //----The "model" isn't if (there have been some picks) { new_clause = LearnClause(); backjump("unsatisfiable",new_clause,PlaceOfEarliestPick(new_clause)); } else { return("unsatisfiable"); } } else { S = Simplify(S,p); //----Assign p TRUE in model } } if (S is empty) { return("satisfiable"); } pick some literal p from a shortest clause in S; if (CDCL(Simplify(S,p)) == "satisfiable") { //----Assign p TRUE in model return("satisfiable"); } else { if (backjumped to here) { Add new_clause to S (as it was before the Simplify) return(CDCL(S)); } else { return(CDCL(Simplify(S,~p)); //----Assign p FALSE in model } } } function Simplify(S,p) { delete every clause in S containing p; delete every occurrence in S of ~p; return(S); } function LearnClause() { return(DisjunctionOf(NegatedPx())); }
Example | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
S1 = { p | q | r, p | q | ~r, p | ~q | r, p | ~q | ~r, ~p | q | r, ~p | q | ~r, ~p | ~q | r }
|