use of com.sri.ai.grinder.api.SingleVariableConstraint in project aic-expresso by aic-sri-international.
the class DefaultMultiVariableConstraint method conjoinWithLiteral.
@Override
public DefaultMultiVariableConstraint conjoinWithLiteral(Expression literal, Context context) {
DefaultMultiVariableConstraint result;
Expression variable = getSomeVariableFor(literal, context);
if (variable == null) {
// the literal has no variables.
Expression literalEvaluation = getTheory().simplify(literal, context);
if (literalEvaluation.equals(TRUE)) {
result = this;
} else {
result = makeContradiction();
}
} else {
SingleVariableConstraint singleVariableConstraint = getConstraintFor(variable, context);
SingleVariableConstraint newSingleVariableConstraint = singleVariableConstraint.conjoin(literal, context);
if (newSingleVariableConstraint.isContradiction()) {
result = makeContradiction();
} else if (newSingleVariableConstraint == singleVariableConstraint) {
result = this;
} else {
Map<Expression, SingleVariableConstraint> newFromVariableToItsConstraint = new LinkedHashMap<>(fromVariableToItsConstraint);
newFromVariableToItsConstraint.put(variable, newSingleVariableConstraint);
result = makeWithNewFromVariableToItsConstraint(newFromVariableToItsConstraint);
}
}
return result;
}
use of com.sri.ai.grinder.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.api.SingleVariableConstraint in project aic-expresso by aic-sri-international.
the class IncompleteMultiVariableConstraint method conjoinLiteralForVariable.
private IncompleteMultiVariableConstraint conjoinLiteralForVariable(Expression literal, Expression variable, Context context) {
IncompleteMultiVariableConstraint result;
SingleVariableConstraint singleVariableConstraint = getConstraintFor(variable, context);
SingleVariableConstraint newSingleVariableConstraint = singleVariableConstraint.conjoin(literal, context);
if (newSingleVariableConstraint.isContradiction()) {
result = makeContradiction();
} else if (newSingleVariableConstraint == singleVariableConstraint) {
result = this;
} else {
result = makeCopyWithNewSingleVariableConstraintForVariable(variable, newSingleVariableConstraint);
}
return result;
}
use of com.sri.ai.grinder.api.SingleVariableConstraint in project aic-expresso by aic-sri-international.
the class ConjoinedContext method makeNewConjoinedContextFromNewHeadAndNewTail.
private Context makeNewConjoinedContextFromNewHeadAndNewTail(Pair<SingleVariableConstraint, Context> newHeadAndNewTail, Context context) {
SingleVariableConstraint newHead = newHeadAndNewTail.first;
Context newTail = newHeadAndNewTail.second;
Context result;
if (newHead == head && newTail == tail) {
// in case nothing changed
result = this;
} else {
result = makeAndCheck(getTheory(), newHead, newTail, propertyCheckerStepSolverMaker, context);
}
return result;
}
use of com.sri.ai.grinder.api.SingleVariableConstraint in project aic-expresso by aic-sri-international.
the class AbstractSingleQuantifierEliminationStepSolver method makeSubProblemStepSolver.
protected ExpressionStepSolver makeSubProblemStepSolver(boolean splitterValue, ExpressionLiteralSplitterStepSolver.Step bodyStep, Constraint newIndexConstraint) {
SingleVariableConstraint newIndexConstraintAsSingleVariableConstraint = (SingleVariableConstraint) newIndexConstraint;
AbstractSingleQuantifierEliminationStepSolver result = makeWithNewIndexConstraint(newIndexConstraintAsSingleVariableConstraint);
result.initialBodyEvaluationStepSolver = bodyStep.getStepSolverForWhenSplitterIs(splitterValue);
return result;
}
Aggregations