Search in sources :

Example 1 with SingleVariableConstraint

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

the class CompoundTheory method makeSingleVariableConstraint.

@Override
public SingleVariableConstraint makeSingleVariableConstraint(Expression variable, Theory theory, Context context) {
    Theory theoryForVariable = getTheory(variable, context);
    SingleVariableConstraint result;
    if (theoryForVariable != null) {
        result = theoryForVariable.makeSingleVariableConstraint(variable, theory, context);
    } else {
        result = null;
    }
    return result;
}
Also used : SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) AbstractTheory(com.sri.ai.grinder.sgdpllt.core.constraint.AbstractTheory)

Example 2 with SingleVariableConstraint

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

the class MultiVariableContextWithCheckedProperty method conjoinSpecializedForConstraintsIfApplicable.

/**
	 * Returns a pair indicating whether specialized conjoin for constraints applies to this case and,
	 * if so, provides the result of this conjoining.
	 * @param formula
	 * @param context
	 * @return
	 */
private Pair<Boolean, Context> conjoinSpecializedForConstraintsIfApplicable(Expression formula, Context context) {
    Pair<Boolean, Context> result;
    if (formula instanceof SingleVariableConstraint) {
        SingleVariableConstraint formulaAsSingleVariableConstraint = (SingleVariableConstraint) formula;
        Expression variable = formulaAsSingleVariableConstraint.getVariable();
        // TODO: this forces expression representation to be generated, which can be expensive. Better write a method that checks it on the constraint representation itself
        boolean variableAlreadyConstrainedInThis = contains(this, variable);
        if (!variableAlreadyConstrainedInThis) {
            // if the variable is new to this constraint, we can simply tack on its constraint on it. 
            Context newContext = makeAndCheck(getTheory(), formulaAsSingleVariableConstraint, this, contextDependentProblemStepSolverMaker, context);
            result = pair(true, newContext);
        } else {
            // otherwise we won't be able to use the single variable constraint structure in any special way
            result = pair(false, null);
        }
    } else if (formula instanceof MultiVariableContextWithCheckedProperty) {
        MultiVariableContextWithCheckedProperty formulaAsMultiVariableConstraint = (MultiVariableContextWithCheckedProperty) formula;
        // if formula is itself a MultiVariableContextWithCheckedProperty,
        // we conjoin its two known parts individually.
        // Their own inner structure will also be efficiently exploited by these conjunctions.
        Context conjunction = this;
        if (formulaAsMultiVariableConstraint.tail != null) {
            conjunction = conjunction.conjoin(formulaAsMultiVariableConstraint.tail, context);
        }
        if (formulaAsMultiVariableConstraint.head != null) {
            conjunction = conjunction.conjoin(formulaAsMultiVariableConstraint.head, context);
        }
        result = pair(true, conjunction);
    } else {
        // the formula does not have a recognizable structure we can exploit
        result = pair(false, null);
    }
    return result;
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint) Expression(com.sri.ai.expresso.api.Expression)

Example 3 with SingleVariableConstraint

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

the class SGDPLLTTester method runGroupProblemSolvingTesterOnEmptyConstraint.

/**
	 * Same as {@link #runGroupProblemSolvingTesterForSuccessiveConstraints(String, TestRunner, boolean, AssociativeCommutativeGroup, TheoryTestingSupport, long, int, boolean)},
	 * but running the tester on a single, empty constraint.
	 * @param problemName
	 * @param tester
	 * @param testAgainstBruteForce
	 * @param group
	 * @param theoryTestingSupport
	 * @param numberOfTests
	 * @param outputCount
	 * @throws Error
	 */
