use of org.logicng.transformations.cnf.CNFFactorization in project LogicNG by logic-ng.
the class ConnectedComponentsComputerTest method testFormulaSplit.
@Test
public void testFormulaSplit() throws IOException, ParserException {
final FormulaFactory f = new FormulaFactory();
f.putConfiguration(CCConfig.builder().amoEncoding(CCConfig.AMO_ENCODER.PURE).build());
final Formula parsed = FormulaReader.readPseudoBooleanFormula("src/test/resources/formulas/formula1.txt", f);
final List<Formula> formulas = new ArrayList<>();
final List<Formula> originalFormulas = new ArrayList<>();
for (final Formula formula : parsed) {
originalFormulas.add(formula);
if (formula instanceof PBConstraint) {
formulas.add(formula);
} else {
formulas.add(formula.transform(new CNFFactorization()));
}
}
final Graph<Variable> constraintGraph = ConstraintGraphGenerator.generateFromCnf(formulas);
final Set<Set<Node<Variable>>> ccs = ConnectedComponentsComputation.compute(constraintGraph);
final List<List<Formula>> split = ConnectedComponentsComputation.splitFormulasByComponent(originalFormulas, ccs);
assertThat(split).hasSize(4);
assertThat(split.get(0)).hasSize(1899);
assertThat(split.get(1)).hasSize(3);
assertThat(split.get(2)).hasSize(3);
assertThat(split.get(3)).hasSize(3);
}
use of org.logicng.transformations.cnf.CNFFactorization in project LogicNG by logic-ng.
the class ConstraintGraphGeneratorTest method testRealExample.
@Test
public void testRealExample() throws IOException, ParserException {
final FormulaFactory f = new FormulaFactory();
f.putConfiguration(CCConfig.builder().amoEncoding(CCConfig.AMO_ENCODER.PURE).build());
final Formula parsed = FormulaReader.readPseudoBooleanFormula("src/test/resources/formulas/formula1.txt", f);
final List<Formula> formulas = new ArrayList<>();
for (final Formula formula : parsed) {
if (formula instanceof PBConstraint) {
formulas.add(formula);
} else {
formulas.add(formula.transform(new CNFFactorization()));
}
}
final Graph<Variable> constraintGraph = ConstraintGraphGenerator.generateFromCnf(formulas);
final Set<Set<Node<Variable>>> ccs = ConnectedComponentsComputation.compute(constraintGraph);
assertThat(ccs).hasSize(4);
}
use of org.logicng.transformations.cnf.CNFFactorization in project LogicNG by logic-ng.
the class DnnfCompilerTest method testLargeFormula.
@Test
@LongRunningTag
public void testLargeFormula() throws IOException, ParserException {
final FormulaFactory f = new FormulaFactory();
f.putConfiguration(CCConfig.builder().amoEncoding(CCConfig.AMO_ENCODER.PURE).build());
final Formula parsed = FormulaReader.readPseudoBooleanFormula("src/test/resources/formulas/formula1.txt", f);
final DnnfFactory dnnfFactory = new DnnfFactory();
Dnnf dnnf = dnnfFactory.compile(parsed);
final BigInteger dnnfCount = dnnf.execute(DnnfModelCountFunction.get());
final List<Formula> formulas = new ArrayList<>();
final List<Formula> originalFormulas = new ArrayList<>();
for (final Formula formula : parsed) {
originalFormulas.add(formula);
if (formula instanceof PBConstraint) {
formulas.add(formula);
} else {
formulas.add(formula.transform(new CNFFactorization()));
}
}
final Graph<Variable> constraintGraph = ConstraintGraphGenerator.generateFromCnf(formulas);
final Set<Set<Node<Variable>>> ccs = ConnectedComponentsComputation.compute(constraintGraph);
final List<List<Formula>> split = ConnectedComponentsComputation.splitFormulasByComponent(originalFormulas, ccs);
BigInteger multipliedCount = BigInteger.ONE;
for (final List<Formula> component : split) {
dnnf = dnnfFactory.compile(f.and(component));
multipliedCount = multipliedCount.multiply(dnnf.execute(DnnfModelCountFunction.get()));
}
assertThat(dnnfCount).isEqualTo(multipliedCount);
}
Aggregations