Search in sources :

Example 1 with AnswerSet

use of at.ac.tuwien.kr.alpha.api.AnswerSet 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 AnswerSet

use of at.ac.tuwien.kr.alpha.api.AnswerSet 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 AnswerSet

use of at.ac.tuwien.kr.alpha.api.AnswerSet 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 4 with AnswerSet

use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.

the class StratifiedEvaluationTest method testNonGroundableRule.

@Test
public void testNonGroundableRule() {
    String asp = "p(a). q(a, b). s(X, Y) :- p(X), q(X, Y), r(Y).";
    CompiledProgram evaluated = parseAndEvaluate.apply(asp);
    Set<AnswerSet> answerSets = solveCompiledProg.apply(evaluated);
    TestUtils.assertAnswerSetsEqual("p(a), q(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 AnswerSet

use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.

the class StratifiedEvaluationTest method testNegatedFixedInterpretationLiteral.

@Test
public void testNegatedFixedInterpretationLiteral() {
    String asp = "stuff(1). stuff(2). smallStuff(X) :- stuff(X), not X > 1.";
    CompiledProgram evaluated = parseAndEvaluate.apply(asp);
    Set<AnswerSet> answerSets = solveCompiledProg.apply(evaluated);
    TestUtils.assertAnswerSetsEqual("stuff(1), stuff(2), smallStuff(1)", 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)

Aggregations

AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)80 Test (org.junit.jupiter.api.Test)64 Alpha (at.ac.tuwien.kr.alpha.api.Alpha)25 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)24 AnswerSetBuilder (at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder)20 InputConfig (at.ac.tuwien.kr.alpha.api.config.InputConfig)17 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)14 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)14 HashSet (java.util.HashSet)13 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)10 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)9 Solver (at.ac.tuwien.kr.alpha.api.Solver)8 InputProgram (at.ac.tuwien.kr.alpha.core.programs.InputProgram)7 Disabled (org.junit.jupiter.api.Disabled)7 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)4 ProgramParser (at.ac.tuwien.kr.alpha.api.programs.ProgramParser)4 ConstantTerm (at.ac.tuwien.kr.alpha.api.terms.ConstantTerm)4 TestUtils.assertRegressionTestAnswerSet (at.ac.tuwien.kr.alpha.core.test.util.TestUtils.assertRegressionTestAnswerSet)4 TestUtils.buildSolverForRegressionTest (at.ac.tuwien.kr.alpha.core.test.util.TestUtils.buildSolverForRegressionTest)4 HashMap (java.util.HashMap)4