Search in sources :

Example 76 with ASPCore2Program

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

the class DependencyGraphImplTest method reachabilityCheckSimpleTest.

@Test
public void reachabilityCheckSimpleTest() {
    ASPCore2Program prog = parser.parse("b :- a.");
    NormalProgram normalProg = normalizeTransform.apply(prog);
    AnalyzedProgram analyzed = AnalyzedProgram.analyzeNormalProgram(normalProg);
    DependencyGraph dg = analyzed.getDependencyGraph();
    Node a = dg.getNodeForPredicate(Predicates.getPredicate("a", 0));
    Node b = dg.getNodeForPredicate(Predicates.getPredicate("b", 0));
    NodeImpl nonExistent = new NodeImpl(Predicates.getPredicate("notHere", 0));
    assertTrue(DependencyGraphUtils.isReachableFrom(a, a, dg));
    assertTrue(DependencyGraphUtils.isReachableFrom(b, a, dg));
    assertFalse(DependencyGraphUtils.isReachableFrom(a, b, dg));
    assertFalse(DependencyGraphUtils.isReachableFrom(nonExistent, a, dg));
    assertFalse(DependencyGraphUtils.isReachableFrom(nonExistent, b, dg));
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) AnalyzedProgram(at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram) Node(at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph.Node) NormalProgram(at.ac.tuwien.kr.alpha.api.programs.NormalProgram) DependencyGraph(at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph) Test(org.junit.jupiter.api.Test)

Example 77 with ASPCore2Program

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

the class NaiveGrounderTest method testPermissiveGrounderHeuristicTolerance_1_accept_accept_two_substitutions_with_different_remaining_tolerances.

@Test
public void testPermissiveGrounderHeuristicTolerance_1_accept_accept_two_substitutions_with_different_remaining_tolerances() {
    ASPCore2Program program = PROGRAM_PARSER.parse("a(1). " + "c(X) :- a(1), b(X,Y). " + "b(X,Y) :- something(X,Y).");
    testPermissiveGrounderHeuristicTolerance(program, 0, litA1, 1, 1, new ThriceTruth[] { null, null }, 2, true, Arrays.asList(1, 1));
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) Test(org.junit.jupiter.api.Test)

Example 78 with ASPCore2Program

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

the class AlphaImpl method readProgramFiles.

@Override
public ASPCore2Program readProgramFiles(boolean literate, Map<String, PredicateInterpretation> externals, Path... paths) throws IOException {
    InputProgram.Builder prgBuilder = InputProgram.builder();
    ASPCore2Program tmpProg;
    for (Path path : paths) {
        InputStream stream;
        if (!literate) {
            stream = Files.newInputStream(path);
        } else {
            stream = Channels.newInputStream(Util.streamToChannel(Util.literate(Files.lines(path))));
        }
        tmpProg = parser.parse(stream, externals);
        prgBuilder.accumulate(tmpProg);
    }
    return prgBuilder.build();
}
Also used : Path(java.nio.file.Path) ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) InputStream(java.io.InputStream) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram)

Example 79 with ASPCore2Program

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

the class AlphaImplTest method filterOutput.

@Test
public void filterOutput() throws Exception {
    Alpha system = new AlphaImpl();
    InputConfig inputCfg = InputConfig.forString("node(1). node(2). outgoing13(X) :- node(X), &getLargeGraphEdges(13,X).");
    inputCfg.addPredicateMethod("getLargeGraphEdges", Externals.processPredicate(() -> new HashSet<>(asList(asList(Terms.newConstant(1), Terms.newConstant(2)), asList(Terms.newConstant(2), Terms.newConstant(1)), asList(Terms.newConstant(13), Terms.newConstant(1))))));
    ASPCore2Program program = system.readProgram(inputCfg);
    Set<AnswerSet> actual = system.solve(program).collect(Collectors.toSet());
    Set<AnswerSet> expected = AnswerSetsParser.parse("{ node(1), node(2), outgoing13(1) }");
    assertEquals(expected, actual);
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 80 with ASPCore2Program

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

the class AlphaImplTest method problematicRun.

private void problematicRun(String program, long seed, int limit) throws IOException {
    final Path base = Paths.get("src", "test", "resources", "PreviouslyProblematic");
    SystemConfig cfg = new SystemConfig();
    cfg.setGrounderName("naive");
    cfg.setSolverName("default");
    cfg.setNogoodStoreName("alpharoaming");
    cfg.setDebugInternalChecks(true);
    cfg.setSeed(seed);
    final Alpha system = new AlphaImpl(cfg);
    InputConfig inputCfg = new InputConfig();
    List<String> files = new ArrayList<>();
    files.add(base.resolve(program).toString());
    inputCfg.setFiles(files);
    ASPCore2Program prog = system.readProgram(inputCfg);
    assertFalse(system.solve(prog).limit(limit).collect(Collectors.toList()).isEmpty());
}
Also used : Path(java.nio.file.Path) ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) ArrayList(java.util.ArrayList) InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig)

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