Search in sources :

Example 66 with Predicate

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());
}
Also used : Substitution(at.ac.tuwien.kr.alpha.api.grounder.Substitution) BasicSubstitution(at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution) BasicSubstitution(at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution) Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) BasicAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate)

Example 67 with Predicate

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);
}
Also used : HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) SortedSet(java.util.SortedSet) BasicAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate)

Example 68 with Predicate

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);
}
Also used : ArrayList(java.util.ArrayList) Term(at.ac.tuwien.kr.alpha.api.terms.Term) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate)

Example 69 with Predicate

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);
}
Also used : ArrayList(java.util.ArrayList) Term(at.ac.tuwien.kr.alpha.api.terms.Term) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate)

Aggregations

Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)69 Test (org.junit.jupiter.api.Test)37 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)27 BasicAtom (at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom)19 WorkingMemory (at.ac.tuwien.kr.alpha.core.grounder.WorkingMemory)15 Literal (at.ac.tuwien.kr.alpha.api.programs.literals.Literal)14 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)13 BasicSubstitution (at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution)13 LinkedHashSet (java.util.LinkedHashSet)13 Substitution (at.ac.tuwien.kr.alpha.api.grounder.Substitution)11 AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)10 ArrayList (java.util.ArrayList)10 DependencyGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph)9 ComponentGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph)8 Term (at.ac.tuwien.kr.alpha.api.terms.Term)8 AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)8 AnalyzedProgram (at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram)8 CompiledRule (at.ac.tuwien.kr.alpha.core.rules.CompiledRule)8 TrailAssignment (at.ac.tuwien.kr.alpha.core.solver.TrailAssignment)8 HashMap (java.util.HashMap)8