Search in sources :

Example 11 with Atom

use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.

the class UnificationTest method nonunificationSimple.

@Test
public void nonunificationSimple() {
    Atom left = partsParser.parseLiteral("a(b,X)").getAtom();
    Atom right = partsParser.parseLiteral("a(c,Y)").getAtom();
    Unifier unifier = Unification.unifyAtoms(left, right);
    assertNull(unifier);
}
Also used : Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Unifier(at.ac.tuwien.kr.alpha.commons.substitutions.Unifier) Test(org.junit.jupiter.api.Test)

Example 12 with Atom

use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.

the class UnificationTest method unificationBothSides.

@Test
public void unificationBothSides() {
    Atom left = partsParser.parseLiteral("p(X, 1)").getAtom();
    Atom right = partsParser.parseLiteral("p(d, Y)").getAtom();
    Unifier unifier = Unification.unifyAtoms(left, right);
    assertNotNull(unifier);
    assertEquals(2, unifier.getMappedVariables().size());
    assertEquals("d", unifier.eval(Terms.newVariable("X")).toString());
    assertEquals("1", unifier.eval(Terms.newVariable("Y")).toString());
}
Also used : Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Unifier(at.ac.tuwien.kr.alpha.commons.substitutions.Unifier) Test(org.junit.jupiter.api.Test)

Example 13 with Atom

use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.

the class UnificationTest method nonunificationNested.

@Test
public void nonunificationNested() {
    Atom left = partsParser.parseLiteral("a(f(X,a))").getAtom();
    Atom right = partsParser.parseLiteral("a(f(a,b))").getAtom();
    Unifier unifier = Unification.unifyAtoms(left, right);
    assertNull(unifier);
}
Also used : Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Unifier(at.ac.tuwien.kr.alpha.commons.substitutions.Unifier) Test(org.junit.jupiter.api.Test)

Example 14 with Atom

use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.

the class UnificationTest method simpleGroundUnification.

@Test
public void simpleGroundUnification() {
    Atom pX = partsParser.parseLiteral("p(X)").getAtom();
    Atom pa = partsParser.parseLiteral("p(abc)").getAtom();
    Unifier unifier = Unification.unifyAtoms(pa, pX);
    assertNotNull(unifier);
    assertEquals(1, unifier.getMappedVariables().size());
    assertEquals("abc", unifier.eval(Terms.newVariable("X")).toString());
}
Also used : Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Unifier(at.ac.tuwien.kr.alpha.commons.substitutions.Unifier) Test(org.junit.jupiter.api.Test)

Example 15 with Atom

use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.

the class LiteralInstantiationStrategyTest method defaultLazyGroundingCheckFalseGroundLiteral.

/**
 * Uses {@link DefaultLazyGroundingInstantiationStrategy} to check the truth
 * (i.e. {@link AssignmentStatus}) of the positive ground literal "p(a)".
 *
 * In this case, the instantiation strategy has an assignment where the atom
 * "p(a)" is assigned ThriceTruth.FALSE, so we expect the instantiation strategy
 * to determine that p(a) is FALSE. Since UNASSIGNED and FALSE atoms are
 * (potentially) stale in working memory, we expect the atom "p(a)" to be added
 * to the stale set by the instantiation strategy.
 */
@Test
public void defaultLazyGroundingCheckFalseGroundLiteral() {
    Predicate p = Predicates.getPredicate("p", 1);
    BasicAtom pOfA = Atoms.newBasicAtom(p, Terms.newSymbolicConstant("a"));
    WorkingMemory workingMemory = new WorkingMemory();
    AtomStore atomStore = new AtomStoreImpl();
    WritableAssignment assignment = new TrailAssignment(atomStore);
    atomStore.putIfAbsent(pOfA);
    assignment.growForMaxAtomId();
    assignment.assign(atomStore.get(pOfA), ThriceTruth.FALSE);
    LinkedHashSet<Atom> staleSet = new LinkedHashSet<>();
    DefaultLazyGroundingInstantiationStrategy strategy = new DefaultLazyGroundingInstantiationStrategy(workingMemory, atomStore, Collections.emptyMap(), false);
    strategy.setStaleWorkingMemoryEntries(staleSet);
    strategy.setCurrentAssignment(assignment);
    AssignmentStatus assignmentStatus = strategy.getTruthForGroundLiteral(Literals.fromAtom(pOfA, true));
    assertEquals(AssignmentStatus.FALSE, assignmentStatus);
    assertEquals(1, staleSet.size());
    assertTrue(staleSet.contains(pOfA));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AtomStore(at.ac.tuwien.kr.alpha.core.common.AtomStore) WorkingMemory(at.ac.tuwien.kr.alpha.core.grounder.WorkingMemory) AtomStoreImpl(at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl) WritableAssignment(at.ac.tuwien.kr.alpha.core.solver.WritableAssignment) BasicAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom) TrailAssignment(at.ac.tuwien.kr.alpha.core.solver.TrailAssignment) BasicAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate) Test(org.junit.jupiter.api.Test)

Aggregations

Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)73 Test (org.junit.jupiter.api.Test)38 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)27 BasicAtom (at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom)27 LinkedHashSet (java.util.LinkedHashSet)16 Unifier (at.ac.tuwien.kr.alpha.commons.substitutions.Unifier)15 ArrayList (java.util.ArrayList)14 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)13 Literal (at.ac.tuwien.kr.alpha.api.programs.literals.Literal)12 AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)11 Instance (at.ac.tuwien.kr.alpha.commons.substitutions.Instance)9 AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)9 WorkingMemory (at.ac.tuwien.kr.alpha.core.grounder.WorkingMemory)9 TrailAssignment (at.ac.tuwien.kr.alpha.core.solver.TrailAssignment)9 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)8 RuleAtom (at.ac.tuwien.kr.alpha.core.atoms.RuleAtom)8 WritableAssignment (at.ac.tuwien.kr.alpha.core.solver.WritableAssignment)7 Substitution (at.ac.tuwien.kr.alpha.api.grounder.Substitution)6 ExternalAtom (at.ac.tuwien.kr.alpha.api.programs.atoms.ExternalAtom)6 AnswerSetBuilder (at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder)6