Search in sources :

Example 21 with Constraint

use of com.sri.ai.grinder.api.Constraint in project aic-expresso by aic-sri-international.

the class ValuesOfSingleVariableDifferenceArithmeticConstraintStepSolverTest method runTest.

private void runTest(Expression variable, String constraintString, Expression expected, Context context) {
    Constraint constraint = new SingleVariableDifferenceArithmeticConstraint(variable, true, context.getTheory());
    constraint = constraint.conjoin(parse(constraintString), context);
    ExpressionLiteralSplitterStepSolver stepSolver = new ValuesOfSingleVariableDifferenceArithmeticConstraintStepSolver((SingleVariableDifferenceArithmeticConstraint) constraint);
    Expression actual = stepSolver.solve(context);
    System.out.println("Variable " + variable + "\nhas possible values:\n" + actual + "\nsatisfying constraint:\n" + constraintString + "\n");
    assertEquals(expected, actual);
}
Also used : ValuesOfSingleVariableDifferenceArithmeticConstraintStepSolver(com.sri.ai.grinder.theory.differencearithmetic.ValuesOfSingleVariableDifferenceArithmeticConstraintStepSolver) SingleVariableDifferenceArithmeticConstraint(com.sri.ai.grinder.theory.differencearithmetic.SingleVariableDifferenceArithmeticConstraint) Constraint(com.sri.ai.grinder.api.Constraint) Expression(com.sri.ai.expresso.api.Expression) ExpressionLiteralSplitterStepSolver(com.sri.ai.grinder.api.ExpressionLiteralSplitterStepSolver) SingleVariableDifferenceArithmeticConstraint(com.sri.ai.grinder.theory.differencearithmetic.SingleVariableDifferenceArithmeticConstraint)

Example 22 with Constraint

use of com.sri.ai.grinder.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);
}
Also used : SingleVariableEqualityConstraint(com.sri.ai.grinder.theory.equality.SingleVariableEqualityConstraint) Context(com.sri.ai.grinder.api.Context) SingleVariableEqualityConstraint(com.sri.ai.grinder.theory.equality.SingleVariableEqualityConstraint) Constraint(com.sri.ai.grinder.api.Constraint) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) AbstractTheoryIncludingEqualityTest(com.sri.ai.test.grinder.theory.base.AbstractTheoryIncludingEqualityTest) Test(org.junit.Test)

Aggregations

Constraint (com.sri.ai.grinder.api.Constraint)22 Expression (com.sri.ai.expresso.api.Expression)16 SingleVariableConstraint (com.sri.ai.grinder.api.SingleVariableConstraint)15 Context (com.sri.ai.grinder.api.Context)11 IncompleteMultiVariableConstraint (com.sri.ai.grinder.core.constraint.IncompleteMultiVariableConstraint)10 QuantifiedExpression (com.sri.ai.expresso.api.QuantifiedExpression)9 AssociativeCommutativeGroup (com.sri.ai.grinder.group.AssociativeCommutativeGroup)9 LinkedHashSet (java.util.LinkedHashSet)9 Beta (com.google.common.annotations.Beta)8 Type (com.sri.ai.expresso.api.Type)8 TRUE (com.sri.ai.expresso.helper.Expressions.TRUE)8 ZERO (com.sri.ai.expresso.helper.Expressions.ZERO)8 Expressions.getVariablesBeingReferenced (com.sri.ai.expresso.helper.Expressions.getVariablesBeingReferenced)8 Expressions.makeSymbol (com.sri.ai.expresso.helper.Expressions.makeSymbol)8 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)8 SubExpressionsDepthFirstIterator (com.sri.ai.expresso.helper.SubExpressionsDepthFirstIterator)8 SingleQuantifierEliminationProblem (com.sri.ai.grinder.api.SingleQuantifierEliminationProblem)8 Theory (com.sri.ai.grinder.api.Theory)8 DefaultSingleQuantifierEliminationProblem (com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem)8 AssignmentMapsIterator (com.sri.ai.grinder.helper.AssignmentMapsIterator)8