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
}
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();
}
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);
}
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;
}
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());
}
Aggregations