use of at.ac.tuwien.kr.alpha.api.terms.VariableTerm 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.VariableTerm 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.VariableTerm 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.VariableTerm in project Alpha by alpha-asp.
the class VariableTermImpl method normalizeVariables.
@Override
public Term normalizeVariables(String renamePrefix, Term.RenameCounter counter) {
VariableTerm renamedThis = counter.getRenamedVariables().get(this);
if (renamedThis != null) {
return renamedThis;
} else {
VariableTerm renamedVariable = VariableTermImpl.getInstance(renamePrefix + counter.getAndIncrement());
counter.getRenamedVariables().put(this, renamedVariable);
return renamedVariable;
}
}
use of at.ac.tuwien.kr.alpha.api.terms.VariableTerm 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;
}
Aggregations