use of at.ac.tuwien.kr.alpha.core.solver.TrailAssignment in project Alpha by alpha-asp.
the class LiteralInstantiationStrategyTest method defaultLazyGroundingSubstituteNonGroundLiteralWithUnassignedInstance.
/**
* 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 empty assignment, so we
* expect the assignment status (i.e. assignment status of the found ground
* instance) passed back with the substitution to be UNASSIGNED. Since
* UNASSIGNED and FALSE atoms are (potentially) stale in working memory, we
* expect the atom "q(a, b)" to be added to the stale set by the instantiation
* strategy.
*/
@Test
public void defaultLazyGroundingSubstituteNonGroundLiteralWithUnassignedInstance() {
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);
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.UNASSIGNED, assignmentStatus);
assertTrue(substitution.isVariableSet(Terms.newVariable("X")));
assertEquals(Terms.newSymbolicConstant("b"), substitution.eval(Terms.newVariable("X")));
assertEquals(1, staleSet.size());
assertTrue(staleSet.contains(Atoms.newBasicAtom(q, Terms.newSymbolicConstant("a"), Terms.newSymbolicConstant("b"))));
}
use of at.ac.tuwien.kr.alpha.core.solver.TrailAssignment in project Alpha by alpha-asp.
the class AlphaHeuristicTestAssumptions method setUp.
@BeforeEach
public void setUp() {
String testProgram = "" + "b1." + "b2." + "{b3}." + "{b4}." + "h :- b1, b2, not b3, not b4.";
CompiledProgram internalProgram = parseAndPreprocess.apply(testProgram);
atomStore = new AtomStoreImpl();
grounder = new NaiveGrounder(internalProgram, atomStore, true);
assignment = new TrailAssignment(atomStore);
choiceManager = new TestableChoiceManager(assignment, new NaiveNoGoodStore(assignment));
}
use of at.ac.tuwien.kr.alpha.core.solver.TrailAssignment in project Alpha by alpha-asp.
the class BranchingHeuristicFactoryTest method setUp.
@BeforeEach
public void setUp() {
AtomStore atomStore = new AtomStoreImpl();
WritableAssignment assignment = new TrailAssignment(atomStore);
NoGoodStore store = new NoGoodStoreAlphaRoaming(assignment, debugInternalChecks);
this.choiceManager = new ChoiceManager(assignment, store);
}
use of at.ac.tuwien.kr.alpha.core.solver.TrailAssignment in project Alpha by alpha-asp.
the class ReplayHeuristicTest method setUp.
@BeforeEach
public void setUp() {
AtomStore atomStore = new AtomStoreImpl();
WritableAssignment assignment = new TrailAssignment(atomStore);
NoGoodStore store = new NoGoodStoreAlphaRoaming(assignment, debugInternalChecks);
this.choiceManager = new PseudoChoiceManager(assignment, store);
}
use of at.ac.tuwien.kr.alpha.core.solver.TrailAssignment in project Alpha by alpha-asp.
the class NaiveGrounderTest method groundRuleAlreadyGround.
/**
* Asserts that a ground rule whose positive body is not satisfied by the empty assignment
* is grounded immediately.
*/
@Test
public void groundRuleAlreadyGround() {
ASPCore2Program program = PROGRAM_PARSER.parse("a :- not b. " + "b :- not a. " + "c :- b.");
NormalProgram normal = NORMALIZE_TRANSFORM.apply(program);
CompiledProgram prog = new StratifiedEvaluation().apply(AnalyzedProgram.analyzeNormalProgram(normal));
AtomStore atomStore = new AtomStoreImpl();
Grounder grounder = GrounderFactory.getInstance("naive", prog, atomStore, true);
Map<Integer, NoGood> noGoods = grounder.getNoGoods(new TrailAssignment(atomStore));
int litCNeg = Literals.atomToLiteral(atomStore.get(PROGRAM_PART_PARSER.parseBasicAtom("c")), false);
int litB = Literals.atomToLiteral(atomStore.get(PROGRAM_PART_PARSER.parseBasicAtom("b")));
assertExistsNoGoodContaining(noGoods.values(), litCNeg);
assertExistsNoGoodContaining(noGoods.values(), litB);
}
Aggregations