use of org.logicng.formulas.Literal in project LogicNG by logic-ng.
the class LiteralProfileTest method testNot.
@Test
public void testNot() throws ParserException {
final Map<Literal, Integer> expected = new HashMap<>();
expected.put(this.f2.variable("a"), 2);
expected.put(this.f2.variable("b"), 1);
expected.put(this.f2.variable("c"), 1);
expected.put(this.f2.literal("b", false), 1);
expected.put(this.f2.literal("c", false), 2);
final PropositionalParser p = new PropositionalParser(this.f);
final Formula formula = p.parse("~(a & (b | c) & ((~b | ~c) => (~c & a)))");
assertThat(formula.apply(this.litProfile, true)).isEqualTo(expected);
assertThat(formula.apply(this.litProfile, false)).isEqualTo(expected);
}
use of org.logicng.formulas.Literal in project LogicNG by logic-ng.
the class MinimumPrimeImplicantTest method isPrimeImplicant.
private void isPrimeImplicant(final Formula formula, final SortedSet<Literal> pi) {
assertThat(this.f.implication(this.f.and(pi), formula).holds(new TautologyPredicate(this.f))).isTrue();
for (final Literal literal : pi) {
final TreeSet<Literal> newSet = new TreeSet<>(pi);
newSet.remove(literal);
if (!newSet.isEmpty()) {
assertThat(this.f.implication(this.f.and(newSet), formula).holds(new TautologyPredicate(this.f))).isFalse();
}
}
}
use of org.logicng.formulas.Literal in project LogicNG by logic-ng.
the class MinimumPrimeImplicantTest method testSimpleCases.
@Test
public void testSimpleCases() throws ParserException {
Formula formula = this.f.parse("a");
SortedSet<Literal> pi = formula.apply(MinimumPrimeImplicantFunction.get());
assertThat(pi).hasSize(1);
isPrimeImplicant(formula, pi);
formula = this.f.parse("a | b | c");
pi = formula.apply(MinimumPrimeImplicantFunction.get());
assertThat(pi).hasSize(1);
isPrimeImplicant(formula, pi);
formula = this.f.parse("a & b & (~a|~b)");
pi = formula.apply(MinimumPrimeImplicantFunction.get());
assertThat(pi).isNull();
formula = this.f.parse("a & b & c");
pi = formula.apply(MinimumPrimeImplicantFunction.get());
assertThat(pi).hasSize(3);
isPrimeImplicant(formula, pi);
formula = this.f.parse("a | b | ~c => e & d & f");
pi = formula.apply(MinimumPrimeImplicantFunction.get());
assertThat(pi).hasSize(3);
isPrimeImplicant(formula, pi);
formula = this.f.parse("a | b | ~c <=> e & d & f");
pi = formula.apply(MinimumPrimeImplicantFunction.get());
assertThat(pi).hasSize(4);
isPrimeImplicant(formula, pi);
formula = this.f.parse("(a | b | ~c <=> e & d & f) | (a | b | ~c => e & d & f)");
pi = formula.apply(MinimumPrimeImplicantFunction.get());
assertThat(pi).hasSize(3);
isPrimeImplicant(formula, pi);
formula = this.f.parse("(a | b | ~c <=> e & d & f) | (a | b | ~c => e & d & f) | (a & b)");
pi = formula.apply(MinimumPrimeImplicantFunction.get());
assertThat(pi).hasSize(2);
isPrimeImplicant(formula, pi);
formula = this.f.parse("(a | b | ~c <=> e & d & f) | (a | b | ~c => e & d & f) | (a & b) | (f => g)");
pi = formula.apply(MinimumPrimeImplicantFunction.get());
assertThat(pi).hasSize(1);
isPrimeImplicant(formula, pi);
}
use of org.logicng.formulas.Literal in project LogicNG by logic-ng.
the class QuineMcCluskeyTest method getTerm.
static Term getTerm(final String string, final FormulaFactory f) throws ParserException {
final List<Literal> literals = new ArrayList<>();
final PropositionalParser p = new PropositionalParser(f);
for (final String var : string.split(" ")) {
literals.add((Literal) p.parse(var));
}
return convertToTerm(literals, f);
}
use of org.logicng.formulas.Literal in project LogicNG by logic-ng.
the class SATTest method testLocalMinimum.
/**
* Tests if the given satisfying assignment is a local minimal model regarding the given relevant literals, i.e.
* there is no variable in the assignment, contained in the relevant literals, that can be flipped without
* resulting in an unsatisfying assignment.
* @param solver the solver with the loaded formulas
* @param assignment the satisfying assignment
* @param relevantLiterals the relevant literals.
*/
private void testLocalMinimum(final SATSolver solver, final Assignment assignment, final Collection<? extends Literal> relevantLiterals) {
final SortedSet<Literal> literals = assignment.literals();
for (final Literal lit : relevantLiterals) {
if (!literals.contains(lit)) {
final SortedSet<Literal> literalsWithFlip = new TreeSet<>(literals);
literalsWithFlip.remove(lit.negate());
literalsWithFlip.add(lit);
assertThat(solver.sat(literalsWithFlip)).isEqualTo(Tristate.FALSE);
}
}
}
Aggregations