use of com.sri.ai.util.base.NullaryFunction in project aic-expresso by aic-sri-international.
the class SGDPLLTTester method testMultiVariableConstraints.
/**
* Given a theory and a number <code>n</code> of multi-variable constraint tests,
* generates <code>n</code> formulas in the theory
* and see if those detected as unsatisfiable by the corresponding solver
* are indeed unsatisfiable (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 testMultiVariableConstraints(boolean testAgainstBruteForce, TheoryTestingSupport theoryTestingSupport, long numberOfTests, int maxNumberOfLiterals, boolean outputCount) {
NullaryFunction<Constraint> makeInitialConstraint = () -> new DefaultMultiVariableConstraint(theoryTestingSupport.getTheory());
Context context = theoryTestingSupport.makeContextWithTestingInformation();
Function<Constraint, Expression> makeRandomLiteral = c -> theoryTestingSupport.makeRandomLiteral(context);
// DefaultMultiVariableConstraint is incomplete
TestRunner tester = SGDPLLTTester::testIncompleteSatisfiability;
runTesterGivenOnSuccessiveConjunctionsOfLiterals("incomplete satisfiability", tester, numberOfTests, maxNumberOfLiterals, testAgainstBruteForce, theoryTestingSupport, makeInitialConstraint, makeRandomLiteral, outputCount, context);
}
use of com.sri.ai.util.base.NullaryFunction in project aic-praise by aic-sri-international.
the class Polytopes method IntensionalConvexHullToListOfFactors.
public static List<TableFactor> IntensionalConvexHullToListOfFactors(IntensionalConvexHullOfFactors polytope) {
TableFactor factor = (TableFactor) polytope.getFactor();
List<TableVariable> indexes = mapIntoArrayList(polytope.getIndices(), v -> (TableVariable) v);
List<List<Integer>> listOfListOfValues = mapIntoList(indexes, v -> mapIntoList(v.getValues(), o -> (Integer) o));
List<NullaryFunction<Iterator<Integer>>> iteratorForListOfVariableValues = mapIntoList(listOfListOfValues, element -> () -> element.iterator());
Iterator<ArrayList<Integer>> cartesianProduct = new CartesianProductIterator<Integer>(iteratorForListOfVariableValues);
List<TableFactor> result = new LinkedList<>();
for (List<Integer> instantiations : in(cartesianProduct)) {
result.add(TableFactor.copyToSubTableFactor(factor, indexes, instantiations));
}
return result;
}
use of com.sri.ai.util.base.NullaryFunction 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.util.base.NullaryFunction in project aic-expresso by aic-sri-international.
the class DefaultExtensionalBound method boundProduct.
public static DefaultExtensionalBound boundProduct(Theory theory, Context context, Bound... listOfBounds) {
if (listOfBounds.length == 0) {
DefaultExtensionalBound singletonWithNumberOne = new DefaultExtensionalBound(parse("1"));
return singletonWithNumberOne;
}
ArrayList<NullaryFunction<Iterator<Expression>>> iteratorForBoundList = mapIntoArrayList(listOfBounds, bound -> () -> getElements(bound).iterator());
Iterator<ArrayList<Expression>> cartesianProduct = new CartesianProductIterator<Expression>(iteratorForBoundList);
if (!cartesianProduct.hasNext()) {
DefaultExtensionalBound singletonWithNumberOne = new DefaultExtensionalBound(parse("1"));
println("One of the bounds on the list is { }, which is an error");
return singletonWithNumberOne;
}
ArrayList<Expression> resultList = new ArrayList<>();
for (ArrayList<? extends Expression> element : in(cartesianProduct)) {
if (element == null || element.get(0) == null) {
return null;
}
Expression product = apply("*", element);
Expression evaluation = theory.evaluate(product, context);
resultList.add(evaluation);
}
DefaultExtensionalBound result = new DefaultExtensionalBound(resultList);
// Updating extreme points
result = updateExtremes(result, theory, context);
return result;
}
Aggregations