use of at.ac.tuwien.kr.alpha.api.terms.Term in project Alpha by alpha-asp.
the class EnumerationAtom method substitute.
@Override
public EnumerationAtom substitute(Substitution substitution) {
Term substEnumIdTerm = enumIdTerm.substitute(substitution);
Term substValueTerm = valueTerm.substitute(substitution);
Term substIndexTerm = indexTerm.substitute(substitution);
return new EnumerationAtom(substEnumIdTerm, substValueTerm, (VariableTerm) substIndexTerm);
}
use of at.ac.tuwien.kr.alpha.api.terms.Term in project Alpha by alpha-asp.
the class EnumerationAtom method addEnumerationIndexToSubstitution.
/**
* Based on a given substitution, substitutes the first two terms of this {@link EnumerationAtom} with the values from the substitution,
* and returns a new substitution with all mappings from the input substitution plus a binding for the third term of the enum atom to the
* integer index that is mapped to the first two terms in the internal <code>ENUMERATIONS</code> map.
*
* @param substitution an input substitution which must provide ground terms for the first two terms of the enumeration atom.
* @return a new substitution where the third term of the enumeration atom is bound to an integer.
*/
public Substitution addEnumerationIndexToSubstitution(Substitution substitution) {
Term idTerm = this.getTerms().get(0).substitute(substitution);
Term enumerationTerm = this.getTerms().get(1).substitute(substitution);
if (!enumerationTerm.isGround()) {
throw new RuntimeException("Enumeration term is not ground after substitution. Should not happen.");
}
Integer enumerationIndex = getEnumerationIndex(idTerm, enumerationTerm);
BasicSubstitution retVal = new BasicSubstitution(substitution);
retVal.put((VariableTerm) getTerms().get(2), Terms.newConstant(enumerationIndex));
return retVal;
}
use of at.ac.tuwien.kr.alpha.api.terms.Term in project Alpha by alpha-asp.
the class EnumerationLiteral method getNonBindingVariables.
@Override
public Set<VariableTerm> getNonBindingVariables() {
Set<VariableTerm> ret = new HashSet<>(2);
Term idTerm = getTerms().get(0);
Term enumTerm = getTerms().get(1);
if (idTerm instanceof VariableTerm) {
ret.add((VariableTerm) idTerm);
}
if (enumTerm instanceof VariableTerm) {
ret.add((VariableTerm) enumTerm);
}
return ret;
}
use of at.ac.tuwien.kr.alpha.api.terms.Term in project Alpha by alpha-asp.
the class ComparisonLiteralImpl method getNonBindingVariables.
@Override
public Set<VariableTerm> getNonBindingVariables() {
final Term left = getTerms().get(0);
final Term right = getTerms().get(1);
HashSet<VariableTerm> occurringVariables = new HashSet<>();
List<VariableTerm> leftOccurringVariables = new LinkedList<>(left.getOccurringVariables());
List<VariableTerm> rightOccurringVariables = new LinkedList<>(right.getOccurringVariables());
if (assignable(left)) {
leftOccurringVariables.remove(left);
}
if (assignable(right)) {
rightOccurringVariables.remove(right);
}
occurringVariables.addAll(leftOccurringVariables);
occurringVariables.addAll(rightOccurringVariables);
if (assignable(left) || assignable(right)) {
return occurringVariables;
}
// Neither left- nor right-assigning, hence no variable is binding.
return occurringVariables;
}
use of at.ac.tuwien.kr.alpha.api.terms.Term in project Alpha by alpha-asp.
the class ComparisonLiteralImpl method getBindingVariables.
@Override
public Set<VariableTerm> getBindingVariables() {
final Term left = getTerms().get(0);
final Term right = getTerms().get(1);
if (assignable(left) && assignable(right)) {
// In this case non-binding and binding variables cannot be reported accurately, in fact, the double variable could be compiled away.
throw new RuntimeException("Builtin equality with left and right side being variables encountered. Should not happen.");
}
if (assignable(left)) {
return Collections.singleton((VariableTerm) left);
}
if (assignable(right)) {
return Collections.singleton((VariableTerm) right);
}
return Collections.emptySet();
}
Aggregations