Search in sources :

Example 11 with ContextSplitting

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

the class AbstractLinearStepSolver method step.

@Override
public Step<T> step(Context context) {
    Step<T> result;
    if (current != n) {
        Expression unsimplifiedLiteral = makeLiteral();
        Expression literal = context.getTheory().simplify(unsimplifiedLiteral, context);
        ContextSplitting split = new ContextSplitting(literal, context);
        switch(split.getResult()) {
            case CONSTRAINT_IS_CONTRADICTORY:
                result = null;
                break;
            case LITERAL_IS_TRUE:
                result = makeSubStepSolverWhenLiteralIsTrue().step(context);
                break;
            case LITERAL_IS_FALSE:
                result = makeSubStepSolverWhenLiteralIsFalse().step(context);
                break;
            case LITERAL_IS_UNDEFINED:
                result = new ItDependsOn<T>(literal, split, makeSubStepSolverWhenLiteralIsTrue(), makeSubStepSolverWhenLiteralIsFalse());
                break;
            default:
                throw new Error("Unexpected ConstraintSplitting result.");
        }
    } else {
        result = makeSolutionWhenAllElementsHaveBeenChecked();
    }
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) ContextSplitting(com.sri.ai.grinder.core.constraint.ContextSplitting)

Example 12 with ContextSplitting

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

the class ContextDependentExpressionProblemSolver method solveSplittedProblem.

private Expression solveSplittedProblem(ExpressionLiteralSplitterStepSolver.Step step) {
    explain("Problem depends on ", step);
    Expression splitter = step.getSplitter();
    ContextSplitting split = (ContextSplitting) step.getContextSplittingWhenSplitterIsLiteral();
    myAssert(() -> split.isUndefined(), () -> "Context splitting is supposed to be conditional but result contradicts that: " + split.getResult());
    Expression subSolution1 = solve(step.getStepSolverForWhenSplitterIs(true), split.getConstraintAndLiteral());
    Expression subSolution2 = solve(step.getStepSolverForWhenSplitterIs(false), split.getConstraintAndLiteralNegation());
    Expression result = IfThenElse.make(splitter, subSolution1, subSolution2, true);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) ContextSplitting(com.sri.ai.grinder.core.constraint.ContextSplitting)

Example 13 with ContextSplitting

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

the class AssociativeCommutativeGroupOperationApplicationStepSolver method makeConditionalStep.

private Step makeConditionalStep(Step operandStep, Context context) {
    ContextSplitting contextSplitting = operandStep.getContextSplittingWhenSplitterIsLiteral();
    ExpressionLiteralSplitterStepSolver sequelStepSolverForWhenSplitterIsTrue = makeSequelStepSolverGivenCurrentOperandSequelStepSolver(operandStep.getStepSolverForWhenSplitterIs(true));
    ExpressionLiteralSplitterStepSolver sequelStepSolverForWhenSplitterIsFalse = makeSequelStepSolverGivenCurrentOperandSequelStepSolver(operandStep.getStepSolverForWhenSplitterIs(false));
    Step conditionalStep = new ItDependsOn(contextSplitting.getLiteral(), contextSplitting, sequelStepSolverForWhenSplitterIsTrue, sequelStepSolverForWhenSplitterIsFalse);
    return conditionalStep;
}
Also used : ExpressionLiteralSplitterStepSolver(com.sri.ai.grinder.api.ExpressionLiteralSplitterStepSolver) ContextSplitting(com.sri.ai.grinder.core.constraint.ContextSplitting)

Example 14 with ContextSplitting

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

the class ContextSplittingTester method recursivelySplitContextForTotalTime.

