Search in sources :

Example 61 with Context

use of com.sri.ai.grinder.api.Context in project aic-expresso by aic-sri-international.

the class BasicTest method debug.

private void debug(Expression problem) {
    Theory theory = new DifferenceArithmeticTheory(true, true);
    Context context = new TrueContext(theory);
    context = context.putGlobalObject(BRUTE_FORCE_CHECKING_OF_NON_CONDITIONAL_PROBLEMS, "Yes");
    Expression symbolicSolution = theory.evaluate(problem, context);
    println(symbolicSolution);
    BruteForceInterpreter bruteForceInterpreter = new BruteForceCommonInterpreter();
    Expression bruteForceSolution = bruteForceInterpreter.apply(problem, context);
    println(bruteForceSolution);
    Assert.assertEquals(bruteForceSolution, symbolicSolution);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) BruteForceCommonInterpreter(com.sri.ai.grinder.interpreter.BruteForceCommonInterpreter) Theory(com.sri.ai.grinder.api.Theory) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) Expression(com.sri.ai.expresso.api.Expression) BruteForceInterpreter(com.sri.ai.grinder.interpreter.BruteForceInterpreter) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) TrueContext(com.sri.ai.grinder.core.TrueContext)

Example 62 with Context

use of com.sri.ai.grinder.api.Context in project aic-expresso by aic-sri-international.

the class SummationOnDifferenceArithmeticAndPolynomialStepSolverTest method simpleBodyTest.

@Test
public void simpleBodyTest() {
    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");
    constraintString = "true";
    expected = parse("10");
    runTest(variable, constraintString, body, expected, context);
    constraintString = "I != 3";
    expected = parse("7");
    runTest(variable, constraintString, body, expected, context);
    constraintString = "I < 3";
    expected = parse("3");
    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.api.Context) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) Test(org.junit.Test)

Example 63 with Context

use of com.sri.ai.grinder.api.Context in project aic-expresso by aic-sri-international.

the class SummationOnDifferenceArithmeticAndPolynomialStepSolverTest method polynomialBodyTest.

@Test
public void polynomialBodyTest() {
    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 - I + 1");
    constraintString = "true";
    expected = parse("25");
    runTest(variable, constraintString, body, expected, context);
    constraintString = "I != 3";
    expected = parse("18");
    runTest(variable, constraintString, body, expected, context);
    constraintString = "I < 3";
    expected = parse("5");
    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.api.Context) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) Test(org.junit.Test)

Example 64 with Context

use of com.sri.ai.grinder.api.Context in project aic-expresso by aic-sri-international.

the class ValuesOfSingleVariableDifferenceArithmeticConstraintStepSolverTest method test.

@Test
public void test() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new DifferenceArithmeticTheory(true, true));
    theoryTestingSupport.setVariableNamesAndTypesForTesting(map("I", new IntegerInterval(0, 4), "J", new IntegerInterval(0, 4), "K", new IntegerInterval(0, 4)));
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    Expression variable;
    String constraintString;
    Expression expected;
    variable = parse("I");
    constraintString = "true";
    expected = parse("aboveAndUpTo(-1, 4)");
    runTest(variable, constraintString, expected, context);
    variable = parse("I");
    constraintString = "false";
    expected = parse("{}");
    runTest(variable, constraintString, expected, context);
    variable = parse("I");
    constraintString = "I < 3 and J > I";
    expected = parse("if 3 > J then if 0 < J then aboveAndUpTo(-1, J - 1) else {} else aboveAndUpTo(-1, 2)");
    runTest(variable, constraintString, expected, context);
    variable = parse("I");
    constraintString = "I < 3 and J > I and I != 2";
    expected = parse("if 3 > J then if 0 < J then aboveAndUpTo(-1, J - 1) else {} else aboveAndUpTo(-1, 2) - { 2 }");
    runTest(variable, constraintString, expected, context);
    variable = parse("I");
    constraintString = "I < 3 and J > I and I != 2 and I != K";
    expected = parse("if 3 > J then if 0 < J then if K + 1 <= J then aboveAndUpTo(-1, J - 1) - { K } else aboveAndUpTo(-1, J - 1) else {} else if K <= 2 then if 2 = K then aboveAndUpTo(-1, 2) - { K } else aboveAndUpTo(-1, 2) - { 2, K } else aboveAndUpTo(-1, 2) - { 2 }");
    runTest(variable, constraintString, expected, context);
}
Also used : Context(com.sri.ai.grinder.api.Context) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) Test(org.junit.Test)

Example 65 with Context

use of com.sri.ai.grinder.api.Context in project aic-expresso by aic-sri-international.

the class LinearRealArithmeticTheoryTest method testMeasure.

@Test
public void testMeasure() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new LinearRealArithmeticTheory(true, true));
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    Expression variable;
    String constraintString;
    Expression expected;
    variable = parse("X");
    constraintString = "true";
    expected = parse("4");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < 3";
    expected = parse("3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X <= 3";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X < 4";
    expected = parse("1");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4 and X != 3.2";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2 and X = 3.2";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.2";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < Y";
    expected = parse("if Y > 0 then Y else 0");
    runMeasureTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X < Y + 1";
    expected = parse("if Y > 3 then 4 else Y + 1");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < Y - 4";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < 2 - Y";
    expected = parse("if Y < 2 then -Y + 2 else 0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > Y";
    expected = parse("if Y < 4 then 4 - Y else 0");
    runMeasureTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X > Y + 1";
    expected = parse("if Y < 3 then 4 - (Y + 1) else 0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y + 4";
    expected = parse("if Y <= 0 then 4 - (Y + 4) else 0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y + 2";
    expected = parse("if Y <= 2 then 4 - (Y + 2) else 0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y";
    expected = parse("4 - Y");
    runMeasureTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X >= Y + 1";
    expected = parse("if Y <= 3 then 4 - (Y + 1) else 0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X <= 3";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4 and X != 3.2";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2 and X = 3.2";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.2";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.6";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > Z and X >= Y";
    expected = parse("if Z < Y then if Y <= 3.4 then 3.4 - Y else 0 else if Z < 3.4 then 3.4 - Z else 0");
    runMeasureTest(variable, constraintString, expected, context);
}
Also used : Context(com.sri.ai.grinder.api.Context) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) Test(org.junit.Test)

Aggregations

Context (com.sri.ai.grinder.api.Context)132 Expression (com.sri.ai.expresso.api.Expression)100 Test (org.junit.Test)50 TrueContext (com.sri.ai.grinder.core.TrueContext)40 TheoryTestingSupport (com.sri.ai.grinder.tester.TheoryTestingSupport)36 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)32 Type (com.sri.ai.expresso.api.Type)31 Theory (com.sri.ai.grinder.api.Theory)24 PropositionalTheory (com.sri.ai.grinder.theory.propositional.PropositionalTheory)23 IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)22 EqualityTheory (com.sri.ai.grinder.theory.equality.EqualityTheory)21 Set (java.util.Set)20 IntensionalSet (com.sri.ai.expresso.api.IntensionalSet)19 CompoundTheory (com.sri.ai.grinder.theory.compound.CompoundTheory)19 CompleteMultiVariableContext (com.sri.ai.grinder.core.constraint.CompleteMultiVariableContext)16 Map (java.util.Map)16 Beta (com.google.common.annotations.Beta)15 Constraint (com.sri.ai.grinder.api.Constraint)15 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)14 SingleVariableConstraint (com.sri.ai.grinder.api.SingleVariableConstraint)14