Search in sources :

Example 21 with TheoryTestingSupport

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;
}
Also used : Type(com.sri.ai.expresso.api.Type) FunctionType(com.sri.ai.expresso.type.FunctionType) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) AbstractTheoryTestingSupport(com.sri.ai.grinder.sgdpllt.core.constraint.AbstractTheoryTestingSupport) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport)

Example 22 with TheoryTestingSupport

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;
}
Also used : EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) ArrayList(java.util.ArrayList) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory)

Example 23 with TheoryTestingSupport

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);
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) Expression(com.sri.ai.expresso.api.Expression) AbstractTheoryTestingSupport(com.sri.ai.grinder.sgdpllt.core.constraint.AbstractTheoryTestingSupport) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory)

Example 24 with TheoryTestingSupport

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);
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) Expression(com.sri.ai.expresso.api.Expression) Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) AbstractTheoryTestingSupport(com.sri.ai.grinder.sgdpllt.core.constraint.AbstractTheoryTestingSupport) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) AbstractTheoryTest(com.sri.ai.test.grinder.sgdpllt.theory.base.AbstractTheoryTest) Test(org.junit.Test)

Example 25 with TheoryTestingSupport

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);
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) Test(org.junit.Test)

Aggregations

TheoryTestingSupport (com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport)50 Test (org.junit.Test)42 Context (com.sri.ai.grinder.sgdpllt.api.Context)36 Expression (com.sri.ai.expresso.api.Expression)27 DifferenceArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory)23 EqualityTheory (com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory)21 PropositionalTheory (com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory)18 FunctionType (com.sri.ai.expresso.type.FunctionType)13 Type (com.sri.ai.expresso.api.Type)12 CompoundTheory (com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory)12 StepSolver (com.sri.ai.grinder.sgdpllt.api.StepSolver)10 UnificationStepSolver (com.sri.ai.grinder.sgdpllt.theory.base.UnificationStepSolver)10 AbstractTheoryTestingSupport (com.sri.ai.grinder.sgdpllt.core.constraint.AbstractTheoryTestingSupport)9 LinearRealArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory)9 Constraint (com.sri.ai.grinder.sgdpllt.api.Constraint)7 LinkedHashMap (java.util.LinkedHashMap)7 CompleteMultiVariableContext (com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext)6 Ignore (org.junit.Ignore)6 Categorical (com.sri.ai.expresso.type.Categorical)4 Theory (com.sri.ai.grinder.sgdpllt.api.Theory)4