Search in sources :

Example 1 with CommandLineParser

use of at.ac.tuwien.kr.alpha.app.config.CommandLineParser 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)

Aggregations

Alpha (at.ac.tuwien.kr.alpha.api.Alpha)1 DebugSolvingContext (at.ac.tuwien.kr.alpha.api.DebugSolvingContext)1 Solver (at.ac.tuwien.kr.alpha.api.Solver)1 StatisticsReportingSolver (at.ac.tuwien.kr.alpha.api.StatisticsReportingSolver)1 AlphaConfig (at.ac.tuwien.kr.alpha.api.config.AlphaConfig)1 InputConfig (at.ac.tuwien.kr.alpha.api.config.InputConfig)1 AlphaImpl (at.ac.tuwien.kr.alpha.api.impl.AlphaImpl)1 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)1 CommandLineParser (at.ac.tuwien.kr.alpha.app.config.CommandLineParser)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ParseException (org.apache.commons.cli.ParseException)1