Search in sources :

Example 11 with IntegerInterval

use of com.sri.ai.expresso.type.IntegerInterval in project aic-expresso by aic-sri-international.

the class SingleVariableDifferenceArithmeticConstraint method getImplicitNegativeNormalizedAtomsIterator.

@Override
protected /**
	 * Returns iterator ranging over implicit normalized atoms representing variable bounds.
	 */
Iterator<Expression> getImplicitNegativeNormalizedAtomsIterator(Context context) {
    if (cachedImplicitNegativeNormalizedAtoms == null) {
        IntegerInterval interval = getType(context);
        Expression nonStrictLowerBound = interval.getNonStrictLowerBound();
        Expression nonStrictUpperBound = interval.getNonStrictUpperBound();
        cachedImplicitNegativeNormalizedAtoms = list();
        if (!nonStrictLowerBound.equals("unknown") && !nonStrictLowerBound.equals(UnaryMinus.make(INFINITY))) {
            cachedImplicitNegativeNormalizedAtoms.add(apply(LESS_THAN, getVariable(), nonStrictLowerBound));
        // this is the negation of variable >= nonStrictLowerBound. We need to use a negative normalized atom because applications of >= are not considered normalized atoms
        }
        if (!nonStrictUpperBound.equals("unknown") && !nonStrictUpperBound.equals(INFINITY)) {
            cachedImplicitNegativeNormalizedAtoms.add(apply(GREATER_THAN, getVariable(), nonStrictUpperBound));
        // this is the negation of variable <= nonStrictUpperBound. We need to use a negative normalized atom because applications of <= are not considered normalized atoms
        }
    }
    return cachedImplicitNegativeNormalizedAtoms.iterator();
}
Also used : Expression(com.sri.ai.expresso.api.Expression) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval)

Example 12 with IntegerInterval

use of com.sri.ai.expresso.type.IntegerInterval in project aic-expresso by aic-sri-international.

the class ExpressionStepSolverToLiteralSplitterStepSolverAdapterTest method testCompoundTheoryWithDifferenceArithmeticWithRandomDisjunctiveFormulas.

@Test
public void testCompoundTheoryWithDifferenceArithmeticWithRandomDisjunctiveFormulas() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, true), new PropositionalTheory()));
    // using different testing variables and types to test distribution of testing information
    // to sub constraint theories.
    Categorical booleanType = BOOLEAN_TYPE;
    Categorical dogsType = new Categorical("Dogs", 4, arrayList(parse("fido"), parse("rex")));
    IntegerInterval oneTwoThree = new IntegerInterval(1, 3);
    Map<String, Type> variablesAndTypes = map("F", booleanType, "G", booleanType, "R", dogsType, "S", dogsType, "T", oneTwoThree, "U", oneTwoThree);
    theoryTestingSupport.setVariableNamesAndTypesForTesting(variablesAndTypes);
    runRandomDisjunctiveFormulasTest(theoryTestingSupport);
}
Also used : EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) Type(com.sri.ai.expresso.api.Type) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) Categorical(com.sri.ai.expresso.type.Categorical) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) Test(org.junit.Test)

Example 13 with IntegerInterval

use of com.sri.ai.expresso.type.IntegerInterval in project aic-expresso by aic-sri-international.

the class GrinderUtilTest method testIsRealIntervalSubtypeOf.

