Search in sources :

Example 1 with Solver

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);
}
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 2 with Solver

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);
}
Also used : Solver(at.ac.tuwien.kr.alpha.api.Solver) StatisticsReportingSolver(at.ac.tuwien.kr.alpha.api.StatisticsReportingSolver) StatisticsReportingSolver(at.ac.tuwien.kr.alpha.api.StatisticsReportingSolver) DummyGrounder(at.ac.tuwien.kr.alpha.core.grounder.DummyGrounder) TestUtils.buildSolverForRegressionTest(at.ac.tuwien.kr.alpha.core.test.util.TestUtils.buildSolverForRegressionTest)

Example 3 with Solver

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
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) Solver(at.ac.tuwien.kr.alpha.api.Solver) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram)

Example 4 with Solver

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
}
Also used : Solver(at.ac.tuwien.kr.alpha.api.Solver) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) CharStream(org.antlr.v4.runtime.CharStream)

Example 5 with Solver

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));
}
Also used : Solver(at.ac.tuwien.kr.alpha.api.Solver) TestUtils.assertRegressionTestAnswerSet(at.ac.tuwien.kr.alpha.core.test.util.TestUtils.assertRegressionTestAnswerSet) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) TestUtils.buildSolverForRegressionTest(at.ac.tuwien.kr.alpha.core.test.util.TestUtils.buildSolverForRegressionTest)

Aggregations

Solver (at.ac.tuwien.kr.alpha.api.Solver)14 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)8 StatisticsReportingSolver (at.ac.tuwien.kr.alpha.api.StatisticsReportingSolver)6 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)6 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)5 TestUtils.buildSolverForRegressionTest (at.ac.tuwien.kr.alpha.core.test.util.TestUtils.buildSolverForRegressionTest)5 DebugSolvingContext (at.ac.tuwien.kr.alpha.api.DebugSolvingContext)3 Alpha (at.ac.tuwien.kr.alpha.api.Alpha)2 AlphaConfig (at.ac.tuwien.kr.alpha.api.config.AlphaConfig)2 InputConfig (at.ac.tuwien.kr.alpha.api.config.InputConfig)2 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)2 AlphaImpl (at.ac.tuwien.kr.alpha.api.impl.AlphaImpl)2 NormalProgram (at.ac.tuwien.kr.alpha.api.programs.NormalProgram)2 ComponentGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph)2 DependencyGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph)2 CommandLineParser (at.ac.tuwien.kr.alpha.app.config.CommandLineParser)2 DummyGrounder (at.ac.tuwien.kr.alpha.core.grounder.DummyGrounder)2 AnalyzedProgram (at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram)2 InputProgram (at.ac.tuwien.kr.alpha.core.programs.InputProgram)2 FileNotFoundException (java.io.FileNotFoundException)2