Search in sources :

Example 21 with NormalProgram

use of at.ac.tuwien.kr.alpha.api.programs.NormalProgram 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)

Example 22 with NormalProgram

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

the class AlphaImplTest method disableStratifiedEvalTest.

/**
 * Verifies that no stratified evaluation is performed up-front when disabled in config.
 */
@Test
public void disableStratifiedEvalTest() {
    // Note: This might be cleaner if the test used the debugSolve method from the interface
    String progstr = "p(a). q(X) :- p(X).";
    SystemConfig cfg = new SystemConfig();
    cfg.setEvaluateStratifiedPart(false);
    AlphaImpl system = new AlphaImpl(cfg);
    ASPCore2Program input = system.readProgramString(progstr);
    NormalProgram normal = system.normalizeProgram(input);
    CompiledProgram preprocessed = system.performProgramPreprocessing(normal);
    assertFalse(preprocessed.getFacts().contains(Atoms.newBasicAtom(Predicates.getPredicate("q", 1), Terms.newSymbolicConstant("a"))), "Preprocessed program contains fact derived from stratifiable rule, but should not!");
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) NormalProgram(at.ac.tuwien.kr.alpha.api.programs.NormalProgram) CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) Test(org.junit.jupiter.api.Test)

Example 23 with NormalProgram

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

the class AlphaImplTest method enableStratifiedEvalTest.

/**
 * Verifies that stratified evaluation is performed up-front if not otherwise configured.
 */
@Test
public void enableStratifiedEvalTest() {
    // Note: This might be cleaner if the test used the debugSolve method from the interface
    String progstr = "p(a). q(X) :- p(X).";
    SystemConfig cfg = new SystemConfig();
    AlphaImpl system = new AlphaImpl(cfg);
    ASPCore2Program input = system.readProgramString(progstr);
    NormalProgram normal = system.normalizeProgram(input);
    CompiledProgram preprocessed = system.performProgramPreprocessing(normal);
    assertTrue(preprocessed.getFacts().contains(Atoms.newBasicAtom(Predicates.getPredicate("q", 1), Terms.newSymbolicConstant("a"))), "Preprocessed program does not contain fact derived from stratifiable rule, but should!");
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) NormalProgram(at.ac.tuwien.kr.alpha.api.programs.NormalProgram) CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) Test(org.junit.jupiter.api.Test)

Aggregations

NormalProgram (at.ac.tuwien.kr.alpha.api.programs.NormalProgram)23 Test (org.junit.jupiter.api.Test)20 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)19 DependencyGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph)13 AnalyzedProgram (at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram)13 ComponentGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph)8 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)7 SCComponent (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph.SCComponent)7 Node (at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph.Node)5 AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)5 AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)5 StratifiedEvaluation (at.ac.tuwien.kr.alpha.core.programs.transformation.StratifiedEvaluation)5 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)4 NoGood (at.ac.tuwien.kr.alpha.core.common.NoGood)3 InternalProgram (at.ac.tuwien.kr.alpha.core.programs.InternalProgram)3 TrailAssignment (at.ac.tuwien.kr.alpha.core.solver.TrailAssignment)3 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)2 NormalRule (at.ac.tuwien.kr.alpha.api.rules.NormalRule)2 VariableTerm (at.ac.tuwien.kr.alpha.api.terms.VariableTerm)2 ArrayList (java.util.ArrayList)2