use of at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl 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.common.AtomStoreImpl 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.common.AtomStoreImpl 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.common.AtomStoreImpl 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);
}
use of at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl in project Alpha by alpha-asp.
the class NaiveGrounderTest method testDeadEnd.
/**
* Tests the method {@link NaiveGrounder#getGroundInstantiations(InternalRule, RuleGroundingOrder, Substitution, Assignment)} on a
* predefined program:
* <code>
* p1(1). q1(1). <br/>
* x :- p1(X), p2(X), q1(Y), q2(Y). <br/>
* p2(X) :- something(X). <br/>
* q2(X) :- something(X). <br/>
* </code>
* Given one grounding order {@code groundingOrder} for the first rule in this program which starts with
* the literal whose predicate name is {@code predicateNameOfStartingLiteral} and a substitution substituting
* the variable in this literal by 1 it is attempted to ground the rule.
* It is then asserted that ground instantiations are produced if and only if {@code expectNoGoods} is true.
*
* @param predicateNameOfStartingLiteral the predicate name of the starting literal, either "p1" or "q1".
* @param groundingOrder a grounding order for the first rule in the predefined program that starts with the literal
* whose predicate name is {@code predicateNameOfStartingLiteral}.
* @param expectNoGoods {@code true} iff ground instantiations are expected to be produced under the conditions
* described above.
*/
private void testDeadEnd(String predicateNameOfStartingLiteral, RuleGroundingOrderImpl groundingOrder, boolean expectNoGoods) {
String aspStr = "p1(1). q1(1). " + "x :- p1(X), p2(X), q1(Y), q2(Y). " + "p2(X) :- something(X). " + "q2(X) :- something(X). ";
CompiledProgram program = InternalProgram.fromNormalProgram(NORMALIZE_TRANSFORM.apply(PROGRAM_PARSER.parse(aspStr)));
AtomStore atomStore = new AtomStoreImpl();
NaiveGrounder grounder = (NaiveGrounder) GrounderFactory.getInstance("naive", program, atomStore, p -> true, GrounderHeuristicsConfiguration.permissive(), true);
CompiledRule nonGroundRule = grounder.getNonGroundRule(0);
String strLiteral = "p1".equals(predicateNameOfStartingLiteral) ? "p1(X)" : "p1(Y)";
final Literal startingLiteral = PROGRAM_PART_PARSER.parseLiteral(strLiteral);
((RuleGroundingInfoImpl) nonGroundRule.getGroundingInfo()).groundingOrders.put(startingLiteral, groundingOrder);
grounder.bootstrap();
TrailAssignment currentAssignment = new TrailAssignment(atomStore);
final Substitution subst1 = BasicSubstitution.specializeSubstitution(startingLiteral, new Instance(Terms.newConstant(1)), BasicSubstitution.EMPTY_SUBSTITUTION);
final BindingResult bindingResult = grounder.getGroundInstantiations(nonGroundRule, groundingOrder, subst1, currentAssignment);
assertEquals(expectNoGoods, bindingResult.size() > 0);
}
Aggregations