use of at.ac.tuwien.kr.alpha.core.programs.CompiledProgram in project Alpha by alpha-asp.
the class StratifiedEvaluationTest method testIntervalFact.
@Test
public void testIntervalFact() {
String asp = "a(1..3).";
CompiledProgram evaluated = parseAndEvaluate.apply(asp);
Set<AnswerSet> answerSets = solveCompiledProg.apply(evaluated);
TestUtils.assertAnswerSetsEqual("a(1), a(2), a(3)", answerSets);
}
use of at.ac.tuwien.kr.alpha.core.programs.CompiledProgram in project Alpha by alpha-asp.
the class StratifiedEvaluationTest method testNegatedExternalLiteral.
@Test
public void testNegatedExternalLiteral() throws Exception {
String asp = "claimedTruth(bla). truth(X) :- claimedTruth(X), &sayTrue[X]. lie(X) :- claimedTruth(X), not &sayTrue[X].";
Map<String, PredicateInterpretation> externals = new HashMap<>();
externals.put("sayTrue", Externals.processPredicateMethod(this.getClass().getMethod("sayTrue", Object.class)));
ProgramParser parserWithExternals = new ProgramParserImpl();
AnalyzedProgram analyzed = AnalyzedProgram.analyzeNormalProgram(normalizer.apply(parserWithExternals.parse(asp, externals)));
CompiledProgram evaluated = new StratifiedEvaluation().apply(analyzed);
Set<AnswerSet> answerSets = solveCompiledProg.apply(evaluated);
TestUtils.assertAnswerSetsEqual("claimedTruth(bla), truth(bla)", answerSets);
}
use of at.ac.tuwien.kr.alpha.core.programs.CompiledProgram in project Alpha by alpha-asp.
the class StratifiedEvaluationTest method testRecursiveRanking.
@Test
public void testRecursiveRanking() {
// @formatter:off
String asp = "thing(a).\n" + "thing(b).\n" + "thing(c).\n" + "thing_before(a, b).\n" + "thing_before(b, c).\n" + "has_prev_thing(X) :- thing(X), thing_succ(_, X).\n" + "first_thing(X) :- thing(X), not has_prev_thing(X).\n" + "thing_not_succ(X, Y) :-\n" + " thing(X),\n" + " thing(Y),\n" + " thing(INTM),\n" + " thing_before(X, Y),\n" + " thing_before(X, INTM),\n" + " thing_before(INTM, X).\n" + "thing_succ(X, Y) :-\n" + " thing(X),\n" + " thing(Y),\n" + " thing_before(X, Y),\n" + " not thing_not_succ(X, Y).\n" + "thing_rank(X, 1) :- first_thing(X).\n" + "thing_rank(X, R) :-\n" + " thing(X),\n" + " thing_succ(Y, X),\n" + " thing_rank(Y, K),\n" + " R = K + 1.";
// @formatter:on
CompiledProgram evaluated = parseAndEvaluate.apply(asp);
Predicate rank = Predicates.getPredicate("thing_rank", 2);
BasicAtom rank1 = Atoms.newBasicAtom(rank, Terms.newSymbolicConstant("a"), Terms.newConstant(1));
BasicAtom rank2 = Atoms.newBasicAtom(rank, Terms.newSymbolicConstant("b"), Terms.newConstant(2));
BasicAtom rank3 = Atoms.newBasicAtom(rank, Terms.newSymbolicConstant("c"), Terms.newConstant(3));
List<Atom> evaluatedFacts = evaluated.getFacts();
assertTrue(evaluatedFacts.contains(rank1));
assertTrue(evaluatedFacts.contains(rank2));
assertTrue(evaluatedFacts.contains(rank3));
}
use of at.ac.tuwien.kr.alpha.core.programs.CompiledProgram in project Alpha by alpha-asp.
the class StratifiedEvaluationTest method testCountAggregate.
@Test
public void testCountAggregate() {
String asp = "a. b :- 1 <= #count { 1 : a }.";
CompiledProgram evaluated = parseAndEvaluate.apply(asp);
Set<AnswerSet> answerSets = solveCompiledProg.apply(evaluated);
TestUtils.assertAnswerSetsEqual("a, b", answerSets);
}
use of at.ac.tuwien.kr.alpha.core.programs.CompiledProgram in project Alpha by alpha-asp.
the class StratifiedEvaluationTest method testEqualityWithConstantTerms.
@Test
public void testEqualityWithConstantTerms() {
String aspStr = "equal :- 1 = 1.";
CompiledProgram evaluated = parseAndEvaluate.apply(aspStr);
Atom equal = TestUtils.basicAtomWithSymbolicTerms("equal");
assertTrue(evaluated.getFacts().contains(equal));
}
Aggregations