use of com.sri.ai.grinder.sgdpllt.api.Constraint in project aic-expresso by aic-sri-international.
the class AbstractEqualityConstraintTest method testSatisfiabilitySpecialCases.
@Test
public void testSatisfiabilitySpecialCases() {
String conjunction;
// looks unsatisfiable for type size 5, but it is not
conjunction = "X != a and X != b and X != c and X != Y and X != Z";
TheoryTestingSupport theoryTestingSupport = makeTheoryTestingSupport();
Constraint constraint = new SingleVariableEqualityConstraint(parse("X"), false, theoryTestingSupport.getTheory());
Context context = theoryTestingSupport.makeContextWithTestingInformation();
constraint = constraint.conjoinWithConjunctiveClause(parse(conjunction), context);
// satisfiable if either Y or Z is equal to a, b, c, or each other.
Assert.assertNotEquals(null, constraint);
}
use of com.sri.ai.grinder.sgdpllt.api.Constraint in project aic-expresso by aic-sri-international.
the class AbstractEqualityConstraintTest method runCompleteSatisfiabilityTest.
/**
* @param conjunction
* @param expected
*/
private void runCompleteSatisfiabilityTest(String conjunction, Expression expected, TheoryTestingSupport theoryTestingSupport) {
Context context = theoryTestingSupport.makeContextWithTestingInformation();
Constraint constraint = new CompleteMultiVariableContext(theoryTestingSupport.getTheory(), context);
for (Expression literal : And.getConjuncts(parse(conjunction))) {
constraint = constraint.conjoin(literal, context);
if (constraint.isContradiction()) {
break;
}
}
if (expected == null && !constraint.isContradiction()) {
throw new AssertionError("Expected null but was <" + constraint + ">");
} else if (expected != null && constraint.isContradiction()) {
throw new AssertionError("Expected <" + expected + "> but was null");
} else if (expected != null && !constraint.isContradiction() && !expected.equals(constraint)) {
Simplifier interpreter = (e, c) -> theoryTestingSupport.getTheory().evaluate(e, c);
// Simplifier interpreter = new Evaluator(theoryTestingSupport.getTheory());
Expression equivalenceDefinition = apply(EQUIVALENCE, expected, constraint);
Expression universallyQuantified = universallyQuantifyFreeVariables(equivalenceDefinition, context);
Expression equivalent = interpreter.apply(universallyQuantified, context);
if (equivalent.equals(FALSE)) {
throw new Error("Expected <" + expected + "> but got <" + constraint + ">, which is not equivalent either");
}
}
}
use of com.sri.ai.grinder.sgdpllt.api.Constraint in project aic-expresso by aic-sri-international.
the class LinearRealArithmeticTheoryTest method runQuantifierTest.
private void runQuantifierTest(Expression variable, String constraintString, String bodyString, Expression expected, String computedFunction, BinaryFunction<Constraint, Expression, ExpressionStepSolver> stepSolverMaker, Context context) {
Expression body = parse(bodyString);
Function<Constraint, ExpressionStepSolver> stepSolverMakerFromConstraint = c -> stepSolverMaker.apply(c, body);
runTest(variable, constraintString, expected, computedFunction, stepSolverMakerFromConstraint, context);
}
use of com.sri.ai.grinder.sgdpllt.api.Constraint in project aic-expresso by aic-sri-international.
the class LinearRealArithmeticTheoryTest method runTest.
/**
* @param variable
* @param constraintString
* @param expected
* @param computedFunction
* @param stepSolverMaker
* @param context
*/
private void runTest(Expression variable, String constraintString, Expression expected, String computedFunction, Function<Constraint, ExpressionStepSolver> stepSolverMaker, Context context) {
System.out.println("Solving " + computedFunction + " for " + variable + " in " + constraintString);
Constraint constraint = new SingleVariableLinearRealArithmeticConstraint(variable, true, context.getTheory());
constraint = constraint.conjoin(parse(constraintString), context);
ExpressionStepSolver stepSolver = stepSolverMaker.apply(constraint);
Expression actual = stepSolver.solve(context);
System.out.println("Variable " + variable + "\nhas " + computedFunction + ":\n" + actual + "\nfor constraint:\n" + constraintString + "\n");
assertEquals(expected, actual);
}
use of com.sri.ai.grinder.sgdpllt.api.Constraint in project aic-expresso by aic-sri-international.
the class SGDPLLTTester method testCompleteMultiVariableConstraints.
/**
* Given a theory and a number <code>n</code> of multi-variable constraint tests,
* generates <code>n</code> formulas in the theory
* and see if those detected as unsatisfiable by the corresponding solver
* are indeed unsatisfiable (checked by brute force).
* Throws an {@link Error} with the failure description if a test fails.
* @param theoryTestingSupport
* @param numberOfTests
* @param maxNumberOfLiterals
* @param outputCount
*/
public static void testCompleteMultiVariableConstraints(boolean testAgainstBruteForce, TheoryTestingSupport theoryTestingSupport, long numberOfTests, int maxNumberOfLiterals, boolean outputCount) {
Context context = theoryTestingSupport.makeContextWithTestingInformation();
NullaryFunction<Constraint> makeInitialConstraint = () -> new CompleteMultiVariableContext(theoryTestingSupport.getTheory(), context);
Function<Constraint, Expression> makeRandomLiteral = c -> theoryTestingSupport.makeRandomLiteral(context);
// CompleteMultiVariableContext is complete
TestRunner tester = SGDPLLTTester::testCompleteSatisfiability;
runTesterGivenOnSuccessiveConjunctionsOfLiterals("complete satisfiability", tester, numberOfTests, maxNumberOfLiterals, testAgainstBruteForce, theoryTestingSupport, makeInitialConstraint, makeRandomLiteral, outputCount, context);
}
Aggregations