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