use of com.sri.ai.grinder.sgdpllt.api.Context in project aic-expresso by aic-sri-international.
the class MultiVariableContextWithCheckedProperty method conjoin.
@Override
public Context conjoin(Expression formula, Context context) {
Context result;
Pair<Boolean, Context> specializedResult = conjoinSpecializedForConstraintsIfApplicable(formula, context);
if (specializedResult.first) {
result = specializedResult.second;
} else {
// fall back to default implementation
result = Context.super.conjoin(formula, context);
}
return result;
}
use of com.sri.ai.grinder.sgdpllt.api.Context in project aic-expresso by aic-sri-international.
the class MultiVariableContextWithCheckedProperty method conjoinWithLiteral.
@Override
public Context conjoinWithLiteral(Expression literal, Context context) {
Context result;
if (literal.equals(TRUE)) {
result = this;
} else if (literal.equals(FALSE)) {
result = makeContradiction();
} else {
Collection<Expression> variablesInLiteral = getTheory().getVariablesIn(literal, context);
if (variablesInLiteral.isEmpty()) {
Expression literalSimplifiedToConstant = getTheory().simplify(literal, context);
if (literalSimplifiedToConstant == literal) {
throw new Error("Literal " + literal + " should have been simplified to a boolean constant, but was not. Sometimes this is caused by using a symbol as a variable, but which has not been declared as a variable in the context, or has been declared as a uniquely named constant in the Context (for example by constructing the Context with the default PrologConstantPredicate as a default predicate for recognizing constants, which recognizes all non-capitalized identifiers as such)");
}
result = conjoinWithLiteral(literalSimplifiedToConstant, context);
} else if (head != null) {
SingleVariableConstraint newHead;
Context newTail;
if (variablesInLiteral.contains(head.getVariable())) {
newHead = head.conjoin(literal, context);
newTail = tail;
} else {
newHead = head;
newTail = tail.conjoin(literal, context);
}
// up the chain so they are integrated and simplified in the corresponding single-variable constraints
if (!newHead.isContradiction()) {
for (Expression externalLiteral : newHead.getExternalLiterals()) {
if (!newTail.isContradiction()) {
newTail = newTail.conjoin(externalLiteral, context);
}
}
newHead = newHead.makeSimplificationWithoutExternalLiterals();
}
if (newHead == head && newTail == tail) {
// in case nothing changed
result = this;
} else {
result = makeAndCheck(getTheory(), newHead, newTail, contextDependentProblemStepSolverMaker, context);
}
} else {
Expression firstVariable = getFirstOrNull(variablesInLiteral);
SingleVariableConstraint newSingleVariableConstraint = getTheory().makeSingleVariableConstraint(firstVariable, getTheory(), context);
newSingleVariableConstraint = newSingleVariableConstraint.conjoin(literal, context);
result = makeAndCheck(getTheory(), newSingleVariableConstraint, this, contextDependentProblemStepSolverMaker, context);
}
}
return result;
}
use of com.sri.ai.grinder.sgdpllt.api.Context in project aic-expresso by aic-sri-international.
the class MultiVariableContextWithCheckedProperty method registerAdditionalSymbolsAndTypes.
@Override
public MultiVariableContextWithCheckedProperty registerAdditionalSymbolsAndTypes(Map<Expression, Expression> indicesAndTypes) {
MultiVariableContextWithCheckedProperty result = clone();
Context newTail = tail.registerAdditionalSymbolsAndTypes(indicesAndTypes);
result.tail = newTail;
return result;
}
use of com.sri.ai.grinder.sgdpllt.api.Context in project aic-expresso by aic-sri-international.
the class AbstractTheoryTestingSupport method extendWithTestingInformation.
@Override
public Context extendWithTestingInformation(Context context) {
// we only need to provide the variables types, and not the known constant types, because the latter will be extracted from the already registered types.
Map<String, String> mapFromSymbolNamesToTypeNames = new LinkedHashMap<String, String>();
for (Map.Entry<String, Type> symbolAndType : getVariableNamesAndTypesForTesting().entrySet()) {
mapFromSymbolNamesToTypeNames.put(symbolAndType.getKey(), symbolAndType.getValue().toString());
}
for (Map.Entry<String, Type> symbolAndType : getExtendedVariableNamesAndTypesForTesting().entrySet()) {
mapFromSymbolNamesToTypeNames.put(symbolAndType.getKey(), symbolAndType.getValue().toString());
}
Context result = (Context) GrinderUtil.extendRegistryWith(mapFromSymbolNamesToTypeNames, getTypesForTesting(), context);
return result;
}
use of com.sri.ai.grinder.sgdpllt.api.Context in project aic-expresso by aic-sri-international.
the class SGDPLLTTester method runGroupProblemSolvingTesterForSuccessiveConstraints.
private static void runGroupProblemSolvingTesterForSuccessiveConstraints(String problemName, TestRunner tester, boolean testAgainstBruteForce, AssociativeCommutativeGroup group, TheoryTestingSupport theoryTestingSupport, long numberOfTests, int maxNumberOfLiterals, boolean outputCount) throws Error {
Context context = theoryTestingSupport.makeContextWithTestingInformation();
NullaryFunction<Constraint> makeInitialConstraint = () -> theoryTestingSupport.getTheory().makeSingleVariableConstraint(parse(theoryTestingSupport.pickTestingVariableAtRandom()), theoryTestingSupport.getTheory(), context);
Function<Constraint, Expression> makeRandomLiteral = c -> theoryTestingSupport.makeRandomLiteralOn(((SingleVariableConstraint) c).getVariable().toString(), context);
runTesterGivenOnSuccessiveConjunctionsOfLiterals(problemName, tester, numberOfTests, maxNumberOfLiterals, testAgainstBruteForce, theoryTestingSupport, makeInitialConstraint, makeRandomLiteral, outputCount, context);
}
Aggregations