use of at.ac.tuwien.kr.alpha.api.AnswerSet 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.AnswerSet 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.AnswerSet 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);
}
use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class FixedInterpretationLiteralsTest method negativeNumericComparison.
@Test
public void negativeNumericComparison() {
Optional<AnswerSet> answer = this.alpha.solve(this.alpha.readProgramString(TEST_PROG, this.externals)).findFirst();
assertTrue(answer.isPresent());
AnswerSet answerSet = answer.get();
assertTrue(answerSet.getPredicates().contains(Predicates.getPredicate("negative_numeric_comparison", 0)));
}
use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class FixedInterpretationLiteralsTest method positiveExternalWithOutputDontfire.
@Test
public void positiveExternalWithOutputDontfire() {
Optional<AnswerSet> answer = this.alpha.solve(this.alpha.readProgramString(TEST_PROG, this.externals)).findFirst();
assertTrue(answer.isPresent());
AnswerSet answerSet = answer.get();
assertFalse(answerSet.getPredicates().contains(Predicates.getPredicate("positive_external_with_output_dontfire", 0)));
}
Aggregations