Search in sources :

Example 26 with AnswerSet

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());
}
Also used : SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) ProgramParser(at.ac.tuwien.kr.alpha.api.programs.ProgramParser) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram) Test(org.junit.jupiter.api.Test)

Example 27 with AnswerSet

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);
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 28 with AnswerSet

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);
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 29 with AnswerSet

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)));
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Test(org.junit.jupiter.api.Test)

Example 30 with AnswerSet

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)));
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Test(org.junit.jupiter.api.Test)

Aggregations

AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)80 Test (org.junit.jupiter.api.Test)64 Alpha (at.ac.tuwien.kr.alpha.api.Alpha)25 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)24 AnswerSetBuilder (at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder)20 InputConfig (at.ac.tuwien.kr.alpha.api.config.InputConfig)17 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)14 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)14 HashSet (java.util.HashSet)13 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)10 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)9 Solver (at.ac.tuwien.kr.alpha.api.Solver)8 InputProgram (at.ac.tuwien.kr.alpha.core.programs.InputProgram)7 Disabled (org.junit.jupiter.api.Disabled)7 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)4 ProgramParser (at.ac.tuwien.kr.alpha.api.programs.ProgramParser)4 ConstantTerm (at.ac.tuwien.kr.alpha.api.terms.ConstantTerm)4 TestUtils.assertRegressionTestAnswerSet (at.ac.tuwien.kr.alpha.core.test.util.TestUtils.assertRegressionTestAnswerSet)4 TestUtils.buildSolverForRegressionTest (at.ac.tuwien.kr.alpha.core.test.util.TestUtils.buildSolverForRegressionTest)4 HashMap (java.util.HashMap)4