Search in sources :

Example 1 with Grounder

use of at.ac.tuwien.kr.alpha.core.grounder.Grounder 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 Grounder

use of at.ac.tuwien.kr.alpha.core.grounder.Grounder in project Alpha by alpha-asp.

the class AlphaImpl method prepareSolverFor.

/**
 * Prepares a solver (and accompanying grounder) instance pre-loaded with the given program. Use this if the
 * solver is needed after reading answer sets (e.g. for obtaining statistics).
 *
 * @param program the program to solve.
 * @param filter  a (java util) predicate that filters (asp-)predicates which should be contained in the answer
 *                set stream from the solver.
 * @return a solver (and accompanying grounder) instance pre-loaded with the given program.
 */
private Solver prepareSolverFor(CompiledProgram program, java.util.function.Predicate<Predicate> filter) {
    String grounderName = config.getGrounderName();
    boolean doDebugChecks = config.isDebugInternalChecks();
    GrounderHeuristicsConfiguration grounderHeuristicConfiguration = GrounderHeuristicsConfiguration.getInstance(config.getGrounderToleranceConstraints(), config.getGrounderToleranceRules());
    grounderHeuristicConfiguration.setAccumulatorEnabled(config.isGrounderAccumulatorEnabled());
    AtomStore atomStore = new AtomStoreImpl();
    Grounder grounder = GrounderFactory.getInstance(grounderName, program, atomStore, filter, grounderHeuristicConfiguration, doDebugChecks);
    return SolverFactory.getInstance(config, atomStore, grounder);
}
Also used : AtomStore(at.ac.tuwien.kr.alpha.core.common.AtomStore) GrounderHeuristicsConfiguration(at.ac.tuwien.kr.alpha.api.config.GrounderHeuristicsConfiguration) AtomStoreImpl(at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl) Grounder(at.ac.tuwien.kr.alpha.core.grounder.Grounder)

Aggregations

AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)2 AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)2 Grounder (at.ac.tuwien.kr.alpha.core.grounder.Grounder)2 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)1 Solver (at.ac.tuwien.kr.alpha.api.Solver)1 GrounderHeuristicsConfiguration (at.ac.tuwien.kr.alpha.api.config.GrounderHeuristicsConfiguration)1 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)1 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)1 ProgramParser (at.ac.tuwien.kr.alpha.api.programs.ProgramParser)1 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)1 AnalyzedProgram (at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram)1 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1