use of com.sri.ai.util.collect.FunctionIterator 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.util.collect.FunctionIterator 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.util.collect.FunctionIterator 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.util.collect.FunctionIterator 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.util.collect.FunctionIterator 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