// // PRIVATE METHODS // private bool dpll(List <Sentence> clauses, List <Symbol> symbols, Model model) { // List<Sentence> clauseList = asList(clauses); List <Sentence> clauseList = clauses; // System.Console.WriteLine("clauses are " + clauses.ToString()); // if all clauses are true return true; if (areAllClausesTrue(model, clauseList)) { // System.Console.WriteLine(model.ToString()); return(true); } // if even one clause is false return false if (isEvenOneClauseFalse(model, clauseList)) { // System.Console.WriteLine(model.ToString()); return(false); } // System.Console.WriteLine("At least one clause is unknown"); // try to find a unit clause SymbolValuePair svp = findPureSymbolValuePair(clauseList, model, symbols); if (svp.notNull()) { Symbol[] copy = new Symbol[symbols.Count]; symbols.CopyTo(copy); List <Symbol> newSymbols = new List <Symbol>(copy); newSymbols.Remove(new Symbol(svp.symbol.getValue())); Model newModel = model.extend(new Symbol(svp.symbol.getValue()), svp.value); return(dpll(clauses, newSymbols, newModel)); } SymbolValuePair svp2 = findUnitClause(clauseList, model, symbols); if (svp2.notNull()) { Symbol[] copy = new Symbol[symbols.Count]; symbols.CopyTo(copy); List <Symbol> newSymbols = new List <Symbol>(copy); newSymbols.Remove(new Symbol(svp2.symbol.getValue())); Model newModel = model.extend(new Symbol(svp2.symbol.getValue()), svp2.value); return(dpll(clauses, newSymbols, newModel)); } Symbol symbol = (Symbol)symbols[0]; // System.Console.WriteLine("default behaviour selecting " + symbol); Symbol[] symbolsArr = new Symbol[symbols.Count]; symbols.CopyTo(symbolsArr); List <Symbol> newSymbols2 = symbolsArr.ToList <Symbol>(); newSymbols2.RemoveAt(0); return(dpll(clauses, newSymbols2, model.extend(symbol, true)) || dpll( clauses, newSymbols2, model.extend(symbol, false))); }
private bool Dpll(ISet <Sentence> clauses, IList <Symbol> symbols, Model model) { // IList<Sentence> clauseList = asList(clauses); IList <Sentence> clauseList = clauses.ToList(); // System.out.println("clauses are " + clauses.toString()); // if all clauses are true return true; if (this.AreAllClausesTrue(model, clauseList)) { // System.out.println(model.toString()); return(true); } // if even one clause is false return false if (this.IsEvenOneClauseFalse(model, clauseList)) { // System.out.println(model.toString()); return(false); } // System.out.println("At least one clause is unknown"); // try to find a unit clause SymbolValuePair svp = this.FindPureSymbolValuePair(clauseList, model); IList <Symbol> newSymbols; if (svp.NotNull()) { newSymbols = symbols.ToList(); newSymbols.Remove(new Symbol(svp.Symbol.Value)); Model newModel = model.Extend(new Symbol(svp.Symbol.Value), svp.Value); return(Dpll(clauses, newSymbols, newModel)); } SymbolValuePair svp2 = this.FindUnitClause(clauseList, model); if (svp2.NotNull()) { newSymbols = symbols.ToList(); newSymbols.Remove(new Symbol(svp2.Symbol.Value)); Model newModel = model.Extend(new Symbol(svp2.Symbol.Value), svp2.Value); return(Dpll(clauses, newSymbols, newModel)); } Symbol symbol = symbols[0]; // System.out.println("default behaviour selecting " + symbol); newSymbols = symbols.ToList(); newSymbols.RemoveAt(0); return(Dpll(clauses, newSymbols, model.Extend(symbol, true)) || Dpll( clauses, newSymbols, model.Extend(symbol, false))); }