use of com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory 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;
}
use of com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory 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);
}
use of com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory 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);
}
use of com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory 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);
}
use of com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory in project aic-expresso by aic-sri-international.
the class RandomConditionalExpressionGenerator method main.
public static void main(String[] args) {
Random random = new Random();
TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(new Random(), new DifferenceArithmeticTheory(true, true));
for (int numberOfVariables = 3; numberOfVariables != 5; numberOfVariables++) {
Map<String, Type> variableNamesAndTypes = map();
Type integerInterval = new IntegerInterval(0, 100);
for (int v = 0; v != numberOfVariables; v++) {
variableNamesAndTypes.put("v" + v, integerInterval);
}
theoryTestingSupport.setVariableNamesAndTypesForTesting(variableNamesAndTypes);
Context context = theoryTestingSupport.makeContextWithTestingInformation();
RandomConditionalExpressionGenerator generator = new RandomConditionalExpressionGenerator(theoryTestingSupport, 4, () -> makeSymbol(random.nextDouble()), context);
System.out.println();
System.out.println();
for (Map.Entry<String, Type> variableNameAndType : variableNamesAndTypes.entrySet()) {
Type type = variableNameAndType.getValue();
IntegerInterval interval = (IntegerInterval) type;
System.out.println("random " + variableNameAndType.getKey() + ": " + interval.getNonStrictLowerBound() + ".." + interval.getNonStrictUpperBound() + ";");
}
for (int i = 0; i != 5; i++) {
Expression output = generator.apply();
System.out.println(output + ";");
}
}
}
Aggregations