use of at.ac.tuwien.kr.alpha.api.Alpha in project Alpha by alpha-asp.
the class AlphaImplTest method basicUsageWithString.
@Test
public void basicUsageWithString() throws Exception {
Alpha system = new AlphaImpl();
Set<AnswerSet> actual = system.solve(system.readProgram(InputConfig.forString("p(\"a\")."))).collect(Collectors.toSet());
Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("p").instance("a").build()));
assertEquals(expected, actual);
}
use of at.ac.tuwien.kr.alpha.api.Alpha in project Alpha by alpha-asp.
the class AlphaImplTest method withExternalInvocationCounted3.
@Test
@Disabled("External atom has state, which is not allowed. Caching of calls makes the number of invocations wrong.")
public void withExternalInvocationCounted3() throws Exception {
Alpha system = new AlphaImpl();
InputConfig cfg = InputConfig.forString("a :- &isOne[1], not &isOne[2].");
cfg.addPredicateMethod("isOne", Externals.processPredicateMethod(this.getClass().getMethod("isOne", int.class)));
ASPCore2Program prog = system.readProgram(cfg);
int before = invocations;
Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
int after = invocations;
assertEquals(1, after - before);
Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("a").build()));
assertEquals(expected, actual);
}
use of at.ac.tuwien.kr.alpha.api.Alpha in project Alpha by alpha-asp.
the class AlphaImplTest method testLearnedUnaryNoGoodCausingOutOfOrderLiteralsConflict.
// Detailed reproduction test-case for github issue #239.
@Test
public void testLearnedUnaryNoGoodCausingOutOfOrderLiteralsConflict() throws IOException {
final ProgramParser parser = new ProgramParserImpl();
InputProgram.Builder bld = InputProgram.builder();
bld.accumulate(parser.parse(Files.newInputStream(Paths.get("src", "test", "resources", "HanoiTower_Alpha.asp"), StandardOpenOption.READ)));
bld.accumulate(parser.parse(Files.newInputStream(Paths.get("src", "test", "resources", "HanoiTower_instances", "simple.asp"), StandardOpenOption.READ)));
InputProgram parsedProgram = bld.build();
SystemConfig config = new SystemConfig();
config.setSolverName("default");
config.setNogoodStoreName("alpharoaming");
config.setSeed(0);
config.setBranchingHeuristic(Heuristic.valueOf("VSIDS"));
config.setDebugInternalChecks(true);
config.setDisableJustificationSearch(false);
config.setEvaluateStratifiedPart(false);
config.setReplayChoices(Arrays.asList(21, 26, 36, 56, 91, 96, 285, 166, 101, 290, 106, 451, 445, 439, 448, 433, 427, 442, 421, 415, 436, 409, 430, 397, 391, 424, 385, 379, 418, 373, 412, 406, 394, 388, 382, 245, 232, 208));
Alpha alpha = new AlphaImpl(config);
Optional<AnswerSet> answerSet = alpha.solve(parsedProgram).findFirst();
assertTrue(answerSet.isPresent());
}
use of at.ac.tuwien.kr.alpha.api.Alpha in project Alpha by alpha-asp.
the class AlphaImplTest method withExternalInvocationCounted2.
@Test
@Disabled("External atom has state, which is not allowed. Caching of calls makes the number of invocations wrong.")
public void withExternalInvocationCounted2() throws Exception {
Alpha system = new AlphaImpl();
InputConfig cfg = InputConfig.forString("a. b :- &isOne[1], &isOne[2].");
cfg.addPredicateMethod("isOne", Externals.processPredicateMethod(this.getClass().getMethod("isOne", int.class)));
ASPCore2Program prog = system.readProgram(cfg);
int before = invocations;
Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
int after = invocations;
assertEquals(2, after - before);
Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("a").build()));
assertEquals(expected, actual);
}
use of at.ac.tuwien.kr.alpha.api.Alpha in project Alpha by alpha-asp.
the class AlphaImplTest method withNativeExternal.
@Test
public void withNativeExternal() throws Exception {
Alpha system = new AlphaImpl();
InputConfig cfg = InputConfig.forString("a :- &isTwo[2].");
cfg.addPredicateMethod("isTwo", Externals.processPredicate((Integer t) -> t == 2));
ASPCore2Program prog = system.readProgram(cfg);
Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("a").build()));
assertEquals(expected, actual);
}
Aggregations