use of at.ac.tuwien.kr.alpha.core.programs.CompiledProgram 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.programs.CompiledProgram in project Alpha by alpha-asp.
the class StratifiedEvaluationTest method testPartnerUnitsProblemTopologicalOrder.
/**
* Tests an encoding associated with the partner units problem (PUP) that computes a topological order to be used by
* domain-specific heuristics. The entire program can be solved by stratified evaluation.
*/
@Test
public void testPartnerUnitsProblemTopologicalOrder() throws IOException {
ASPCore2Program prg = parser.parse(StratifiedEvaluationTest.class.getResourceAsStream("/partial-eval/pup_topological_order.asp"));
CompiledProgram evaluated = new StratifiedEvaluation().apply(AnalyzedProgram.analyzeNormalProgram(normalizer.apply(prg)));
assertTrue(evaluated.getRules().isEmpty(), "Not all rules eliminated by stratified evaluation");
assertEquals(57, evaluated.getFacts().size());
}
use of at.ac.tuwien.kr.alpha.core.programs.CompiledProgram in project Alpha by alpha-asp.
the class StratifiedEvaluationTest method testNegatedLiteralInRecursiveRule.
/**
* Verifies correct handling of negated basic literals in StratifiedEvaluation.
* For details, see comments in test program
*
* @throws IOException
*/
@Test
public void testNegatedLiteralInRecursiveRule() throws IOException {
// @formatter:off
String expectedAnswerSet = "basefact1(1), basefact2(1), max_value(10), min_value(1), " + "basefact1(9), basefact2(9), base(1), base(9), " + "inc_value(1), inc_value(2), inc_value(2), inc_value(3), " + "inc_value(4), inc_value(5), inc_value(6), inc_value(7), " + "inc_value(8)";
// @formatter:on
ASPCore2Program prog = Programs.fromInputStream(StratifiedEvaluationTest.class.getResourceAsStream("/partial-eval/recursive_w_negated_condition.asp"), new HashMap<>());
// Run stratified evaluation and solve
CompiledProgram inputStratEval = new StratifiedEvaluation().apply(AnalyzedProgram.analyzeNormalProgram(normalizer.apply(prog)));
Set<AnswerSet> asStrat = solveCompiledProg.apply(inputStratEval);
TestUtils.assertAnswerSetsEqual(expectedAnswerSet, asStrat);
// Solve without stratified evaluation
CompiledProgram inputNoStratEval = InternalProgram.fromNormalProgram(normalizer.apply(prog));
Set<AnswerSet> as = solveCompiledProg.apply(inputNoStratEval);
TestUtils.assertAnswerSetsEqual(expectedAnswerSet, as);
}
use of at.ac.tuwien.kr.alpha.core.programs.CompiledProgram in project Alpha by alpha-asp.
the class StratifiedEvaluationTest method testEqualityWithVarTerms.
@Test
public void testEqualityWithVarTerms() {
String aspStr = "a(1). a(2). a(3). b(X) :- a(X), X = 1. c(X) :- a(X), X = 2. d(X) :- X = 3, a(X).";
CompiledProgram evaluated = parseAndEvaluate.apply(aspStr);
Set<AnswerSet> answerSets = solveCompiledProg.apply(evaluated);
TestUtils.assertAnswerSetsEqual("a(1), a(2), a(3), b(1), c(2), d(3)", answerSets);
}
use of at.ac.tuwien.kr.alpha.core.programs.CompiledProgram 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