use of at.ac.tuwien.kr.alpha.common.BasicAtom in project Alpha by alpha-asp.
the class ChoiceGrounder method assignmentToAnswerSet.
@Override
public AnswerSet assignmentToAnswerSet(Iterable<Integer> trueAtoms) {
SortedSet<Predicate> trueAtomPredicates = new TreeSet<>();
for (int trueAtom : trueAtoms) {
BasicPredicate atomPredicate = new BasicPredicate(atomIdToString.get(trueAtom), 0);
if (!filter.test(atomPredicate)) {
continue;
}
if (atomPredicate.getPredicateName().startsWith("_")) {
continue;
}
trueAtomPredicates.add(atomPredicate);
}
// Add the atom instances
Map<Predicate, SortedSet<Atom>> predicateInstances = new HashMap<>();
for (Predicate trueAtomPredicate : trueAtomPredicates) {
BasicAtom basicAtom = new BasicAtom(trueAtomPredicate);
predicateInstances.put(trueAtomPredicate, new TreeSet<>(singleton(basicAtom)));
}
// only one predicate instance representing 0 terms.
return new BasicAnswerSet(trueAtomPredicates, predicateInstances);
}
use of at.ac.tuwien.kr.alpha.common.BasicAtom in project Alpha by alpha-asp.
the class NonGroundRule method isSafe.
/**
* Checks whether a rule is safe. A rule is safe iff all negated variables and all variables occurring in the
* head also occur in the positive body).
* @return true if this rule is safe.
*/
private boolean isSafe() {
Set<VariableTerm> positiveVariables = new HashSet<>();
Set<VariableTerm> builtinVariables = new HashSet<>();
// Check that all negative variables occur in the positive body.
for (Atom posAtom : bodyAtomsPositive) {
// implementations of the Atom interface. Not nice.
if (posAtom instanceof BasicAtom) {
positiveVariables.addAll(posAtom.getOccurringVariables());
} else if (posAtom instanceof BuiltinAtom) {
builtinVariables.addAll(posAtom.getOccurringVariables());
}
}
for (Atom negAtom : bodyAtomsNegative) {
for (VariableTerm term : negAtom.getOccurringVariables()) {
if (!positiveVariables.contains(term)) {
return false;
}
}
}
for (VariableTerm builtinVariable : builtinVariables) {
if (!positiveVariables.contains(builtinVariable)) {
return false;
}
}
// Constraint are safe at this point
if (isConstraint()) {
return true;
}
// Check that all variables of the head occur in the positive body.
List<VariableTerm> headVariables = headAtom.getOccurringVariables();
headVariables.removeAll(positiveVariables);
return headVariables.isEmpty();
}
Aggregations