use of at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl in project Alpha by alpha-asp.
the class NoGoodGeneratorTest method collectNeg_ContainsOnlyPositiveLiterals.
/**
* Calls {@link NoGoodGenerator#collectNegLiterals(InternalRule, Substitution)}, which puts the atom occurring
* negatively in a rule into the atom store. It is then checked whether the atom in the atom store is positive.
*/
@Test
public void collectNeg_ContainsOnlyPositiveLiterals() {
ASPCore2Program input = PARSER.parse("p(a,b). " + "q(a,b) :- not nq(a,b). " + "nq(a,b) :- not q(a,b).");
NormalProgram normal = NORMALIZE_TRANSFORM.apply(input);
CompiledProgram program = InternalProgram.fromNormalProgram(normal);
CompiledRule rule = program.getRules().get(1);
AtomStore atomStore = new AtomStoreImpl();
Grounder grounder = GrounderFactory.getInstance("naive", program, atomStore, true);
NoGoodGenerator noGoodGenerator = ((NaiveGrounder) grounder).noGoodGenerator;
Substitution substitution = new BasicSubstitution();
substitution.put(X, A);
substitution.put(Y, B);
List<Integer> collectedNeg = noGoodGenerator.collectNegLiterals(rule, substitution);
assertEquals(1, collectedNeg.size());
String negAtomString = atomStore.atomToString(Literals.atomOf(collectedNeg.get(0)));
assertEquals("q(a, b)", negAtomString);
}
use of at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl in project Alpha by alpha-asp.
the class HeapOfActiveAtomsTest method setUp.
@BeforeEach
public void setUp() {
atomStore = new AtomStoreImpl();
assignment = new TrailAssignment(atomStore);
noGoodStore = new NoGoodStoreAlphaRoaming(assignment);
ChoiceManager choiceManager = new PseudoChoiceManager(assignment, noGoodStore);
this.vsids = new VSIDS(assignment, choiceManager, MOMs.DEFAULT_STRATEGY);
}
use of at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl in project Alpha by alpha-asp.
the class SolverTests method dummyGrounder.
@RegressionTest
public void dummyGrounder(RegressionTestConfig cfg) {
AtomStore atomStore = new AtomStoreImpl();
assertEquals(DummyGrounder.EXPECTED, buildSolverForRegressionTest(atomStore, new DummyGrounder(atomStore), cfg).collectSet());
}
use of at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl in project Alpha by alpha-asp.
the class VSIDSTest method setUp.
@BeforeEach
public void setUp() {
atomStore = new AtomStoreImpl();
TestUtils.fillAtomStore(atomStore, 4);
assignment = new TrailAssignment(atomStore);
assignment.growForMaxAtomId();
noGoodStore = new NoGoodStoreAlphaRoaming(assignment);
this.vsids = new VSIDS(assignment, new PseudoChoiceManager(assignment, noGoodStore), null);
}
use of at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl in project Alpha by alpha-asp.
the class LiteralInstantiationStrategyTest method defaultLazyGroundingSubstituteNonGroundLiteralWithTrueInstance.
/**
* Uses {@link DefaultLazyGroundingInstantiationStrategy} to find the ground
* instance "q(a, b)" for the partially ground positive literal "q(a, X)".
*
* In this case, the instantiation strategy has an assignment where q(a, b) is
* assigned ThriceTruth.TRUE, so we expect the assignment status (i.e.
* assignment status of the found ground instance) passed back with the
* substitution to be TRUE. Furthermore, we expect the stale atom set to stay
* empty.
*/
@Test
public void defaultLazyGroundingSubstituteNonGroundLiteralWithTrueInstance() {
Predicate q = Predicates.getPredicate("q", 2);
BasicAtom nonGroundAtom = Atoms.newBasicAtom(q, Terms.newSymbolicConstant("a"), Terms.newVariable("X"));
WorkingMemory workingMemory = new WorkingMemory();
workingMemory.initialize(q);
workingMemory.addInstance(Atoms.newBasicAtom(q, Terms.newSymbolicConstant("a"), Terms.newSymbolicConstant("b")), true);
AtomStore atomStore = new AtomStoreImpl();
WritableAssignment assignment = new TrailAssignment(atomStore);
BasicAtom groundAtom = Atoms.newBasicAtom(q, Terms.newSymbolicConstant("a"), Terms.newSymbolicConstant("b"));
atomStore.putIfAbsent(groundAtom);
assignment.growForMaxAtomId();
assignment.assign(atomStore.get(groundAtom), ThriceTruth.TRUE);
LinkedHashSet<Atom> staleSet = new LinkedHashSet<>();
DefaultLazyGroundingInstantiationStrategy strategy = new DefaultLazyGroundingInstantiationStrategy(workingMemory, atomStore, Collections.emptyMap(), false);
strategy.setStaleWorkingMemoryEntries(staleSet);
strategy.setCurrentAssignment(assignment);
List<ImmutablePair<Substitution, AssignmentStatus>> result = strategy.getAcceptedSubstitutions(Literals.fromAtom(nonGroundAtom, true), new BasicSubstitution());
assertEquals(1, result.size());
ImmutablePair<Substitution, AssignmentStatus> substitutionInfo = result.get(0);
Substitution substitution = substitutionInfo.left;
AssignmentStatus assignmentStatus = substitutionInfo.right;
assertEquals(AssignmentStatus.TRUE, assignmentStatus);
assertTrue(substitution.isVariableSet(Terms.newVariable("X")));
assertEquals(Terms.newSymbolicConstant("b"), substitution.eval(Terms.newVariable("X")));
assertTrue(staleSet.isEmpty());
}
Aggregations