Search in sources :

Example 46 with ASPCore2Program

use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.

the class ThreeColouringWheelTest method testThreeColouring.

private void testThreeColouring(int n, 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(tmpPrg);
    prgBuilder.addFacts(createColors("red", "blue", "green"));
    prgBuilder.addFacts(createVertices(n));
    prgBuilder.addFacts(createEdges(n));
    InputProgram program = prgBuilder.build();
    maybeShuffle(program);
    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 47 with ASPCore2Program

use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.

the class AlphaImpl method readProgram.

@Override
public ASPCore2Program readProgram(InputConfig cfg) throws IOException {
    InputProgram.Builder prgBuilder = InputProgram.builder();
    ASPCore2Program tmpProg;
    if (!cfg.getFiles().isEmpty()) {
        tmpProg = readProgramFiles(cfg.isLiterate(), cfg.getPredicateMethods(), cfg.getFiles());
        prgBuilder.accumulate(tmpProg);
    }
    if (!cfg.getAspStrings().isEmpty()) {
        tmpProg = readProgramString(StringUtils.join(cfg.getAspStrings(), System.lineSeparator()), cfg.getPredicateMethods());
        prgBuilder.accumulate(tmpProg);
    }
    return prgBuilder.build();
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram)

Example 48 with ASPCore2Program

use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.

the class Main method main.

public static void main(String[] args) {
    CommandLineParser commandLineParser = new CommandLineParser(Main.ALPHA_CALL_SYNTAX, (msg) -> Main.exitWithMessage(msg, 0));
    AlphaConfig cfg = null;
    try {
        cfg = commandLineParser.parseCommandLine(args);
    } catch (ParseException ex) {
        System.err.println("Invalid usage: " + ex.getMessage());
        Main.exitWithMessage(commandLineParser.getUsageMessage(), 1);
    }
    Alpha alpha = new AlphaImpl(cfg.getSystemConfig());
    ASPCore2Program program = null;
    try {
        program = alpha.readProgram(cfg.getInputConfig());
    } catch (FileNotFoundException e) {
        Main.bailOut(e.getMessage());
    } catch (IOException e) {
        Main.bailOut("Failed to parse program.", e);
    }
    InputConfig inputCfg = cfg.getInputConfig();
    Solver solver;
    if (inputCfg.isDebugPreprocessing()) {
        DebugSolvingContext dbgCtx = alpha.prepareDebugSolve(program);
        Main.writeNormalProgram(dbgCtx.getNormalizedProgram(), inputCfg.getNormalizedPath());
        Main.writeNormalProgram(dbgCtx.getPreprocessedProgram(), inputCfg.getPreprocessedPath());
        Main.writeDependencyGraph(dbgCtx.getDependencyGraph(), inputCfg.getDepgraphPath());
        Main.writeComponentGraph(dbgCtx.getComponentGraph(), inputCfg.getCompgraphPath());
        solver = dbgCtx.getSolver();
    } else {
        solver = alpha.prepareSolverFor(program, inputCfg.getFilter());
    }
    Main.computeAndConsumeAnswerSets(solver, cfg);
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) Solver(at.ac.tuwien.kr.alpha.api.Solver) StatisticsReportingSolver(at.ac.tuwien.kr.alpha.api.StatisticsReportingSolver) AlphaImpl(at.ac.tuwien.kr.alpha.api.impl.AlphaImpl) AlphaConfig(at.ac.tuwien.kr.alpha.api.config.AlphaConfig) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) FileNotFoundException(java.io.FileNotFoundException) InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig) CommandLineParser(at.ac.tuwien.kr.alpha.app.config.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) IOException(java.io.IOException) DebugSolvingContext(at.ac.tuwien.kr.alpha.api.DebugSolvingContext)

Example 49 with ASPCore2Program

use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.

the class AggregateRewritingContextTest method rewritingContextForAspString.

// @formatter:on
private static final AggregateRewritingContext rewritingContextForAspString(String asp) {
    ASPCore2Program program = new ProgramParserImpl().parse(asp);
    AggregateRewritingContext ctx = new AggregateRewritingContext();
    for (Rule<Head> rule : program.getRules()) {
        ctx.registerRule(rule);
    }
    return ctx;
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) Head(at.ac.tuwien.kr.alpha.api.rules.heads.Head) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)

Example 50 with ASPCore2Program

use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.

the class HanoiTowerTest method testHanoiTower.

private void testHanoiTower(String instance, RegressionTestConfig cfg) throws IOException {
    ASPCore2Program prog = new ProgramParserImpl().parse(Paths.get("src", "test", "resources", "HanoiTower_Alpha.asp"), Paths.get("src", "test", "resources", "HanoiTower_instances", instance + ".asp"));
    Solver solver = TestUtils.buildSolverForRegressionTest(prog, cfg);
    Optional<AnswerSet> answerSet = solver.stream().findFirst();
    assertTrue(answerSet.isPresent());
    checkGoal(prog, answerSet.get());
}
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)

Aggregations

ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)89 Test (org.junit.jupiter.api.Test)70 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)23 NormalProgram (at.ac.tuwien.kr.alpha.api.programs.NormalProgram)22 Alpha (at.ac.tuwien.kr.alpha.api.Alpha)21 InputConfig (at.ac.tuwien.kr.alpha.api.config.InputConfig)19 AnalyzedProgram (at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram)15 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)14 DependencyGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph)12 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)11 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)10 Disabled (org.junit.jupiter.api.Disabled)9 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)8 AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)8 InputProgram (at.ac.tuwien.kr.alpha.core.programs.InputProgram)8 HashSet (java.util.HashSet)8 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)7 ComponentGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph)7 SCComponent (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph.SCComponent)7 AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)7