Search in sources :

Example 1 with CompiledProgram

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);
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) Test(org.junit.jupiter.api.Test)

Example 2 with CompiledProgram

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);
}
Also used : AnalyzedProgram(at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram) HashMap(java.util.HashMap) ProgramParser(at.ac.tuwien.kr.alpha.api.programs.ProgramParser) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) PredicateInterpretation(at.ac.tuwien.kr.alpha.api.common.fixedinterpretations.PredicateInterpretation) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) Test(org.junit.jupiter.api.Test)

Example 3 with CompiledProgram

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));
}
Also used : CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) BasicAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom) BasicAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate) Test(org.junit.jupiter.api.Test)

Example 4 with CompiledProgram

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);
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) Test(org.junit.jupiter.api.Test)

Example 5 with CompiledProgram

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));
}
Also used : CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) BasicAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Test(org.junit.jupiter.api.Test)

Aggregations

CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)33 Test (org.junit.jupiter.api.Test)30 AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)12 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)11 Literal (at.ac.tuwien.kr.alpha.api.programs.literals.Literal)11 AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)10 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)9 TrailAssignment (at.ac.tuwien.kr.alpha.core.solver.TrailAssignment)9 NormalProgram (at.ac.tuwien.kr.alpha.api.programs.NormalProgram)7 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)6 BasicAtom (at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom)6 NaiveGrounder (at.ac.tuwien.kr.alpha.core.grounder.NaiveGrounder)6 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)6 ProgramParser (at.ac.tuwien.kr.alpha.api.programs.ProgramParser)5 AnalyzedProgram (at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram)5 CompiledRule (at.ac.tuwien.kr.alpha.core.rules.CompiledRule)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Substitution (at.ac.tuwien.kr.alpha.api.grounder.Substitution)4 BasicSubstitution (at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution)4 Instance (at.ac.tuwien.kr.alpha.commons.substitutions.Instance)4