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;
}
};
}
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!");
}
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!");
}
Aggregations