Search in sources :

Example 1 with ConstraintSplitting

use of com.sri.ai.grinder.sgdpllt.core.constraint.ConstraintSplitting in project aic-expresso by aic-sri-international.

the class AbstractQuantifierEliminationStepSolver method resultIfLiteralContainsIndex.

protected Step resultIfLiteralContainsIndex(Expression literal, ExpressionLiteralSplitterStepSolver.Step bodyStep, Context contextForBody, Context context) {
    // if the splitter contains the index, we must split the quantifier:
    // Quant_x:C Body  --->   (Quant_{x:C and L} Body) op (Quant_{x:C and not L} Body)
    Step result;
    Expression solutionValue;
    // Here, we need to obtain the new index constraints, for the case in which the splitter literal is true and false,
    // to create the corresponding sub-problems, solve them, and combine them.
    // However, it is important to remember that bodyStep.getContextSplittingWhenSplitterIsLiteral()
    // contains the splitting of contextForBody with the splitter literal,
    // so the information on the new index constraints is already there in some form.
    // TODO: We current don't have a Constraint-generic way to extract it, but expect to do it in the future.
    // For now, we split the index constraint separately
    ConstraintSplitting indexConstraintSplitting = new ConstraintSplitting(literal, getIndexConstraint(), context);
    Constraint indexConstraintAndLiteral = indexConstraintSplitting.getConstraintAndLiteral();
    Constraint indexConstraintAndLiteralNegation = indexConstraintSplitting.getConstraintAndLiteralNegation();
    switch(indexConstraintSplitting.getResult()) {
        case CONSTRAINT_IS_CONTRADICTORY:
            solutionValue = null;
            break;
        case LITERAL_IS_UNDEFINED:
            // (**) IF DELETING THIS MARKER, DELETE ALL THE REFERENCES TO IT IN THIS FILE
            // This is where this step solver may return a Solution with literals in it:
            // solveSubProblem uses an exhaustive solve.
            solutionValue = solveSubProblems(makeSubProblem(true, bodyStep, indexConstraintAndLiteral), makeSubProblem(false, bodyStep, indexConstraintAndLiteralNegation), context);
            break;
        case LITERAL_IS_TRUE:
            solutionValue = solveSubProblem(makeSubProblem(true, bodyStep, indexConstraintAndLiteral), context);
            break;
        case LITERAL_IS_FALSE:
            solutionValue = solveSubProblem(makeSubProblem(false, bodyStep, indexConstraintAndLiteralNegation), context);
            break;
        default:
            throw new Error("Unrecognized result for " + ConstraintSplitting.class + ": " + indexConstraintSplitting.getResult());
    }
    if (solutionValue == null) {
        result = null;
    } else {
        result = new Solution(solutionValue);
    }
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint) Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) ConstraintSplitting(com.sri.ai.grinder.sgdpllt.core.constraint.ConstraintSplitting)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)1 Constraint (com.sri.ai.grinder.sgdpllt.api.Constraint)1 SingleVariableConstraint (com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint)1 ConstraintSplitting (com.sri.ai.grinder.sgdpllt.core.constraint.ConstraintSplitting)1