Search in sources :

Example 11 with Alpha

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

Example 12 with Alpha

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);
}
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 13 with Alpha

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());
}
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 14 with Alpha

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);
}
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 15 with Alpha

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

Aggregations

Alpha (at.ac.tuwien.kr.alpha.api.Alpha)30 Test (org.junit.jupiter.api.Test)28 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)24 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)21 InputConfig (at.ac.tuwien.kr.alpha.api.config.InputConfig)20 HashSet (java.util.HashSet)13 AnswerSetBuilder (at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder)12 Disabled (org.junit.jupiter.api.Disabled)6 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)4 AlphaImpl (at.ac.tuwien.kr.alpha.api.impl.AlphaImpl)4 InputProgram (at.ac.tuwien.kr.alpha.core.programs.InputProgram)4 DebugSolvingContext (at.ac.tuwien.kr.alpha.api.DebugSolvingContext)3 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)3 ConstantTerm (at.ac.tuwien.kr.alpha.api.terms.ConstantTerm)3 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 ProgramParser (at.ac.tuwien.kr.alpha.api.programs.ProgramParser)2 MethodPredicateInterpretation (at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.MethodPredicateInterpretation)2 InlineDirectivesImpl (at.ac.tuwien.kr.alpha.core.parser.InlineDirectivesImpl)2 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)2