Search in sources :

Example 6 with AnswerSet

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

the class StratifiedEvaluationRegressionTest method runTest.

@ParameterizedTest
@MethodSource("at.ac.tuwien.kr.alpha.core.programs.transformation.StratifiedEvaluationRegressionTest#params")
public void runTest(String aspString, Consumer<CompiledProgram> programVerifier, Consumer<Set<AnswerSet>> resultVerifier) {
    // Parse and pre-evaulate program
    ProgramParser parser = new ProgramParserImpl();
    ASPCore2Program prog = parser.parse(aspString);
    AnalyzedProgram analyzed = AnalyzedProgram.analyzeNormalProgram(new NormalizeProgramTransformation(SystemConfig.DEFAULT_AGGREGATE_REWRITING_CONFIG).apply(prog));
    CompiledProgram evaluated = new StratifiedEvaluation().apply(analyzed);
    // Verify stratified evaluation result
    programVerifier.accept(evaluated);
    // Solve remaining program
    AtomStore atomStore = new AtomStoreImpl();
    Grounder grounder = GrounderFactory.getInstance("naive", evaluated, atomStore, false);
    Solver solver = SolverFactory.getInstance(new SystemConfig(), atomStore, grounder);
    Set<AnswerSet> answerSets = solver.collectSet();
    resultVerifier.accept(answerSets);
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) Solver(at.ac.tuwien.kr.alpha.api.Solver) SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) AnalyzedProgram(at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram) ProgramParser(at.ac.tuwien.kr.alpha.api.programs.ProgramParser) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) AtomStoreImpl(at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) AtomStore(at.ac.tuwien.kr.alpha.core.common.AtomStore) Grounder(at.ac.tuwien.kr.alpha.core.grounder.Grounder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with AnswerSet

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

the class AggregateRewritingTest method countLeSortingGridSimple.

// @formatter:on
@Test
public void countLeSortingGridSimple() {
    List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(CNT_LE1_ASP);
    assertEquals(1, answerSets.size());
    AnswerSet answerSet = answerSets.get(0);
    Predicate thing = Predicates.getPredicate("thing", 1);
    Predicate candidate = Predicates.getPredicate("candidate", 1);
    Predicate cntLe = Predicates.getPredicate("cnt_le", 1);
    // System.out.println(new SimpleAnswerSetFormatter("\n").format(answerSet));
    assertTrue(answerSet.getPredicateInstances(thing).contains(Atoms.newBasicAtom(thing, Terms.newConstant(75))));
    assertTrue(answerSet.getPredicateInstances(thing).contains(Atoms.newBasicAtom(thing, Terms.newConstant(76))));
    assertTrue(answerSet.getPredicateInstances(candidate).contains(Atoms.newBasicAtom(candidate, Terms.newConstant(2))));
    assertTrue(answerSet.getPredicateInstances(candidate).contains(Atoms.newBasicAtom(candidate, Terms.newConstant(3))));
    assertTrue(answerSet.getPredicateInstances(candidate).contains(Atoms.newBasicAtom(candidate, Terms.newConstant(4))));
    assertTrue(answerSet.getPredicates().contains(cntLe));
    assertTrue(answerSet.getPredicateInstances(cntLe).contains(Atoms.newBasicAtom(cntLe, Terms.newConstant(2))));
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate) Test(org.junit.jupiter.api.Test)

Example 8 with AnswerSet

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

the class AggregateRewritingTest method countEqGlobalVars.

@Test
public void countEqGlobalVars() {
    List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(VERTEX_DEGREE_ASP);
    assertEquals(1, answerSets.size());
    AnswerSet answerSet = answerSets.get(0);
    Predicate vertexDegree = Predicates.getPredicate("graph_vertex_degree", 3);
    // System.out.println(new SimpleAnswerSetFormatter("\n").format(answerSet));
    assertTrue(answerSet.getPredicates().contains(vertexDegree));
    assertTrue(answerSet.getPredicateInstances(vertexDegree).contains(Atoms.newBasicAtom(vertexDegree, Terms.newSymbolicConstant("g1"), Terms.newConstant(1), Terms.newConstant(2))));
    assertTrue(answerSet.getPredicateInstances(vertexDegree).contains(Atoms.newBasicAtom(vertexDegree, Terms.newSymbolicConstant("g1"), Terms.newConstant(2), Terms.newConstant(2))));
    assertTrue(answerSet.getPredicateInstances(vertexDegree).contains(Atoms.newBasicAtom(vertexDegree, Terms.newSymbolicConstant("g1"), Terms.newConstant(3), Terms.newConstant(2))));
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate) Test(org.junit.jupiter.api.Test)

Example 9 with AnswerSet

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

the class AggregateRewritingTest method sumEquals1.

@Test
public void sumEquals1() {
    List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(SUM_EQ1_ASP);
    assertEquals(1, answerSets.size());
    AnswerSet answerSet = answerSets.get(0);
    Predicate sumThings = Predicates.getPredicate("sum_things", 1);
    // System.out.println(new SimpleAnswerSetFormatter("\n").format(answerSet));
    assertTrue(answerSet.getPredicates().contains(sumThings));
    assertEquals(1, answerSet.getPredicateInstances(sumThings).size());
    assertTrue(answerSet.getPredicateInstances(sumThings).contains(Atoms.newBasicAtom(sumThings, Terms.newConstant(12))));
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate) Test(org.junit.jupiter.api.Test)

Example 10 with AnswerSet

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

the class AggregateRewritingTest method countEqSimple.

@Test
public void countEqSimple() {
    List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(CNT_EQ1_ASP);
    assertEquals(1, answerSets.size());
    AnswerSet answerSet = answerSets.get(0);
    Predicate thing = Predicates.getPredicate("thing", 1);
    Predicate cntThings = Predicates.getPredicate("cnt_things", 1);
    // System.out.println(new SimpleAnswerSetFormatter("\n").format(answerSet));
    assertTrue(answerSet.getPredicateInstances(thing).contains(Atoms.newBasicAtom(thing, Terms.newConstant(4))));
    assertTrue(answerSet.getPredicateInstances(thing).contains(Atoms.newBasicAtom(thing, Terms.newConstant(5))));
    assertTrue(answerSet.getPredicateInstances(thing).contains(Atoms.newBasicAtom(thing, Terms.newConstant(6))));
    assertTrue(answerSet.getPredicates().contains(cntThings));
    assertTrue(answerSet.getPredicateInstances(cntThings).contains(Atoms.newBasicAtom(cntThings, Terms.newConstant(3))));
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate) 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