use of com.sri.ai.grinder.sgdpllt.core.constraint.AbstractSingleVariableConstraint in project aic-expresso by aic-sri-international.
the class AbstractSingleVariableNumericConstraintFeasibilityRegionStepSolver method makeUpperBoundsAndStrictness.
/**
* A method setting {@link #upperBoundsIncludingImplicitOnes} and {@link #fromUpperBoundsIncludingImplicitOnesToStrictness}
* from constraint and variable's type.
* @param context
*/
protected void makeUpperBoundsAndStrictness(Context context) {
AbstractSingleVariableConstraint abstractSingleVariableConstraint = (AbstractSingleVariableConstraint) constraint;
FunctionIterator<Expression, Pair<Expression, Boolean>> upperBoundsFromPositiveNormalizedAtomsIterator = functionIterator(predicateIterator(abstractSingleVariableConstraint.getPositiveNormalizedAtoms(), e -> e.hasFunctor(LESS_THAN)), // strict
e -> processExplicitUpperBoundAndStrictnessPair(e.get(1), true, context));
FunctionIterator<Expression, Pair<Expression, Boolean>> upperBoundsFromNegativeNormalizedAtomsIterator = functionIterator(predicateIterator(abstractSingleVariableConstraint.getNegativeNormalizedAtoms(), // not (X > Y) <=> X <= Y, so Y is a non-strict upper bound
e -> e.hasFunctor(GREATER_THAN)), // non-strict
e -> processExplicitUpperBoundAndStrictnessPair(e.get(1), false, context));
Pair<Expression, Boolean> typeUpperBound = getTypeUpperBoundAndStrictness(context);
Iterator<Pair<Expression, Boolean>> upperBoundsAndStrictnessIterator = new NestedIterator<>(upperBoundsFromPositiveNormalizedAtomsIterator, upperBoundsFromNegativeNormalizedAtomsIterator, typeUpperBound);
upperBoundsIncludingImplicitOnes = arrayList();
fromUpperBoundsIncludingImplicitOnesToStrictness = map();
for (Pair<Expression, Boolean> boundAndStrictness : in(upperBoundsAndStrictnessIterator)) {
Expression bound = boundAndStrictness.first;
upperBoundsIncludingImplicitOnes.add(bound);
Boolean strictness = boundAndStrictness.second;
Boolean previousStrictness = fromUpperBoundsIncludingImplicitOnesToStrictness.get(bound);
if (previousStrictness == null || (!previousStrictness && strictness)) {
// if no strictness information so far, store current one; otherwise, only need to change it if previous occurrences were non-strict and this one is strict
fromUpperBoundsIncludingImplicitOnesToStrictness.put(bound, strictness);
}
}
}
use of com.sri.ai.grinder.sgdpllt.core.constraint.AbstractSingleVariableConstraint in project aic-expresso by aic-sri-international.
the class AbstractSingleVariableNumericConstraintFeasibilityRegionStepSolver method getDisequals.
protected ArrayList<Expression> getDisequals() {
if (disequals == null) {
AbstractSingleVariableConstraint abstractSingleVariableConstraint = (AbstractSingleVariableConstraint) constraint;
Iterator<Expression> disequalsIterator = functionIterator(predicateIterator(abstractSingleVariableConstraint.getNegativeNormalizedAtoms(), // negative equality is disequality
e -> e.hasFunctor(FunctorConstants.EQUALITY)), e -> e.get(1));
disequals = arrayListFrom(disequalsIterator);
}
return disequals;
}
use of com.sri.ai.grinder.sgdpllt.core.constraint.AbstractSingleVariableConstraint in project aic-expresso by aic-sri-international.
the class AbstractSingleVariableNumericConstraintFeasibilityRegionStepSolver method makeLowerBoundsAndStrictness.
/**
* A method setting {@link #lowerBoundsIncludingImplicitOnes} and {@link #fromLowerBoundsIncludingImplicitOnesToStrictness}
* from constraint and variable's type.
* @param context
*/
protected void makeLowerBoundsAndStrictness(Context context) {
AbstractSingleVariableConstraint abstractSingleVariableConstraint = (AbstractSingleVariableConstraint) constraint;
FunctionIterator<Expression, Pair<Expression, Boolean>> lowerBoundsAndStrictnessFromPositiveNormalizedAtomsIterator = functionIterator(predicateIterator(abstractSingleVariableConstraint.getPositiveNormalizedAtoms(), // X > Y, so Y is a strict lower bound
e -> e.hasFunctor(GREATER_THAN)), // bound is strict
e -> processExplicitLowerBoundAndStrictnessPair(e.get(1), true, context));
FunctionIterator<Expression, Pair<Expression, Boolean>> lowerBoundsAndStrictnessFromNegativeNormalizedAtomsIterator = functionIterator(predicateIterator(abstractSingleVariableConstraint.getNegativeNormalizedAtoms(), e -> e.hasFunctor(LESS_THAN)), // not (X < Y) <=> X >= Y, so bound is non-strict
e -> processExplicitLowerBoundAndStrictnessPair(e.get(1), false, context));
Pair<Expression, Boolean> typeLowerBoundAndStrictness = getTypeLowerBoundAndStrictness(context);
Iterator<Pair<Expression, Boolean>> lowerBoundsAndStrictnessIterator = new NestedIterator<>(lowerBoundsAndStrictnessFromPositiveNormalizedAtomsIterator, lowerBoundsAndStrictnessFromNegativeNormalizedAtomsIterator, typeLowerBoundAndStrictness);
lowerBoundsIncludingImplicitOnes = arrayList();
fromLowerBoundsIncludingImplicitOnesToStrictness = map();
for (Pair<Expression, Boolean> boundAndStrictness : in(lowerBoundsAndStrictnessIterator)) {
Expression bound = boundAndStrictness.first;
lowerBoundsIncludingImplicitOnes.add(bound);
Boolean strictness = boundAndStrictness.second;
Boolean previousStrictness = fromLowerBoundsIncludingImplicitOnesToStrictness.get(bound);
if (previousStrictness == null || (!previousStrictness && strictness)) {
// if no strictness information so far, store current one; otherwise, only need to change it if previous occurrences were non-strict and this one is strict
fromLowerBoundsIncludingImplicitOnesToStrictness.put(bound, strictness);
}
}
}
use of com.sri.ai.grinder.sgdpllt.core.constraint.AbstractSingleVariableConstraint in project aic-expresso by aic-sri-international.
the class AbstractSingleVariableNumericConstraintFeasibilityRegionStepSolver method getNonEqualityComparisons.
protected ArrayList<Expression> getNonEqualityComparisons(Context context) {
if (nonEqualityComparisons == null) {
AbstractSingleVariableConstraint abstractSingleVariableConstraint = (AbstractSingleVariableConstraint) constraint;
Iterator<Expression> fromPositiveNormalizedAtoms = predicateIterator(abstractSingleVariableConstraint.getPositiveNormalizedAtoms(), e -> !e.hasFunctor(FunctorConstants.EQUALITY));
Iterator<Expression> fromNegativeNormalizedAtoms = functionIterator(// negative normalized atom is never an equality
abstractSingleVariableConstraint.getNegativeNormalizedAtoms(), e -> abstractSingleVariableConstraint.getTheory().getLiteralNegation(e, context));
Pair<Expression, Boolean> typeLowerBoundAndStrictness = getTypeLowerBoundAndStrictness(context);
Expression typeLowerBound = typeLowerBoundAndStrictness.first;
boolean typeLowerBoundIsStrict = typeLowerBoundAndStrictness.second;
String greaterThanOperator = typeLowerBoundIsStrict ? GREATER_THAN : GREATER_THAN_OR_EQUAL_TO;
Expression variableIsGreaterThanTypeLowerBound = apply(greaterThanOperator, getConstraint().getVariable(), typeLowerBound);
Pair<Expression, Boolean> typeUpperBoundAndStrictness = getTypeUpperBoundAndStrictness(context);
Expression typeUpperBound = typeUpperBoundAndStrictness.first;
boolean typeUpperBoundIsStrict = typeUpperBoundAndStrictness.second;
String lessThanOperator = typeUpperBoundIsStrict ? LESS_THAN : LESS_THAN_OR_EQUAL_TO;
Expression variableIsLessThanOrEqualToTypeUpperBound = apply(lessThanOperator, getConstraint().getVariable(), typeUpperBound);
Iterator<Expression> all = new NestedIterator<Expression>(fromPositiveNormalizedAtoms, fromNegativeNormalizedAtoms, variableIsGreaterThanTypeLowerBound, variableIsLessThanOrEqualToTypeUpperBound);
nonEqualityComparisons = arrayListFrom(all);
}
return nonEqualityComparisons;
}
use of com.sri.ai.grinder.sgdpllt.core.constraint.AbstractSingleVariableConstraint in project aic-expresso by aic-sri-international.
the class AbstractSingleVariableNumericConstraintFeasibilityRegionStepSolver method getEquals.
protected ArrayList<Expression> getEquals() {
if (equals == null) {
AbstractSingleVariableConstraint abstractSingleVariableConstraint = (AbstractSingleVariableConstraint) constraint;
Iterator<Expression> equalsIterator = functionIterator(predicateIterator(abstractSingleVariableConstraint.getPositiveNormalizedAtoms(), e -> e.hasFunctor(EQUALITY)), e -> e.get(1));
equals = arrayListFrom(equalsIterator);
}
return equals;
}
Aggregations