Search in sources :

Example 31 with TheoryTestingSupport

use of com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.

the class LinearRealArithmeticTheoryTest method testSatisfiability.

@Test
public void testSatisfiability() {
    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("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < 3";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X <= 3";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X < 4";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4 and X != 3.2";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2";
    expected = parse("true");
    runSatisfiabilityTest(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("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.2";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 8";
    expected = parse("false");
    runSatisfiabilityTest(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("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7 and X = 8";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < Y";
    expected = parse("Y > 0");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X < Y + 1";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < Y - 4";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < 2 - Y";
    expected = parse("Y < 2");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > Y";
    expected = parse("Y < 4");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X > Y + 1";
    expected = parse("Y < 3");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y + 4";
    expected = parse("Y <= 0");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y + 2";
    expected = parse("Y <= 2");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X >= Y + 1";
    expected = parse("Y <= 3");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X <= 3";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4 and X != 3.2";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2";
    expected = parse("true");
    runSatisfiabilityTest(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("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.2";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.6";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 8";
    expected = parse("false");
    runSatisfiabilityTest(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("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7 and X = 8";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > Z and X >= Y";
    expected = parse("if Z < Y then Y <= 3.4 else Z < 3.4");
    runSatisfiabilityTest(variable, constraintString, 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) LinearRealArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory) Test(org.junit.Test)

Example 32 with TheoryTestingSupport

use of com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport 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 -1*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.sgdpllt.api.Context) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) LinearRealArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory) Test(org.junit.Test)

Example 33 with TheoryTestingSupport

use of com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.

the class ExpressionStepSolverToLiteralSplitterStepSolverAdapterTest method testDifferenceArithmeticTheoryWithPropagationOfAllLiteralsWhenBoundWithRandomDisjunctiveFormulas.

@Test
public void testDifferenceArithmeticTheoryWithPropagationOfAllLiteralsWhenBoundWithRandomDisjunctiveFormulas() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new DifferenceArithmeticTheory(true, true));
    extendTestingVaribles("K", theoryTestingSupport, "L", "M", "N", "O", "P");
    runRandomDisjunctiveFormulasTest(theoryTestingSupport);
}
Also used : TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) Test(org.junit.Test)

Example 34 with TheoryTestingSupport

use of com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.

the class ExpressionStepSolverToLiteralSplitterStepSolverAdapterTest method testCompoundTheoryWithoutDifferenceArithmeticWithRandomDisjunctiveFormulas.

@Test
public void testCompoundTheoryWithoutDifferenceArithmeticWithRandomDisjunctiveFormulas() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, true), new PropositionalTheory()));
    runRandomDisjunctiveFormulasTest(theoryTestingSupport);
}
Also used : EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) Test(org.junit.Test)

Example 35 with TheoryTestingSupport

use of com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.

the class ExpressionStepSolverToLiteralSplitterStepSolverAdapterTest method testEqualityTheoryWithPropagationOfAllLiteralsWhenBoundWithRandomDisjunctiveFormulas.

@Test
public void testEqualityTheoryWithPropagationOfAllLiteralsWhenBoundWithRandomDisjunctiveFormulas() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new EqualityTheory(true, true));
    extendTestingVaribles("X", theoryTestingSupport, "S", "T", "U", "V", "W");
    runRandomDisjunctiveFormulasTest(theoryTestingSupport);
}
Also used : EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) 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