Search in sources :

Example 1 with AlphaImpl

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);
}
Also used : AlphaImpl(at.ac.tuwien.kr.alpha.api.impl.AlphaImpl) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) DependencyGraph(at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph) DebugSolvingContext(at.ac.tuwien.kr.alpha.api.DebugSolvingContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 2 with AlphaImpl

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);
}
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 3 with AlphaImpl

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);
}
Also used : AlphaImpl(at.ac.tuwien.kr.alpha.api.impl.AlphaImpl) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.jupiter.api.Test)

Example 4 with AlphaImpl

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);
}
Also used : ComponentGraph(at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph) AlphaImpl(at.ac.tuwien.kr.alpha.api.impl.AlphaImpl) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) DebugSolvingContext(at.ac.tuwien.kr.alpha.api.DebugSolvingContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

Alpha (at.ac.tuwien.kr.alpha.api.Alpha)4 AlphaImpl (at.ac.tuwien.kr.alpha.api.impl.AlphaImpl)4 DebugSolvingContext (at.ac.tuwien.kr.alpha.api.DebugSolvingContext)3 Test (org.junit.jupiter.api.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)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 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)1 ComponentGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph)1 DependencyGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph)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 Workbook (org.apache.poi.ss.usermodel.Workbook)1