private void recursivelySplitContextForTotalTime(Context contextToSplit, int variableNumber) {
    // BASE CASE
    if (variableNumber > numberOfVariables) {
        return;
    }
    int nextVariable = variableNumber + 1;
    // RECURSIVE SPLITTING
    for (int assignmentValue = 1; assignmentValue < cardinalityOfVariables; assignmentValue++) {
        Expression literalToSplitOn = variableAssignmentExpressions.getVariableAssignmentExpressions(variableNumber, assignmentValue);
        ContextSplitting splitter = new ContextSplitting(literalToSplitOn, contextToSplit);
        recursivelySplitContextForTotalTime(splitter.getContextAndLiteral(), nextVariable);
        contextToSplit = splitter.getContextAndLiteralNegation();
    }
    recursivelySplitContextForTotalTime(contextToSplit, nextVariable);
}
Also used : Expression(com.sri.ai.expresso.api.Expression) ContextSplitting(com.sri.ai.grinder.core.constraint.ContextSplitting)

Example 15 with ContextSplitting

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

the class ContextSplittingTester method recursivelySplitContext.

// / CONTEXT SPLITTING METHODS //////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////////
private void recursivelySplitContext(Context contextToSplit, int variableNumber) {
    // BASE CASE
    if (variableNumber > numberOfVariables) {
        contextSplittingResults.generatedContexts.add(contextToSplit);
        contextSplittingResults.literalsToSplitOn.add(null);
        contextSplittingResults.timeToSplitContext.add(0L);
        contextSplittingResults.finalContexts.add(contextToSplit);
        return;
    }
    int nextVariable = variableNumber + 1;
    // RECURSIVE SPLITTING
    for (int assignmentValue = 1; assignmentValue < cardinalityOfVariables; assignmentValue++) {
        contextSplittingResults.generatedContexts.add(contextToSplit);
        Expression literalToSplitOn = variableAssignmentExpressions.getVariableAssignmentExpressions(variableNumber, assignmentValue);
        contextSplittingResults.literalsToSplitOn.add(literalToSplitOn);
        ContextSplitting splitter = splitContextAndRecordTime(literalToSplitOn, contextToSplit);
        recursivelySplitContext(splitter.getContextAndLiteral(), nextVariable);
        contextToSplit = splitter.getContextAndLiteralNegation();
    }
    recursivelySplitContext(contextToSplit, nextVariable);
}
Also used : Expression(com.sri.ai.expresso.api.Expression) ContextSplitting(com.sri.ai.grinder.core.constraint.ContextSplitting)

Aggregations

ContextSplitting (com.sri.ai.grinder.core.constraint.ContextSplitting)20 Expression (com.sri.ai.expresso.api.Expression)16 ExpressionLiteralSplitterStepSolver (com.sri.ai.grinder.api.ExpressionLiteralSplitterStepSolver)6 Context (com.sri.ai.grinder.api.Context)5 TrueContext (com.sri.ai.grinder.core.TrueContext)4 Solution (com.sri.ai.grinder.api.ExpressionLiteralSplitterStepSolver.Solution)3 Test (org.junit.Test)3 Rewriter (com.sri.ai.grinder.rewriter.api.Rewriter)2 Constraint (com.sri.ai.grinder.api.Constraint)1 ItDependsOn (com.sri.ai.grinder.api.ExpressionLiteralSplitterStepSolver.ItDependsOn)1 ExpressionStepSolver (com.sri.ai.grinder.api.ExpressionStepSolver)1 SingleQuantifierEliminationProblem (com.sri.ai.grinder.api.SingleQuantifierEliminationProblem)1 StepSolver (com.sri.ai.grinder.api.StepSolver)1 Step (com.sri.ai.grinder.api.StepSolver.Step)1 AssignmentMapsIterator (com.sri.ai.grinder.helper.AssignmentMapsIterator)1 BruteForceCommonInterpreter (com.sri.ai.grinder.interpreter.BruteForceCommonInterpreter)1 RewriterFromStepMaker (com.sri.ai.grinder.rewriter.api.RewriterFromStepMaker)1 ConstantExpressionStepSolver (com.sri.ai.grinder.theory.base.ConstantExpressionStepSolver)1 ArrayList (java.util.ArrayList)1