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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations