use of at.ac.tuwien.kr.alpha.api.programs.Predicate in project Alpha by alpha-asp.
the class SubstitutionTest method substituteBasicAtomLiteral.
private void substituteBasicAtomLiteral(boolean negated) {
Predicate p = Predicates.getPredicate("p", 2);
BasicAtom atom = Atoms.newBasicAtom(p, Arrays.asList(X, Y));
Literal literal = Literals.fromAtom(atom, !negated);
Substitution substitution = new BasicSubstitution();
substitution.put(X, A);
substitution.put(Y, B);
literal = literal.substitute(substitution);
assertEquals(p, literal.getPredicate());
assertEquals(A, literal.getTerms().get(0));
assertEquals(B, literal.getTerms().get(1));
assertEquals(negated, literal.isNegated());
}
use of at.ac.tuwien.kr.alpha.api.programs.Predicate in project Alpha by alpha-asp.
the class DummyGrounder method assignmentToAnswerSet.
@Override
public AnswerSet assignmentToAnswerSet(Iterable<Integer> trueAtoms) {
// Note: This grounder only deals with 0-ary predicates, i.e., every atom is a predicate and there is
// only one predicate instance representing 0 terms.
SortedSet<Predicate> trueAtomPredicates = new TreeSet<>();
for (int trueAtom : trueAtoms) {
Predicate atomPredicate = atomStore.get(trueAtom).getPredicate();
if (!filter.test(atomPredicate)) {
continue;
}
if (atomPredicate.isInternal()) {
continue;
}
trueAtomPredicates.add(atomPredicate);
}
// Add the atom instances
Map<Predicate, SortedSet<Atom>> predicateInstances = new HashMap<>();
for (Predicate trueAtomPredicate : trueAtomPredicates) {
BasicAtom internalBasicAtom = Atoms.newBasicAtom(trueAtomPredicate);
predicateInstances.put(trueAtomPredicate, new TreeSet<>(singleton(internalBasicAtom)));
}
return AnswerSets.newAnswerSet(trueAtomPredicates, predicateInstances);
}
use of at.ac.tuwien.kr.alpha.api.programs.Predicate in project Alpha by alpha-asp.
the class ThreeColouringTestWithRandom method fact.
private Atom fact(String predicateName, int... iTerms) {
List<Term> terms = new ArrayList<>(iTerms.length);
Predicate predicate = Predicates.getPredicate(predicateName, iTerms.length);
for (int i : iTerms) {
terms.add(Terms.newConstant(i));
}
return Atoms.newBasicAtom(predicate, terms);
}
use of at.ac.tuwien.kr.alpha.api.programs.Predicate in project Alpha by alpha-asp.
the class TestUtils method basicAtomWithStringTerms.
public static BasicAtom basicAtomWithStringTerms(String predicate, String... terms) {
Predicate pred = Predicates.getPredicate(predicate, terms.length);
List<Term> trms = new ArrayList<>();
for (String str : terms) {
trms.add(Terms.newConstant(str));
}
return Atoms.newBasicAtom(pred, trms);
}
Aggregations