use of com.sri.ai.grinder.api.ExpressionLiteralSplitterStepSolver in project aic-expresso by aic-sri-international.
the class EvaluationTest method runTest.
private void runTest(String expressionString, Expression expected, Context context) {
Expression expression = parse(expressionString);
ExpressionLiteralSplitterStepSolver stepSolver = context.getTheory().makeEvaluatorStepSolver(expression);
System.out.println("Evaluating " + expression);
Expression solution = ContextDependentExpressionProblemSolver.staticSolve(stepSolver, context);
System.out.println(expression + " -----> " + solution + "\n");
assertEquals(expected, solution);
}
use of com.sri.ai.grinder.api.ExpressionLiteralSplitterStepSolver 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);
}
use of com.sri.ai.grinder.api.ExpressionLiteralSplitterStepSolver in project aic-expresso by aic-sri-international.
the class Switch method makeStepSolver.
@Override
public ExpressionLiteralSplitterStepSolver makeStepSolver(Expression expression) {
ExpressionLiteralSplitterStepSolver result;
T key = keyMaker.apply(expression);
Rewriter baseRewriter = fromKeyValueToRewriter.get(key);
if (baseRewriter != null) {
result = baseRewriter.makeStepSolver(expression);
} else {
result = new ConstantExpressionStepSolver(expression);
}
return result;
}
use of com.sri.ai.grinder.api.ExpressionLiteralSplitterStepSolver in project aic-expresso by aic-sri-international.
the class UnificationStepSolver method step.
@Override
public StepSolver.Step<Boolean> step(Context context) {
StepSolver.Step<Boolean> result = null;
if (precomputedResult != null) {
result = precomputedResult;
} else {
List<Integer> stepUnknownSolutionIndexesForUnificationEqualities = new ArrayList<>(unknownSolutionIndexesForUnificationEqualities);
List<Integer> stepFoundSolutions = new ArrayList<>();
for (Integer unknownSolutionIndex : stepUnknownSolutionIndexesForUnificationEqualities) {
Expression equality = unificationEqualitiesToTest.get(unknownSolutionIndex);
ExpressionLiteralSplitterStepSolver evaluatorStepSolver = context.getTheory().makeEvaluatorStepSolver(equality);
Expression equalityResult = evaluatorStepSolver.solve(context);
if (equalityResult.equals(TRUE)) {
stepFoundSolutions.add(unknownSolutionIndex);
} else if (equalityResult.equals(FALSE)) {
// Can't unify
result = new StepSolver.Solution<>(Boolean.FALSE);
break;
} else {
// Solution to unification equality still unknown
}
}
if (result == null) {
stepUnknownSolutionIndexesForUnificationEqualities.removeAll(stepFoundSolutions);
if (stepUnknownSolutionIndexesForUnificationEqualities.size() == 0) {
// No more unknown solutions and this means all of them were true if we got to here
result = new StepSolver.Solution<>(Boolean.TRUE);
} else {
// We still have unknown equality unifications, so will split on the first unknown
// of these equalities
Integer firstUnknownUnificationEqualityIndex = stepUnknownSolutionIndexesForUnificationEqualities.get(0);
Expression unknownUnificationEqualityToSplitOn = unificationEqualitiesToTest.get(firstUnknownUnificationEqualityIndex);
StepSolver<Boolean> ifTrue;
if (stepUnknownSolutionIndexesForUnificationEqualities.size() == 1) {
// If there is only 1 unknown unification equality remaining, then on the true branch
// we know the unification will result in true, so just return that known up front.
ifTrue = new ConstantStepSolver<>(Boolean.TRUE);
} else {
ifTrue = this.clone();
((UnificationStepSolver) ifTrue).unknownSolutionIndexesForUnificationEqualities = new ArrayList<>(stepUnknownSolutionIndexesForUnificationEqualities);
}
StepSolver<Boolean> ifFalse = new ConstantStepSolver<>(Boolean.FALSE);
ContextSplitting contextSplitting = null;
// information for the literal.
if (context.getTheory().isLiteralOrBooleanConstant(unknownUnificationEqualityToSplitOn, context)) {
contextSplitting = new ContextSplitting(unknownUnificationEqualityToSplitOn, context);
}
result = new StepSolver.ItDependsOn<>(unknownUnificationEqualityToSplitOn, contextSplitting, ifTrue, ifFalse);
}
}
}
return result;
}
use of com.sri.ai.grinder.api.ExpressionLiteralSplitterStepSolver in project aic-expresso by aic-sri-international.
the class FallbackTheory method getSingleQuantifierEliminatorStepSolver.
@Override
public ExpressionLiteralSplitterStepSolver getSingleQuantifierEliminatorStepSolver(SingleQuantifierEliminationProblem problem, Context context) {
ExpressionLiteralSplitterStepSolver baseQuantifierEliminatorStepSolver = getBase().getSingleQuantifierEliminatorStepSolver(problem, context);
ExpressionLiteralSplitterStepSolver result = makeFallbackQuantifierEliminationStepSolver(problem, baseQuantifierEliminatorStepSolver);
return result;
}
Aggregations