use of com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.
the class CompoundTheoryTestingSupport method getTheoryTestingSupport.
private TheoryTestingSupport getTheoryTestingSupport(String variable) {
Type variableType = getTestingVariableType(variable);
Theory subConstraintTheory = getTheory().getTheory(parse(variable), variableType);
check(() -> subConstraintTheory != null, () -> "There is no sub-theory suitable for " + variable + ", which has type " + variableType);
TheoryTestingSupport result = getTheoryToTestingSupport().get(subConstraintTheory);
return result;
}
use of com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport in project aic-praise by aic-sri-international.
the class RandomConditionalPotentialExpressionGenerator method newTheoryTestingSupport.
private TheoryTestingSupport newTheoryTestingSupport(Random random, RandomHOGMv1Generator.TheoryTypePropositionalArgs[] propositionTheoryArgs, RandomHOGMv1Generator.TheoryTypeEqualityArgs[] equalityTheoryArgs, RandomHOGMv1Generator.TheoryTypeInequalityArgs[] inequalityTheoryArgs) {
List<Theory> theories = new ArrayList<>();
if (propositionTheoryArgs.length > 0) {
theories.add(new PropositionalTheory());
}
if (equalityTheoryArgs.length > 0) {
EqualityTheory equalityTheory;
if (inequalityTheoryArgs.length == 0) {
// first flag is 'true' because all equalities are atoms in the final theory; there is no need to check arguments type
equalityTheory = new EqualityTheory(true, true);
} else {
// 'false' because not all equalities are atoms in this final theory; need to check arguments type
equalityTheory = new EqualityTheory(false, true);
}
theories.add(equalityTheory);
}
if (inequalityTheoryArgs.length > 0) {
DifferenceArithmeticTheory differenceArithmeticTheory;
if (equalityTheoryArgs.length == 0) {
// first flag is 'true' because all equalities are atoms in the final theory; there is no need to check arguments type
differenceArithmeticTheory = new DifferenceArithmeticTheory(true, true);
} else {
// 'false' because not all equalities are atoms in this final theory; need to check arguments type
differenceArithmeticTheory = new DifferenceArithmeticTheory(false, true);
}
theories.add(differenceArithmeticTheory);
}
Theory finalTheory;
if (theories.size() > 1) {
finalTheory = new CompoundTheory(theories.toArray(new Theory[theories.size()]));
} else {
finalTheory = theories.get(0);
}
TheoryTestingSupport result = TheoryTestingSupport.make(random, finalTheory);
return result;
}
use of com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.
the class CompoundTheoryWithoutDifferenceArithmeticTest method runCompleteSatisfiabilityTest.
/**
* @param conjunction
* @param expected
*/
private void runCompleteSatisfiabilityTest(String conjunction, Expression expected, Map<String, Type> variableNamesAndTypesForTesting) {
TheoryTestingSupport equalityTheoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new EqualityTheory(true, true));
equalityTheoryTestingSupport.setVariableNamesAndTypesForTesting(variableNamesAndTypesForTesting);
TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), equalityTheoryTestingSupport, TheoryTestingSupport.make(makeRandom(), new PropositionalTheory()));
Context context = theoryTestingSupport.makeContextWithTestingInformation();
Constraint constraint = new CompleteMultiVariableContext(theoryTestingSupport.getTheory(), context);
for (Expression literal : And.getConjuncts(parse(conjunction))) {
constraint = constraint.conjoin(literal, context);
}
assertEquals(expected, constraint);
}
use of com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.
the class CompoundTheoryWithoutDifferenceArithmeticTest method basicTests.
@Test
public void basicTests() {
TheoryTestingSupport theoryTestingSupport = makeTheoryTestingSupport();
Expression condition = parse("X = Y and Y = X and P and not Q and P and X = a and X != b");
Context context = theoryTestingSupport.extendWithTestingInformation(new TrueContext(theoryTestingSupport.getTheory()));
Constraint constraint = new CompleteMultiVariableContext(theoryTestingSupport.getTheory(), context);
constraint = constraint.conjoin(condition, context);
Expression expected = parse("(Y = a) and not Q and P and (X = Y)");
assertEquals(expected, constraint);
}
use of com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.
the class SummationOnDifferenceArithmeticAndPolynomialStepSolverTest method polynomialBodyWithADifferentVariableTest.
@Test
public void polynomialBodyWithADifferentVariableTest() {
TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new DifferenceArithmeticTheory(true, true));
Context context = theoryTestingSupport.makeContextWithTestingInformation();
Expression variable;
String constraintString;
Expression body;
Expression expected;
variable = parse("I");
body = parse("I^2 - J + 1");
constraintString = "true";
expected = parse("-5*J + 35");
runTest(variable, constraintString, body, expected, context);
constraintString = "I != 3";
expected = parse("-4*J + 25");
runTest(variable, constraintString, body, expected, context);
constraintString = "I < 3";
expected = parse("-3*J + 8");
runTest(variable, constraintString, body, expected, context);
constraintString = "false";
expected = parse("0");
runTest(variable, constraintString, body, expected, context);
constraintString = "I > 3 and I < 3";
expected = parse("0");
runTest(variable, constraintString, body, expected, context);
constraintString = "I > 1 and I < 3 and I != 2";
expected = parse("0");
runTest(variable, constraintString, body, expected, context);
}
Aggregations