@Test
public void testIsRealIntervalSubtypeOf() {
    RealInterval realInterval = new RealInterval("Real");
    Assert.assertFalse(isTypeSubtypeOf(realInterval, BOOLEAN_TYPE));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, INTEGER_TYPE));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, REAL_TYPE));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("Integer")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..4")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("Real")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[-0.5;4.5]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new FunctionType(realInterval)));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new FunctionType(realInterval, realInterval)));
    realInterval = new RealInterval("[0;4]");
    Assert.assertFalse(isTypeSubtypeOf(realInterval, INTEGER_TYPE));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..4")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("1..4")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..3")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, REAL_TYPE));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("Real")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("[0;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("]0;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;4[")));
    realInterval = new RealInterval("[-infinity;4]");
    Assert.assertFalse(isTypeSubtypeOf(realInterval, INTEGER_TYPE));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..4")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("1..4")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..3")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("-infinity..5")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, REAL_TYPE));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("Real")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("]0;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;4[")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("[-infinity;4]")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("]-infinity;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[-infinity;4[")));
    realInterval = new RealInterval("[0;infinity]");
    Assert.assertFalse(isTypeSubtypeOf(realInterval, INTEGER_TYPE));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..4")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("1..4")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..3")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("-1..infinity")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, REAL_TYPE));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("Real")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("]0;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;4[")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("[0;infinity]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("]0;infinity]")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("[0;infinity[")));
    realInterval = new RealInterval("[-infinity;infinity]");
    Assert.assertFalse(isTypeSubtypeOf(realInterval, INTEGER_TYPE));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..4")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("1..4")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..3")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, REAL_TYPE));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("Real")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("]0;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;4[")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[-infinity;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("]-infinity;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[-infinity;4[")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;infinity]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("]0;infinity]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;infinity[")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("[-infinity;infinity]")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("]-infinity;infinity]")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("[-infinity;infinity[")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("]-infinity;infinity[")));
}
Also used : IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) FunctionType(com.sri.ai.expresso.type.FunctionType) RealInterval(com.sri.ai.expresso.type.RealInterval) Test(org.junit.Test)

Example 14 with IntegerInterval

use of com.sri.ai.expresso.type.IntegerInterval in project aic-expresso by aic-sri-international.

the class AssignmentsSamplingIteratorTest method testSampleOverIntegerInterval.

@Test
public void testSampleOverIntegerInterval() {
    updateContextWithIndexAndType("I", new IntegerInterval(1, 10));
    // Sub-Interval
    Assert.assertEquals("{I=3}:{I=6}:{I=5}", join(":", newSamplingIterator("I", 3, "I > 2 and I < 8")));
    // Singleton
    Assert.assertEquals("{I=2}:{I=2}:{I=2}", join(":", newSamplingIterator("I", 3, "I = 2")));
    // Empty Set
    Assert.assertEquals("", join(":", newSamplingIterator("I", 3, "I = 11")));
    // Broken Interval
    Assert.assertEquals("{I=9}:{I=9}:{I=9}", join(":", newSamplingIterator("I", 3, "I != 1 and I != 3 and I !=4 and I != 5 and I != 6 and I !=7 and I != 8 and I != 10")));
}
Also used : IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) Test(org.junit.Test)

Example 15 with IntegerInterval

use of com.sri.ai.expresso.type.IntegerInterval in project aic-expresso by aic-sri-international.

the class AssignmentsSamplingIteratorTest method testSampleOverFunction.

@Test
public void testSampleOverFunction() {
    updateContextWithIndexAndType("f", new FunctionType(GrinderUtil.BOOLEAN_TYPE, new IntegerInterval(1, 10)));
    Assert.assertEquals("{f=1..10 -> Boolean}:{f=1..10 -> Boolean}:{f=1..10 -> Boolean}", join(":", newSamplingIterator("f", 3, "true")));
}
Also used : FunctionType(com.sri.ai.expresso.type.FunctionType) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) Test(org.junit.Test)

Aggregations

IntegerInterval (com.sri.ai.expresso.type.IntegerInterval)62 Expression (com.sri.ai.expresso.api.Expression)24 Before (org.junit.Before)20 FunctionType (com.sri.ai.expresso.type.FunctionType)18 Test (org.junit.Test)18 Type (com.sri.ai.expresso.api.Type)16 DifferenceArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory)15 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)15 RealInterval (com.sri.ai.expresso.type.RealInterval)14 TrueContext (com.sri.ai.grinder.core.TrueContext)14 IntegerExpressoType (com.sri.ai.expresso.type.IntegerExpressoType)13 CompoundTheory (com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory)13 Categorical (com.sri.ai.expresso.type.Categorical)12 TupleType (com.sri.ai.expresso.type.TupleType)12 TrueContext (com.sri.ai.grinder.sgdpllt.core.TrueContext)12 CompoundTheory (com.sri.ai.grinder.theory.compound.CompoundTheory)12 RealExpressoType (com.sri.ai.expresso.type.RealExpressoType)10 TupleTheory (com.sri.ai.grinder.theory.tuple.TupleTheory)10 TupleTheory (com.sri.ai.grinder.sgdpllt.theory.tuple.TupleTheory)8 Context (com.sri.ai.grinder.api.Context)7