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);
}
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());
}
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);
}
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());
}
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));
}
Aggregations