use of at.ac.tuwien.kr.alpha.api.programs.Predicate in project Alpha by alpha-asp.
the class LiteralInstantiationStrategyTest method defaultLazyGroundingNoAssignmentGroundLiteral.
/**
* Uses {@link DefaultLazyGroundingInstantiationStrategy} to check the truth
* (i.e. {@link AssignmentStatus}) of the positive ground literal "p(a)".
*
* In this case, the instantiation strategy does not have an assignment set (as
* is the case when {@link NaiveGrounder} is in bootstrap),
* so we expect the instantiation strategy to determine that p(a) is TRUE.
* Furthermore, the stale atom set (used by {@link NaiveGrounder} to clean up
* atoms that should be deleted from working memory) must stay empty.
*/
@Test
public void defaultLazyGroundingNoAssignmentGroundLiteral() {
Predicate p = Predicates.getPredicate("p", 1);
BasicAtom pOfA = Atoms.newBasicAtom(p, Terms.newSymbolicConstant("a"));
WorkingMemory workingMemory = new WorkingMemory();
LinkedHashSet<Atom> staleSet = new LinkedHashSet<>();
DefaultLazyGroundingInstantiationStrategy strategy = new DefaultLazyGroundingInstantiationStrategy(workingMemory, new AtomStoreImpl(), Collections.emptyMap(), false);
strategy.setStaleWorkingMemoryEntries(staleSet);
strategy.setCurrentAssignment(null);
AssignmentStatus assignmentStatus = strategy.getTruthForGroundLiteral(Literals.fromAtom(pOfA, true));
assertEquals(AssignmentStatus.TRUE, assignmentStatus);
assertTrue(staleSet.isEmpty());
}
use of at.ac.tuwien.kr.alpha.api.programs.Predicate in project Alpha by alpha-asp.
the class LiteralInstantiationStrategyTest method defaultLazyGroundingCheckTrueGroundLiteral.
/**
* 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.TRUE, so we expect the instantiation strategy
* to determine that p(a) is TRUE. Furthermore, the stale atom set
* (used by {@link NaiveGrounder} to clean up atoms that should be deleted from
* working memory) must stay empty.
*/
@Test
public void defaultLazyGroundingCheckTrueGroundLiteral() {
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.TRUE);
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.TRUE, assignmentStatus);
assertTrue(staleSet.isEmpty());
}
use of at.ac.tuwien.kr.alpha.api.programs.Predicate in project Alpha by alpha-asp.
the class LiteralInstantiationStrategyTest method defaultLazyGroundingCheckUnassignedGroundLiteral.
/**
* 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 empty assignment,
* so we expect the instantiation strategy to determine that p(a) is UNASSIGNED.
* 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 defaultLazyGroundingCheckUnassignedGroundLiteral() {
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);
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.UNASSIGNED, assignmentStatus);
assertEquals(1, staleSet.size());
assertTrue(staleSet.contains(pOfA));
}
use of at.ac.tuwien.kr.alpha.api.programs.Predicate in project Alpha by alpha-asp.
the class AggregateRewritingTest method countLeSortingGridSimple.
// @formatter:on
@Test
public void countLeSortingGridSimple() {
List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(CNT_LE1_ASP);
assertEquals(1, answerSets.size());
AnswerSet answerSet = answerSets.get(0);
Predicate thing = Predicates.getPredicate("thing", 1);
Predicate candidate = Predicates.getPredicate("candidate", 1);
Predicate cntLe = Predicates.getPredicate("cnt_le", 1);
// System.out.println(new SimpleAnswerSetFormatter("\n").format(answerSet));
assertTrue(answerSet.getPredicateInstances(thing).contains(Atoms.newBasicAtom(thing, Terms.newConstant(75))));
assertTrue(answerSet.getPredicateInstances(thing).contains(Atoms.newBasicAtom(thing, Terms.newConstant(76))));
assertTrue(answerSet.getPredicateInstances(candidate).contains(Atoms.newBasicAtom(candidate, Terms.newConstant(2))));
assertTrue(answerSet.getPredicateInstances(candidate).contains(Atoms.newBasicAtom(candidate, Terms.newConstant(3))));
assertTrue(answerSet.getPredicateInstances(candidate).contains(Atoms.newBasicAtom(candidate, Terms.newConstant(4))));
assertTrue(answerSet.getPredicates().contains(cntLe));
assertTrue(answerSet.getPredicateInstances(cntLe).contains(Atoms.newBasicAtom(cntLe, Terms.newConstant(2))));
}
use of at.ac.tuwien.kr.alpha.api.programs.Predicate in project Alpha by alpha-asp.
the class AggregateRewritingTest method countEqGlobalVars.
@Test
public void countEqGlobalVars() {
List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(VERTEX_DEGREE_ASP);
assertEquals(1, answerSets.size());
AnswerSet answerSet = answerSets.get(0);
Predicate vertexDegree = Predicates.getPredicate("graph_vertex_degree", 3);
// System.out.println(new SimpleAnswerSetFormatter("\n").format(answerSet));
assertTrue(answerSet.getPredicates().contains(vertexDegree));
assertTrue(answerSet.getPredicateInstances(vertexDegree).contains(Atoms.newBasicAtom(vertexDegree, Terms.newSymbolicConstant("g1"), Terms.newConstant(1), Terms.newConstant(2))));
assertTrue(answerSet.getPredicateInstances(vertexDegree).contains(Atoms.newBasicAtom(vertexDegree, Terms.newSymbolicConstant("g1"), Terms.newConstant(2), Terms.newConstant(2))));
assertTrue(answerSet.getPredicateInstances(vertexDegree).contains(Atoms.newBasicAtom(vertexDegree, Terms.newSymbolicConstant("g1"), Terms.newConstant(3), Terms.newConstant(2))));
}
Aggregations