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