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();
}
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);
}
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[")));
}
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")));
}
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")));
}
Aggregations