Search in sources :

Example 1 with SystemConfig

use of at.ac.tuwien.kr.alpha.api.config.SystemConfig 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 SystemConfig

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

the class AlphaImplTest method problematicRun_3col_1119718541727902_sorted_400.

/**
 * Runs a test that formerly caused some sort of exception.
 */
@Test
public void problematicRun_3col_1119718541727902_sorted_400() throws IOException {
    /*
		 * NOTE: This was constructed from the following commandline invocation:
		 * -DebugEnableInternalChecks -q -g naive -s default -sort -n 400 -i 3col-20-38.txt
		 */
    SystemConfig cfg = new SystemConfig();
    cfg.setGrounderName("naive");
    cfg.setSolverName("default");
    cfg.setNogoodStoreName("alpharoaming");
    cfg.setDebugInternalChecks(true);
    cfg.setSeed(1119718541727902L);
    final Alpha system = new AlphaImpl(cfg);
    final Path path = Paths.get("src", "test", "resources", "PreviouslyProblematic").resolve("3col-20-38.txt");
    InputConfig inputCfg = new InputConfig();
    List<String> files = new ArrayList<>();
    files.add(path.toString());
    inputCfg.setFiles(files);
    ASPCore2Program prog = system.readProgram(inputCfg);
    assertFalse(system.solve(prog).sorted().limit(400).collect(Collectors.toList()).isEmpty());
}
Also used : Path(java.nio.file.Path) ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) ArrayList(java.util.ArrayList) InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig) Test(org.junit.jupiter.api.Test)

Example 3 with SystemConfig

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

the class RegressionTestConfig method toSystemConfig.

public SystemConfig toSystemConfig() {
    SystemConfig retVal = new SystemConfig();
    retVal.setGrounderName(this.grounderName);
    retVal.setSolverName(this.solverName);
    retVal.setNogoodStoreName(this.noGoodStoreName);
    retVal.setSeed(this.seed);
    retVal.setBranchingHeuristic(this.branchingHeuristic);
    retVal.setDebugInternalChecks(this.debugChecks);
    retVal.setEvaluateStratifiedPart(this.evaluateStratifiedPart);
    retVal.setGrounderAccumulatorEnabled(this.disableInstanceRemoval);
    retVal.setGrounderToleranceRules(this.grounderToleranceRules);
    retVal.setGrounderToleranceConstraints(this.grounderToleranceConstraints);
    retVal.getAggregateRewritingConfig().setUseSortingGridEncoding(this.encodeAggregatesUsingSortingGrid);
    retVal.getAggregateRewritingConfig().setSupportNegativeValuesInSums(this.supportNegativeSumElements);
    return retVal;
}
Also used : SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig)

Example 4 with SystemConfig

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

the class AlphaImplTest method testLearnedUnaryNoGoodCausingOutOfOrderLiteralsConflict.

// Detailed reproduction test-case for github issue #239.
@Test
public void testLearnedUnaryNoGoodCausingOutOfOrderLiteralsConflict() throws IOException {
    final ProgramParser parser = new ProgramParserImpl();
    InputProgram.Builder bld = InputProgram.builder();
    bld.accumulate(parser.parse(Files.newInputStream(Paths.get("src", "test", "resources", "HanoiTower_Alpha.asp"), StandardOpenOption.READ)));
    bld.accumulate(parser.parse(Files.newInputStream(Paths.get("src", "test", "resources", "HanoiTower_instances", "simple.asp"), StandardOpenOption.READ)));
    InputProgram parsedProgram = bld.build();
    SystemConfig config = new SystemConfig();
    config.setSolverName("default");
    config.setNogoodStoreName("alpharoaming");
    config.setSeed(0);
    config.setBranchingHeuristic(Heuristic.valueOf("VSIDS"));
    config.setDebugInternalChecks(true);
    config.setDisableJustificationSearch(false);
    config.setEvaluateStratifiedPart(false);
    config.setReplayChoices(Arrays.asList(21, 26, 36, 56, 91, 96, 285, 166, 101, 290, 106, 451, 445, 439, 448, 433, 427, 442, 421, 415, 436, 409, 430, 397, 391, 424, 385, 379, 418, 373, 412, 406, 394, 388, 382, 245, 232, 208));
    Alpha alpha = new AlphaImpl(config);
    Optional<AnswerSet> answerSet = alpha.solve(parsedProgram).findFirst();
    assertTrue(answerSet.isPresent());
}
Also used : SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) ProgramParser(at.ac.tuwien.kr.alpha.api.programs.ProgramParser) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram) Test(org.junit.jupiter.api.Test)

Example 5 with SystemConfig

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

the class Main method computeAndConsumeAnswerSets.