private static void runGroupProblemSolvingTesterOnEmptyConstraint(String problemName, TestRunner tester, boolean testAgainstBruteForce, AssociativeCommutativeGroup group, TheoryTestingSupport theoryTestingSupport, long numberOfTests, boolean outputCount) throws Error {
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    SingleVariableConstraint emptyConstraint = theoryTestingSupport.getTheory().makeSingleVariableConstraint(parse(theoryTestingSupport.pickTestingVariableAtRandom()), theoryTestingSupport.getTheory(), context);
    for (int i = 1; i != numberOfTests + 1; i++) {
        tester.runOneTest(list(), emptyConstraint, testAgainstBruteForce, theoryTestingSupport, context);
        indicateCompletionOfTest(outputCount, problemName, i, testAgainstBruteForce, theoryTestingSupport);
    }
}
Also used : CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) Context(com.sri.ai.grinder.sgdpllt.api.Context) SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint) Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) DefaultMultiVariableConstraint(com.sri.ai.grinder.sgdpllt.core.constraint.DefaultMultiVariableConstraint) SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint)

Example 4 with SingleVariableConstraint

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

the class SGDPLLTTester method runGroupProblemSolvingTestForSingleVariableConstraint.

private static void runGroupProblemSolvingTestForSingleVariableConstraint(Constraint constraint, AssociativeCommutativeGroup group, boolean testAgainstBruteForce, TheoryTestingSupport theoryTestingSupport, Collection<Expression> literals, int bodyDepth, Context context) {
    SingleVariableConstraint singleVariableConstraint = (SingleVariableConstraint) constraint;
    Expression index = singleVariableConstraint.getVariable();
    runGroupProblemSolvingTestGivenConstraintOnRandomProblem(list(index), constraint, group, testAgainstBruteForce, theoryTestingSupport, bodyDepth, context);
}
Also used : SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint) Expression(com.sri.ai.expresso.api.Expression) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression)

Example 5 with SingleVariableConstraint

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

the class AbstractQuantifierEliminationStepSolver method makeSubProblem.

protected AbstractQuantifierEliminationStepSolver makeSubProblem(boolean valueForLiteral, ExpressionLiteralSplitterStepSolver.Step bodyStep, Constraint newIndexConstraint) {
    SingleVariableConstraint newIndexConstraintAsSingleVariableConstraint = (SingleVariableConstraint) newIndexConstraint;
    AbstractQuantifierEliminationStepSolver result = makeWithNewIndexConstraint(newIndexConstraintAsSingleVariableConstraint);
    result.initialBodyEvaluationStepSolver = valueForLiteral ? bodyStep.getStepSolverForWhenSplitterIsTrue() : bodyStep.getStepSolverForWhenSplitterIsFalse();
    result.initialContextForBody = valueForLiteral ? bodyStep.getContextSplittingWhenSplitterIsLiteral().getConstraintAndLiteral() : bodyStep.getContextSplittingWhenSplitterIsLiteral().getConstraintAndLiteralNegation();
    return result;
}
Also used : SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint)

Aggregations

SingleVariableConstraint (com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint)14 Expression (com.sri.ai.expresso.api.Expression)11 Context (com.sri.ai.grinder.sgdpllt.api.Context)8 Theory (com.sri.ai.grinder.sgdpllt.api.Theory)6 QuantifiedExpression (com.sri.ai.expresso.api.QuantifiedExpression)5 Type (com.sri.ai.expresso.api.Type)5 Constraint (com.sri.ai.grinder.sgdpllt.api.Constraint)5 CompleteMultiVariableContext (com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext)5 DefaultMultiVariableConstraint (com.sri.ai.grinder.sgdpllt.core.constraint.DefaultMultiVariableConstraint)5 Collection (java.util.Collection)5 Map (java.util.Map)5 Beta (com.google.common.annotations.Beta)4 TRUE (com.sri.ai.expresso.helper.Expressions.TRUE)4 ZERO (com.sri.ai.expresso.helper.Expressions.ZERO)4 Expressions.getVariableReferences (com.sri.ai.expresso.helper.Expressions.getVariableReferences)4 Expressions.makeSymbol (com.sri.ai.expresso.helper.Expressions.makeSymbol)4 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)4 SubExpressionsDepthFirstIterator (com.sri.ai.expresso.helper.SubExpressionsDepthFirstIterator)4 AssignmentsIterator (com.sri.ai.grinder.helper.AssignmentsIterator)4 GrinderUtil (com.sri.ai.grinder.helper.GrinderUtil)4