use of at.ac.tuwien.kr.alpha.api.config.InputConfig 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.config.InputConfig 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());
}
use of at.ac.tuwien.kr.alpha.api.config.InputConfig in project Alpha by alpha-asp.
the class AlphaImplTest method smallGraphWithWrongType.
@Test
public void smallGraphWithWrongType() {
assertThrows(IllegalArgumentException.class, () -> {
Alpha system = new AlphaImpl();
InputConfig cfg = InputConfig.forString("a :- &connected[\"hello\",2].");
cfg.addPredicateMethod("connected", Externals.processPredicate((Integer a, Integer b) -> (a == 1 && b == 2) || (b == 2 || b == 3)));
ASPCore2Program prog = system.readProgram(cfg);
system.solve(prog).collect(Collectors.toSet());
});
}
use of at.ac.tuwien.kr.alpha.api.config.InputConfig in project Alpha by alpha-asp.
the class AlphaImplTest method withExternal.
@Test
public void withExternal() throws Exception {
Alpha alpha = new AlphaImpl();
InputConfig inputCfg = InputConfig.forString("a :- &isOne[1].");
inputCfg.addPredicateMethod("isOne", Externals.processPredicateMethod(this.getClass().getMethod("isOne", int.class)));
ASPCore2Program program = alpha.readProgram(inputCfg);
Set<AnswerSet> actual = alpha.solve(program).collect(Collectors.toSet());
Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("a").build()));
assertEquals(expected, actual);
}
use of at.ac.tuwien.kr.alpha.api.config.InputConfig in project Alpha by alpha-asp.
the class AlphaImplTest method smallGraphCoolNode.
@Test
public void smallGraphCoolNode() throws Exception {
Alpha system = new AlphaImpl();
InputConfig cfg = InputConfig.forString("node(1..2). in(X) :- node(X), &coolNode[X].");
cfg.addPredicateMethod("coolNode", Externals.processPredicateMethod(this.getClass().getMethod("coolNode", int.class)));
ASPCore2Program prog = system.readProgram(cfg);
Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
Set<AnswerSet> expected = AnswerSetsParser.parse("{ in(1), node(1), node(2) }");
assertEquals(expected, actual);
}
Aggregations