private static bool CanEliminateClause(Clause clause, int variable, bool value) { if (clause.Literal1 != null && clause.Literal1.Index == variable && !clause.Literal1.Negation == value) return true; if (clause.Literal2 != null && clause.Literal2.Index == variable && !clause.Literal2.Negation == value) return true; return false; }
private IEnumerable<Clause> GetClauses(TextReader reader) { if (reader == null) throw new ArgumentNullException("reader"); var clauses = new List<Clause>(); reader.ReadLine(); while (true) { string row = reader.ReadLine(); if (row == null) { break; } var parts = row.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); var numbers = parts.Select(x => int.Parse(x, CultureInfo.InvariantCulture)).ToArray(); var number1 = numbers[0]; var number2 = numbers[1]; var literal1 = number1 < 0 ? new Literal(-number1).Negate() : new Literal(number1); var literal2 = number2 < 0 ? new Literal(-number2).Negate() : new Literal(number2); var clause = new Clause(literal1, literal2); clauses.Add(clause); } return clauses; }
private static bool IsSatisfied(Clause c, IList<bool> assignment) { return IsSatisfied(c.Literal1, assignment) || IsSatisfied(c.Literal2, assignment); }