private static void computeAndConsumeAnswerSets(Solver solver, AlphaConfig alphaCfg) {
    SystemConfig sysCfg = alphaCfg.getSystemConfig();
    InputConfig inputCfg = alphaCfg.getInputConfig();
    Stream<AnswerSet> stream = solver.stream();
    if (sysCfg.isSortAnswerSets()) {
        stream = stream.sorted();
    }
    int limit = inputCfg.getNumAnswerSets();
    if (limit > 0) {
        stream = stream.limit(limit);
    }
    if (!sysCfg.isQuiet()) {
        AtomicInteger counter = new AtomicInteger(0);
        final BiConsumer<Integer, AnswerSet> answerSetHandler;
        final AnswerSetFormatter<String> fmt = new SimpleAnswerSetFormatter(sysCfg.getAtomSeparator());
        BiConsumer<Integer, AnswerSet> stdoutPrinter = (n, as) -> {
            System.out.println("Answer set " + Integer.toString(n) + ":" + System.lineSeparator() + fmt.format(as));
        };
        if (inputCfg.isWriteAnswerSetsAsXlsx()) {
            BiConsumer<Integer, AnswerSet> xlsxWriter = new AnswerSetToXlsxWriter(inputCfg.getAnswerSetFileOutputPath());
            answerSetHandler = stdoutPrinter.andThen(xlsxWriter);
        } else {
            answerSetHandler = stdoutPrinter;
        }
        stream.forEach(as -> {
            int cnt = counter.incrementAndGet();
            answerSetHandler.accept(cnt, as);
        });
        if (counter.get() == 0) {
            System.out.println("UNSATISFIABLE");
            if (inputCfg.isWriteAnswerSetsAsXlsx()) {
                try {
                    AnswerSetToXlsxWriter.writeUnsatInfo(Paths.get(inputCfg.getAnswerSetFileOutputPath() + ".UNSAT.xlsx"));
                } catch (IOException ex) {
                    System.err.println("Failed writing unsat file!");
                }
            }
        } else {
            System.out.println("SATISFIABLE");
        }
    } else {
        // Note: Even though we are not consuming the result, we will still compute
        // answer sets.
        stream.collect(Collectors.toList());
    }
    if (sysCfg.isPrintStats()) {
        if (solver instanceof StatisticsReportingSolver) {
            ((StatisticsReportingSolver) solver).printStatistics();
        } else {
            // Note: Should not happen with proper validation of commandline args
            System.err.println("Solver of type " + solver.getClass().getSimpleName() + " does not support solving statistics!");
        }
    }
}
Also used : DependencyGraphWriter(at.ac.tuwien.kr.alpha.app.DependencyGraphWriter) DebugSolvingContext(at.ac.tuwien.kr.alpha.api.DebugSolvingContext) AnswerSetFormatter(at.ac.tuwien.kr.alpha.api.util.AnswerSetFormatter) LoggerFactory(org.slf4j.LoggerFactory) InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig) SimpleAnswerSetFormatter(at.ac.tuwien.kr.alpha.commons.util.SimpleAnswerSetFormatter) NormalProgram(at.ac.tuwien.kr.alpha.api.programs.NormalProgram) CommandLineParser(at.ac.tuwien.kr.alpha.app.config.CommandLineParser) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Solver(at.ac.tuwien.kr.alpha.api.Solver) AlphaConfig(at.ac.tuwien.kr.alpha.api.config.AlphaConfig) BiConsumer(java.util.function.BiConsumer) AlphaImpl(at.ac.tuwien.kr.alpha.api.impl.AlphaImpl) PrintStream(java.io.PrintStream) Logger(org.slf4j.Logger) DependencyGraph(at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) StatisticsReportingSolver(at.ac.tuwien.kr.alpha.api.StatisticsReportingSolver) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) ParseException(org.apache.commons.cli.ParseException) ComponentGraphWriter(at.ac.tuwien.kr.alpha.app.ComponentGraphWriter) SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) ComponentGraph(at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph) SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) StatisticsReportingSolver(at.ac.tuwien.kr.alpha.api.StatisticsReportingSolver) IOException(java.io.IOException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SimpleAnswerSetFormatter(at.ac.tuwien.kr.alpha.commons.util.SimpleAnswerSetFormatter) InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig)

Aggregations

SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)9 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)6 Alpha (at.ac.tuwien.kr.alpha.api.Alpha)4 InputConfig (at.ac.tuwien.kr.alpha.api.config.InputConfig)4 Test (org.junit.jupiter.api.Test)4 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)3 NormalProgram (at.ac.tuwien.kr.alpha.api.programs.NormalProgram)3 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)3 Solver (at.ac.tuwien.kr.alpha.api.Solver)2 AlphaConfig (at.ac.tuwien.kr.alpha.api.config.AlphaConfig)2 ProgramParser (at.ac.tuwien.kr.alpha.api.programs.ProgramParser)2 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 ParseException (org.apache.commons.cli.ParseException)2 DebugSolvingContext (at.ac.tuwien.kr.alpha.api.DebugSolvingContext)1 StatisticsReportingSolver (at.ac.tuwien.kr.alpha.api.StatisticsReportingSolver)1 AlphaImpl (at.ac.tuwien.kr.alpha.api.impl.AlphaImpl)1 ComponentGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph)1 DependencyGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph)1