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);
}
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))));
}
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))));
}
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))));
}
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))));
}
Aggregations