use of com.sri.ai.grinder.api.Constraint in project aic-expresso by aic-sri-international.
the class IncompleteMultiVariableConstraint method conjoin.
@Override
public Constraint conjoin(Expression formula, Context context) {
myAssert(() -> context.isLiteral(formula) || formula instanceof Constraint, () -> this.getClass() + " currently only supports conjoining with literals and constraints, but received " + formula);
Constraint result;
if (formula instanceof Constraint) {
result = conjoinWithConjunctiveClause(formula, context);
} else {
result = conjoinWithLiteral(formula, context);
}
return result;
}
use of com.sri.ai.grinder.api.Constraint in project aic-expresso by aic-sri-international.
the class SGDPLLTTester method testModelCountingForSingleVariableConstraints.
/**
* Given a theory and a number <code>n</code> of single-variable constraint tests,
* generates <code>n</code> formulas in the theory
* and see if the model counting solver works (checked by brute force).
* Throws an {@link Error} with the failure description if a test fails.
* @param theoryTestingSupport
* @param numberOfTests
* @param maxNumberOfLiterals
* @param outputCount
*/
public static void testModelCountingForSingleVariableConstraints(boolean testAgainstBruteForce, TheoryTestingSupport theoryTestingSupport, long numberOfTests, int maxNumberOfLiterals, boolean outputCount) {
Context context = theoryTestingSupport.makeContextWithTestingInformation();
Expression variable = parse(theoryTestingSupport.pickTestingVariableAtRandom());
NullaryFunction<Constraint> makeInitialConstraint = () -> theoryTestingSupport.getTheory().makeSingleVariableConstraint(variable, context);
Function<Constraint, Expression> makeRandomLiteral = c -> theoryTestingSupport.makeRandomLiteralOn(((SingleVariableConstraint) c).getVariable().toString(), context);
TestRunner tester = (ls, c, tB, cT, p) -> runModelCountingTestForSingleVariableConstraint(variable, ls, c, tB, cT.getTheory(), p);
runTesterGivenOnSuccessiveConjunctionsOfLiterals("model counting", tester, numberOfTests, maxNumberOfLiterals, testAgainstBruteForce, theoryTestingSupport, makeInitialConstraint, makeRandomLiteral, outputCount, context);
}
use of com.sri.ai.grinder.api.Constraint in project aic-expresso by aic-sri-international.
the class SGDPLLTTester method addLiteralToConstraintAndTest.
private static Constraint addLiteralToConstraintAndTest(TestRunner tester, Expression literal, Constraint constraint, Collection<Expression> literals, boolean testAgainstBruteForce, TheoryTestingSupport theoryTestingSupport, Context context) throws Error {
output("Constraint is " + constraint);
output("Adding " + literal + " (literals added so far: " + join(literals, " and ") + ")");
literals.add(literal);
Constraint newConstraint = constraint.conjoin(literal, context);
output("New constraint is " + newConstraint);
tester.runOneTest(literals, newConstraint, testAgainstBruteForce, theoryTestingSupport, context);
return newConstraint;
}
use of com.sri.ai.grinder.api.Constraint 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()), 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.api.Constraint in project aic-expresso by aic-sri-international.
the class AbstractSingleVariableConstraintWithBinaryAtomsIncludingEquality method conjoinNonTrivialNormalizedEqualityToConstraintWithNonBoundVariable.
protected AbstractSingleVariableConstraintWithDependentNormalizedAtoms conjoinNonTrivialNormalizedEqualityToConstraintWithNonBoundVariable(boolean sign, Expression normalizedAtom, Context context) {
Constraint result;
// first, use super's implementation to detect inconsistencies
AbstractSingleVariableConstraintWithDependentNormalizedAtoms conjunctionWithSignAndNormalizedAtom = super.conjoinNonTrivialSignAndNormalizedAtom(sign, normalizedAtom, context);
if (conjunctionWithSignAndNormalizedAtom == null) {
result = makeContradiction();
} else {
Expression binding = normalizedAtom;
Expression valueVariableIsBoundTo = binding.get(1);
// create a fresh constraint with the binding only and external literals
result = makeSimplification(arrayList(binding), arrayList(), getExternalLiterals());
// convert all other normalized atoms to external literals with valueVariableIsBoundTo standing for constraint's variable
result = conjoinWithSignAndNormalizedAtomsOnValueVariableIsBoundTo(result, true, in(getPositiveNormalizedAtomsIncludingImplicitOnes(context)), valueVariableIsBoundTo, context);
if (result != null) {
result = conjoinWithSignAndNormalizedAtomsOnValueVariableIsBoundTo(result, false, in(getNegativeNormalizedAtomsIncludingImplicitOnes(context)), valueVariableIsBoundTo, context);
}
}
return (AbstractSingleVariableConstraintWithDependentNormalizedAtoms) result;
}
Aggregations