use of at.ac.tuwien.kr.alpha.api.impl.AlphaImpl in project Alpha by alpha-asp.
the class DependencyGraphWriterTest method smokeTest.
@Test
public void smokeTest() {
// Note: rather than testing correct implementation of dot file format,
// (which would be a lot of work), just test correct dot code generation
// for one dependency graph that has all possible "special" node constellations,
// i.e. positive and negative dependencies, cycle through negation, constraints.
String asp = "p(X) :- q(X), r(X)." + LS + "s(X) :- p(X), q(X), not r(X)." + LS + "t(X) :- p(X), not u(X)." + LS + "u(X) :- p(X), not t(X)." + LS + ":- p(X), not q(X), not r(X).";
String expectedGraph = "digraph dependencyGraph" + LS + "{" + LS + "splines=false;" + LS + "ranksep=4.0;" + LS + "n0 [label = \"r/1\"]" + LS + "n1 [label = \"q/1\"]" + LS + "n2 [label = \"t/1\"]" + LS + "n3 [label = \"s/1\"]" + LS + "n4 [label = \"u/1\"]" + LS + "n5 [label = \"[constr_1]/0\"]" + LS + "n6 [label = \"p/1\"]" + LS + "n0 -> n6 [xlabel=\"+\" labeldistance=0.1]" + LS + "n0 -> n3 [xlabel=\"-\" labeldistance=0.1]" + LS + "n0 -> n5 [xlabel=\"-\" labeldistance=0.1]" + LS + "n1 -> n6 [xlabel=\"+\" labeldistance=0.1]" + LS + "n1 -> n3 [xlabel=\"+\" labeldistance=0.1]" + LS + "n1 -> n5 [xlabel=\"-\" labeldistance=0.1]" + LS + "n2 -> n4 [xlabel=\"-\" labeldistance=0.1]" + LS + "n4 -> n2 [xlabel=\"-\" labeldistance=0.1]" + LS + "n5 -> n5 [xlabel=\"-\" labeldistance=0.1]" + LS + "n6 -> n3 [xlabel=\"+\" labeldistance=0.1]" + LS + "n6 -> n2 [xlabel=\"+\" labeldistance=0.1]" + LS + "n6 -> n4 [xlabel=\"+\" labeldistance=0.1]" + LS + "n6 -> n5 [xlabel=\"+\" labeldistance=0.1]" + LS + "}" + LS;
Alpha alpha = new AlphaImpl();
DebugSolvingContext dbgResult = alpha.prepareDebugSolve(alpha.readProgramString(asp));
DependencyGraph depgraph = dbgResult.getDependencyGraph();
DependencyGraphWriter writer = new DependencyGraphWriter();
ByteArrayOutputStream out = new ByteArrayOutputStream();
writer.writeAsDot(depgraph, out);
String actualGraph = out.toString();
assertEquals(expectedGraph, actualGraph);
}
use of at.ac.tuwien.kr.alpha.api.impl.AlphaImpl 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.impl.AlphaImpl in project Alpha by alpha-asp.
the class AnswerSetToWorkbookMapperTest method solveAndWriteWorkbookTest.
@Test
public void solveAndWriteWorkbookTest() {
// @formatter:off
String progstr = "aFlag. oneMoreFlag. yetAnotherFlag. createPs. maxP(5). r(s(1, 2, 3), 4). r(bla, blubb). r(foo, bar(baaz))." + "p(0) :- createPs. " + "p(N) :- p(I), N = I + 1, N <= MX, maxP(MX)." + "q(A, B) :- p(A), p(B).";
// @formatter:on
Alpha alpha = new AlphaImpl();
List<AnswerSet> answerSets = alpha.solve(alpha.readProgramString(progstr)).collect(Collectors.toList());
assertEquals(1, answerSets.size());
AnswerSet as = answerSets.get(0);
Workbook answerSetWorkbook = this.mapper.mapFromAnswerSet(as);
AnswerSetToWorkbookMapperTest.assertWorkbookMatchesAnswerSet(answerSetWorkbook, as);
}
use of at.ac.tuwien.kr.alpha.api.impl.AlphaImpl in project Alpha by alpha-asp.
the class ComponentGraphWriterTest method smokeTest.
@Test
public void smokeTest() {
// Note: rather than testing correct implementation of dot file format,
// (which would be a lot of work), just test correct dot code generation
// for one component graph that has all possible "special" node constellations,
// i.e. positive and negative dependencies, cycle through negation, constraints.
String asp = "p(X) :- q(X), r(X)." + LS + "s(X) :- p(X), q(X), not r(X)." + LS + "t(X) :- p(X), not u(X)." + LS + "u(X) :- p(X), not t(X)." + LS + ":- p(X), not q(X), not r(X).";
String expectedGraph = "digraph componentGraph" + LS + "{" + LS + "splines=false;" + LS + "ranksep=4.0;" + LS + "label = <" + LS + " <table border = '1' cellborder = '0'>" + LS + " <tr><td>Component Id</td><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td></tr>" + LS + " <tr><td>Predicates</td><td>q/1<br/></td><td>r/1<br/></td><td>p/1<br/></td><td>[constr_1]/0<br/></td><td>t/1<br/>u/1<br/></td><td>s/1<br/></td></tr>" + LS + " </table>" + LS + ">" + LS + "" + LS + "n0 [label = C0]" + LS + "n1 [label = C1]" + LS + "n2 [label = C2]" + LS + "n0 -> n2 [xlabel=\"+\" labeldistance=0.1]" + LS + "n1 -> n2 [xlabel=\"+\" labeldistance=0.1]" + LS + "n3 [label = C3]" + LS + "n0 -> n3 [xlabel=\"-\" labeldistance=0.1]" + LS + "n1 -> n3 [xlabel=\"-\" labeldistance=0.1]" + LS + "n2 -> n3 [xlabel=\"+\" labeldistance=0.1]" + LS + "n4 [label = C4]" + LS + "n2 -> n4 [xlabel=\"+\" labeldistance=0.1]" + LS + "n5 [label = C5]" + LS + "n0 -> n5 [xlabel=\"+\" labeldistance=0.1]" + LS + "n1 -> n5 [xlabel=\"-\" labeldistance=0.1]" + LS + "n2 -> n5 [xlabel=\"+\" labeldistance=0.1]" + LS + "}" + LS;
Alpha alpha = new AlphaImpl();
DebugSolvingContext dbgResult = alpha.prepareDebugSolve(alpha.readProgramString(asp));
ComponentGraph compgraph = dbgResult.getComponentGraph();
ComponentGraphWriter writer = new ComponentGraphWriter();
ByteArrayOutputStream out = new ByteArrayOutputStream();
writer.writeAsDot(compgraph, out);
String actualGraph = out.toString();
System.out.println(actualGraph);
assertEquals(expectedGraph, actualGraph);
}
Aggregations