use of at.ac.tuwien.kr.alpha.api.Solver 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.Solver in project Alpha by alpha-asp.
the class SolverStatisticsTests method checkNoGoodCounterStatsByCardinalityUsingDummyGrounder.
@RegressionTest
public void checkNoGoodCounterStatsByCardinalityUsingDummyGrounder(RegressionTestConfig cfg) {
Solver solver = buildSolverForRegressionTest(atomStore, new DummyGrounder(atomStore), cfg);
assumeTrue(solver instanceof StatisticsReportingSolver);
collectAnswerSetsAndCheckNoGoodCounterStatsByCardinality(solver, 2, 1, 1);
}
use of at.ac.tuwien.kr.alpha.api.Solver in project Alpha by alpha-asp.
the class ThreeColouringTestWithRandom method testThreeColouring.
private void testThreeColouring(int n, boolean shuffle, int seed, RegressionTestConfig cfg) {
ASPCore2Program tmpPrg = new ProgramParserImpl().parse("col(V,C) :- v(V), c(C), not ncol(V,C)." + "ncol(V,C) :- col(V,D), c(C), C != D." + ":- e(V,U), col(V,C), col(U,C).");
InputProgram.Builder prgBuilder = InputProgram.builder().accumulate(tmpPrg);
prgBuilder.addFacts(createColors("1", "2", "3"));
prgBuilder.addFacts(createVertices(n));
prgBuilder.addFacts(createEdges(n, shuffle, seed));
InputProgram program = prgBuilder.build();
Solver solver = buildSolverForRegressionTest(program, cfg);
@SuppressWarnings("unused") Optional<AnswerSet> answerSet = solver.stream().findAny();
// System.out.println(answerSet);
// TODO: check correctness of answer set
}
use of at.ac.tuwien.kr.alpha.api.Solver in project Alpha by alpha-asp.
the class RacksTest method test.
private void test(RegressionTestConfig cfg) throws IOException {
CharStream programInputStream = CharStreams.fromPath(Paths.get("benchmarks", "siemens", "racks", "racks.lp"));
Solver solver = buildSolverForRegressionTest(new ProgramParserImpl().parse(programInputStream), cfg);
@SuppressWarnings("unused") Optional<AnswerSet> answerSet = solver.stream().findFirst();
// System.out.println(answerSet);
// TODO: check correctness of answer set
}
use of at.ac.tuwien.kr.alpha.api.Solver in project Alpha by alpha-asp.
the class SolverTests method doubleChoiceRule.
@RegressionTest
public void doubleChoiceRule(RegressionTestConfig cfg) {
Solver solver = buildSolverForRegressionTest("{ a }. { a }.", cfg);
// Make sure that no superfluous answer sets that only differ on hidden atoms occur.
List<AnswerSet> actual = solver.collectList();
assertEquals(2, actual.size());
assertEquals(AnswerSetsParser.parse("{} { a }"), new HashSet<>(actual));
}
Aggregations