use of org.logicng.formulas.PBConstraint in project LogicNG by logic-ng.
the class EvaluatesToConstantPredicateTest method testPBCToTrue.
@Test
public void testPBCToTrue() {
final PBConstraint pbc01 = (PBConstraint) this.f.pbc(CType.EQ, 2, new Literal[] { this.A, this.B }, new int[] { 2, -4 });
assertThat(pbc01.holds(this.emptyToTrue)).isFalse();
assertThat(pbc01.holds(this.aToTrue)).isFalse();
assertThat(pbc01.holds(this.aNotBToTrue)).isTrue();
final PBConstraint pbc02 = (PBConstraint) this.f.pbc(CType.GT, 2, new Literal[] { this.B, this.C }, new int[] { 2, 1 });
assertThat(pbc02.holds(this.emptyToTrue)).isFalse();
assertThat(pbc02.holds(this.aToTrue)).isFalse();
assertThat(pbc02.holds(this.aNotBToTrue)).isFalse();
assertThat(this.PBC1.holds(this.emptyToTrue)).isFalse();
assertThat(this.PBC1.holds(this.aToTrue)).isFalse();
assertThat(this.PBC1.holds(this.aNotBToTrue)).isFalse();
assertThat(this.PBC2.holds(this.emptyToTrue)).isFalse();
assertThat(this.PBC2.holds(this.aToTrue)).isFalse();
assertThat(this.PBC2.holds(this.aNotBToTrue)).isFalse();
}
use of org.logicng.formulas.PBConstraint in project LogicNG by logic-ng.
the class EvaluatesToConstantPredicateTest method testPBCToFalse.
@Test
public void testPBCToFalse() {
final PBConstraint pbc01 = (PBConstraint) this.f.pbc(CType.EQ, 2, new Literal[] { this.A, this.B }, new int[] { 2, -4 });
assertThat(pbc01.holds(this.emptyToFalse)).isFalse();
assertThat(pbc01.holds(this.aToFalse)).isFalse();
assertThat(pbc01.holds(this.aNotBToFalse)).isFalse();
final PBConstraint pbc02 = (PBConstraint) this.f.pbc(CType.GT, 2, new Literal[] { this.B, this.C }, new int[] { 2, 1 });
assertThat(pbc02.holds(this.emptyToFalse)).isFalse();
assertThat(pbc02.holds(this.aToFalse)).isFalse();
assertThat(pbc02.holds(this.aNotBToFalse)).isTrue();
assertThat(this.PBC1.holds(this.emptyToFalse)).isFalse();
assertThat(this.PBC1.holds(this.aToFalse)).isFalse();
assertThat(this.PBC1.holds(this.aNotBToFalse)).isFalse();
assertThat(this.PBC2.holds(this.emptyToFalse)).isFalse();
assertThat(this.PBC2.holds(this.aToFalse)).isFalse();
assertThat(this.PBC2.holds(this.aNotBToFalse)).isFalse();
}
use of org.logicng.formulas.PBConstraint in project LogicNG by logic-ng.
the class FormulaRandomizerTest method testPbc.
@Test
public void testPbc() {
final FormulaRandomizer random = new FormulaRandomizer(this.f, FormulaRandomizerConfig.builder().seed(4242).weightPbcCoeffPositive(3).weightPbcCoeffNegative(1).weightPositiveLiteral(3).weightNegativeLiteral(1).weightPbcTypeLe(5).weightPbcTypeLt(4).weightPbcTypeGe(3).weightPbcTypeGt(2).weightPbcTypeEq(1).maximumCoefficientPbc(10).build());
int posCoeff = 0;
int negCoeff = 0;
int posLit = 0;
int negLit = 0;
int le = 0;
int lt = 0;
int ge = 0;
int gt = 0;
int eq = 0;
for (int i = 0; i < 500; i++) {
final Formula formula = random.pbc();
assertThat(formula).isInstanceOf(PBConstraint.class);
final PBConstraint pbc = (PBConstraint) formula;
int posSum = 0;
int negSum = 0;
for (final int coefficient : pbc.coefficients()) {
if (coefficient > 0) {
posCoeff++;
posSum += coefficient;
} else {
negCoeff++;
negSum += coefficient;
}
}
assertThat(pbc.numberOfOperands()).isLessThanOrEqualTo(10);
assertThat(pbc.rhs()).isStrictlyBetween(negSum - 1, posSum + 1);
for (final Literal literal : pbc.literals()) {
if (literal.phase()) {
posLit++;
} else {
negLit++;
}
}
switch(pbc.comparator()) {
case LE:
le++;
break;
case LT:
lt++;
break;
case GE:
ge++;
break;
case GT:
gt++;
break;
case EQ:
eq++;
break;
}
}
assertThat(posCoeff).isStrictlyBetween((int) (.8 * 3 * negCoeff), (int) (1.2 * 3 * negCoeff));
assertThat(posLit).isStrictlyBetween((int) (.8 * 3 * negLit), (int) (1.2 * 3 * negLit));
assertThat(le).isStrictlyBetween((int) (.7 * 5 / 4 * lt), (int) (1.3 * 5 / 4 * lt));
assertThat(lt).isStrictlyBetween((int) (.7 * 4 / 3 * ge), (int) (1.3 * 4 / 3 * ge));
assertThat(ge).isStrictlyBetween((int) (.7 * 3 / 2 * gt), (int) (1.3 * 3 / 2 * gt));
assertThat(gt).isStrictlyBetween((int) (.7 * 2 / 1 * eq), (int) (1.3 * 2 / 1 * eq));
}
use of org.logicng.formulas.PBConstraint in project LogicNG by logic-ng.
the class FormulaRandomizerTest method testMaximumOperandsPbc.
@Test
public void testMaximumOperandsPbc() {
final FormulaRandomizer random = new FormulaRandomizer(this.f, FormulaRandomizerConfig.builder().maximumOperandsPbc(10).seed(42).build());
for (int i = 0; i < 100; i++) {
final Formula formula = random.pbc();
assertThat(formula.type()).isEqualTo(FType.PBC);
final PBConstraint pbc = (PBConstraint) formula;
assertThat(pbc.literals().size()).isLessThanOrEqualTo(10);
}
}
use of org.logicng.formulas.PBConstraint in project LogicNG by logic-ng.
the class FormulaRandomizerTest method testAmo.
@Test
public void testAmo() {
final FormulaRandomizer random = new FormulaRandomizer(this.f, FormulaRandomizerConfig.builder().seed(4242).maximumCoefficientPbc(10).build());
for (int i = 0; i < 100; i++) {
final Formula formula = random.amo();
assertThat(formula).isInstanceOf(PBConstraint.class);
final PBConstraint amo = (PBConstraint) formula;
assertThat(amo.isCC()).isTrue();
assertThat(amo.rhs()).isEqualTo(1);
assertThat(amo.comparator()).isEqualTo(CType.LE);
}
}
Aggregations