Search in sources :

Example 16 with AnalyzedProgram

use of at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram 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 17 with AnalyzedProgram

use of at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram in project Alpha by alpha-asp.

the class AlphaImpl method prepareDebugSolve.

@Override
public DebugSolvingContext prepareDebugSolve(final NormalProgram program, java.util.function.Predicate<Predicate> filter) {
    final DependencyGraph depGraph;
    final ComponentGraph compGraph;
    final AnalyzedProgram analyzed = AnalyzedProgram.analyzeNormalProgram(program);
    final NormalProgram preprocessed;
    if (this.config.isEvaluateStratifiedPart()) {
        preprocessed = new StratifiedEvaluation().apply(analyzed).toNormalProgram();
    } else {
        preprocessed = program;
    }
    depGraph = analyzed.getDependencyGraph();
    compGraph = analyzed.getComponentGraph();
    final Solver solver = prepareSolverFor(analyzed, filter);
    return new DebugSolvingContext() {

        @Override
        public Solver getSolver() {
            return solver;
        }

        @Override
        public NormalProgram getPreprocessedProgram() {
            return preprocessed;
        }

        @Override
        public NormalProgram getNormalizedProgram() {
            return program;
        }

        @Override
        public DependencyGraph getDependencyGraph() {
            return depGraph;
        }

        @Override
        public ComponentGraph getComponentGraph() {
            return compGraph;
        }
    };
}
Also used : ComponentGraph(at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph) Solver(at.ac.tuwien.kr.alpha.api.Solver) AnalyzedProgram(at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram) NormalProgram(at.ac.tuwien.kr.alpha.api.programs.NormalProgram) DependencyGraph(at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph) DebugSolvingContext(at.ac.tuwien.kr.alpha.api.DebugSolvingContext) StratifiedEvaluation(at.ac.tuwien.kr.alpha.core.programs.transformation.StratifiedEvaluation)

Aggregations

AnalyzedProgram (at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram)17 DependencyGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph)14 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)13 NormalProgram (at.ac.tuwien.kr.alpha.api.programs.NormalProgram)13 Test (org.junit.jupiter.api.Test)13 ComponentGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph)9 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)8 SCComponent (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph.SCComponent)7 Node (at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph.Node)5 ArrayList (java.util.ArrayList)3 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)2 Solver (at.ac.tuwien.kr.alpha.api.Solver)2 ProgramParser (at.ac.tuwien.kr.alpha.api.programs.ProgramParser)2 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)2 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)2 InternalProgram (at.ac.tuwien.kr.alpha.core.programs.InternalProgram)2 StratifiedEvaluation (at.ac.tuwien.kr.alpha.core.programs.transformation.StratifiedEvaluation)2 HashMap (java.util.HashMap)2 List (java.util.List)2 DebugSolvingContext (at.ac.tuwien.kr.alpha.api.DebugSolvingContext)1