use of org.logicng.formulas.Literal in project LogicNG by logic-ng.
the class MUSGenerationTest method readDimacs.
private List<StandardProposition> readDimacs(final String fileName) throws IOException {
final List<StandardProposition> result = new ArrayList<>();
final BufferedReader reader = new BufferedReader(new FileReader(fileName));
while (reader.ready()) {
final String line = reader.readLine();
if (!line.startsWith("p") && !line.startsWith("c")) {
final String[] tokens = line.split("\\s");
final List<Literal> clause = new ArrayList<>();
for (int i = 0; i < tokens.length - 1; i++) {
final int lit = Integer.parseInt(tokens[i]);
clause.add(lit < 0 ? this.f.literal("v" + (-lit), false) : this.f.literal("v" + lit, true));
}
result.add(new StandardProposition(this.f.clause(clause)));
}
}
return result;
}
use of org.logicng.formulas.Literal in project LogicNG by logic-ng.
the class LiteralProfileTest method testBinaryOperator.
@Test
public void testBinaryOperator() 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 impl = p.parse("(a & (b | c) & (~b | ~c)) => (~c & a)");
final Formula equiv = p.parse("(a & (b | c) & (~b | ~c)) <=> (~c & a)");
assertThat(impl.apply(this.litProfile, true)).isEqualTo(expected);
assertThat(impl.apply(this.litProfile, false)).isEqualTo(expected);
assertThat(equiv.apply(this.litProfile, true)).isEqualTo(expected);
assertThat(equiv.apply(this.litProfile, false)).isEqualTo(expected);
}
use of org.logicng.formulas.Literal in project LogicNG by logic-ng.
the class LiteralProfileTest method testNAryOperator.
@Test
public void testNAryOperator() 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 testSmallExamples.
@Test
public void testSmallExamples() throws ParserException {
Formula formula = this.f.parse("(~(v17 | v18) | ~v1494 & (v17 | v18)) & ~v687 => v686");
SortedSet<Literal> pi = formula.apply(MinimumPrimeImplicantFunction.get());
assertThat(pi).hasSize(1);
isPrimeImplicant(formula, pi);
formula = this.f.parse("(~(v17 | v18) | ~v1494 & (v17 | v18)) & v687 => ~v686");
pi = formula.apply(MinimumPrimeImplicantFunction.get());
assertThat(pi).hasSize(1);
isPrimeImplicant(formula, pi);
formula = this.f.parse("v173 + v174 + v451 + v258 + v317 + v259 + v452 + v453 + v175 + v176 + v177 + v178 + v179 + v180 + v181 + v182 + v183 + v102 + v103 + v104 + v105 = 1");
pi = formula.apply(MinimumPrimeImplicantFunction.get());
assertThat(pi).hasSize(21);
isPrimeImplicant(formula, pi);
}
use of org.logicng.formulas.Literal in project LogicNG by logic-ng.
the class VariableProfileTest method testNAryOperator.
@Test
public void testNAryOperator() throws ParserException {
final Map<Literal, Integer> expected = new HashMap<>();
expected.put(this.f2.variable("a"), 1);
expected.put(this.f2.variable("b"), 2);
expected.put(this.f2.variable("c"), 3);
final PropositionalParser p = new PropositionalParser(this.f);
final Formula formula = p.parse("a & (b | c) & (~b | ~c) & c");
assertThat(formula.apply(this.varProfile, true)).isEqualTo(expected);
assertThat(formula.apply(this.varProfile, false)).isEqualTo(expected);
}
Aggregations