use of at.ac.tuwien.kr.alpha.api.terms.Term in project Alpha by alpha-asp.
the class ArithmeticTermImpl method normalizeVariables.
@Override
public Term normalizeVariables(String renamePrefix, Term.RenameCounter counter) {
Term normalizedLeft = left.normalizeVariables(renamePrefix, counter);
Term normalizedRight = right.normalizeVariables(renamePrefix, counter);
return ArithmeticTermImpl.getInstance(normalizedLeft, arithmeticOperator, normalizedRight);
}
use of at.ac.tuwien.kr.alpha.api.terms.Term in project Alpha by alpha-asp.
the class IndexedInstanceStorage method getMostSelectiveGroundTermPosition.
private int getMostSelectiveGroundTermPosition(Atom atom) {
int smallestNumberOfInstances = Integer.MAX_VALUE;
int mostSelectiveTermPosition = -1;
for (int i = 0; i < atom.getTerms().size(); i++) {
Term testTerm = atom.getTerms().get(i);
if (testTerm.isGround()) {
ArrayList<Instance> instancesMatchingTest = indices.get(i).get(testTerm);
if (instancesMatchingTest == null) {
// Ground term at i matches zero instances, it is most selective.
return i;
}
int numInstancesTestTerm = instancesMatchingTest.size();
if (numInstancesTestTerm < smallestNumberOfInstances) {
smallestNumberOfInstances = numInstancesTestTerm;
mostSelectiveTermPosition = i;
}
}
}
return mostSelectiveTermPosition;
}
use of at.ac.tuwien.kr.alpha.api.terms.Term in project Alpha by alpha-asp.
the class TestMinusTerm method testNormalizeVariablesNoVariable.
@Test
public void testNormalizeVariablesNoVariable() {
Term m2 = MinusTerm.getInstance(ConstantTermImpl.getInstance(2));
assertEquals(m2, m2.normalizeVariables(renamePrefix, counter));
}
use of at.ac.tuwien.kr.alpha.api.terms.Term in project Alpha by alpha-asp.
the class TestMinusTerm method testNormalizeVariablesWithVariable.
@Test
public void testNormalizeVariablesWithVariable() {
Term mX = MinusTerm.getInstance(VariableTermImpl.getInstance("X"));
Term expected = MinusTerm.getInstance(VariableTermImpl.getInstance(renamePrefix + 0));
assertEquals(expected, mX.normalizeVariables(renamePrefix, counter));
}
use of at.ac.tuwien.kr.alpha.api.terms.Term in project Alpha by alpha-asp.
the class IntervalLiteral method getIntervalSubstitutions.
private List<Substitution> getIntervalSubstitutions(Substitution partialSubstitution) {
List<Substitution> substitutions = new ArrayList<>();
List<Term> terms = getTerms();
Term intervalRepresentingVariable = terms.get(1);
IntervalTerm intervalTerm = (IntervalTerm) terms.get(0);
// Check whether intervalRepresentingVariable is bound already.
if (intervalRepresentingVariable instanceof VariableTerm) {
// Still a variable, generate all elements in the interval.
for (int i = intervalTerm.getLowerBound(); i <= intervalTerm.getUpperBound(); i++) {
Substitution ith = new BasicSubstitution(partialSubstitution);
ith.put((VariableTerm) intervalRepresentingVariable, Terms.newConstant(i));
substitutions.add(ith);
}
return substitutions;
} else {
// The intervalRepresentingVariable is bound already, check if it is in the interval.
if (!(intervalRepresentingVariable instanceof ConstantTerm) || !(((ConstantTerm<?>) intervalRepresentingVariable).getObject() instanceof Integer)) {
// Term is not bound to an integer constant, not in the interval.
return Collections.emptyList();
}
// TODO to avoid that type of unchecked cast, we may want interval terms to not extend AbstractTerm
@SuppressWarnings("unchecked") Integer integer = ((ConstantTerm<Integer>) intervalRepresentingVariable).getObject();
if (intervalTerm.getLowerBound() <= integer && integer <= intervalTerm.getUpperBound()) {
return Collections.singletonList(partialSubstitution);
}
return Collections.emptyList();
}
}
Aggregations