use of com.sri.ai.util.collect.PermutationIterator in project aic-expresso by aic-sri-international.
the class SatisfiabilityOfSingleVariableEqualityConstraintStepSolver method getPropagatedCNFBesidesPropagatedLiterals.
@Override
protected Iterable<Iterable<Expression>> getPropagatedCNFBesidesPropagatedLiterals(Context context) {
if (!variableIsBoundToUniquelyNamedConstant(context)) {
// the following logic only holds if the variable is not bound to a uniquely named constants,
// since that eliminates all disequalities to other uniquely named constants as redundant
long variableDomainSize = getConstraint().getVariableTypeSize(context);
if (variableDomainSize >= 0 && getConstraint().numberOfDisequals() >= variableDomainSize) {
// the following procedure can be very expensive but the condition above will rarely be satisfied
ArrayList<Expression> variableDisequals = getVariableDisequals(context);
Set<Expression> uniquelyNamedConstantDisequals = getUniquelyNamedConstantDisequals(context);
Expression typeExpression = GrinderUtil.getTypeExpression(getConstraint().getVariable(), context);
Type type = context.getType(typeExpression);
ArrayList<Expression> remainingUniquelyNamedConstants = arrayListFrom(new PredicateIterator<>(type.iterator(), c -> !uniquelyNamedConstantDisequals.contains(c)));
CartesianProductIterator<ArrayList<Expression>> subsetOfVariableDisequalsAndRemainingConstantsPermutationIterator = new CartesianProductIterator<ArrayList<Expression>>(() -> new SubsetsOfKIterator<Expression>(variableDisequals, remainingUniquelyNamedConstants.size()), () -> new PermutationIterator<Expression>(remainingUniquelyNamedConstants));
FunctionIterator<ArrayList<ArrayList<Expression>>, Iterable<Expression>> clausesIterator = FunctionIterator.make(subsetOfVariableDisequalsAndRemainingConstantsPermutationIterator, (ArrayList<ArrayList<Expression>> subsetAndPermutation) -> clauseNegatingAssignmentOfSubsetOfVariablesToParticularPermutationOfRemainingConstants(subsetAndPermutation));
Iterable<Iterable<Expression>> clauses = in(clausesIterator);
return clauses;
}
}
// otherwise, nothing is implied.
return list();
}
Aggregations