use of org.logicng.formulas.Or in project LogicNG by logic-ng.
the class FormulaFactoryImporter method apply.
@Override
public Formula apply(final Formula formula, final boolean cache) {
if (formula.factory() == this.newFormulaFactory) {
return formula;
}
switch(formula.type()) {
case TRUE:
return this.newFormulaFactory.verum();
case FALSE:
return this.newFormulaFactory.falsum();
case LITERAL:
final Literal literal = (Literal) formula;
return this.newFormulaFactory.literal(literal.name(), literal.phase());
case NOT:
final Not not = (Not) formula;
return this.newFormulaFactory.not(apply(not.operand(), cache));
case IMPL:
final Implication implication = (Implication) formula;
return this.newFormulaFactory.implication(apply(implication.left(), cache), apply(implication.right(), cache));
case EQUIV:
final Equivalence equivalence = (Equivalence) formula;
return this.newFormulaFactory.equivalence(apply(equivalence.left(), cache), apply(equivalence.right(), cache));
case OR:
final Or or = (Or) formula;
return this.newFormulaFactory.or(gatherAppliedOperands(or));
case AND:
final And and = (And) formula;
return this.newFormulaFactory.and(gatherAppliedOperands(and));
case PBC:
final PBConstraint pbc = (PBConstraint) formula;
final Literal[] literals = new Literal[pbc.operands().length];
for (int i = 0; i < pbc.operands().length; i++) {
literals[i] = (Literal) apply(pbc.operands()[i], cache);
}
return this.newFormulaFactory.pbc(pbc.comparator(), pbc.rhs(), literals, pbc.coefficients());
default:
throw new IllegalArgumentException("Unknown LogicNG formula type: " + formula.type());
}
}
use of org.logicng.formulas.Or in project LogicNG by logic-ng.
the class FormulaRandomizerTest method testMaximumOperandsOr.
@Test
public void testMaximumOperandsOr() {
final FormulaRandomizer random = new FormulaRandomizer(this.f, FormulaRandomizerConfig.builder().maximumOperandsOr(10).seed(42).build());
for (int i = 0; i < 100; i++) {
final Formula formula = random.or(1);
assertThat(formula.type()).isEqualTo(FType.OR);
final Or or = (Or) formula;
assertThat(or.numberOfOperands()).isLessThanOrEqualTo(10);
}
}
Aggregations