Search in sources :

Example 21 with Alpha

use of at.ac.tuwien.kr.alpha.api.Alpha 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());
}
Also used : Path(java.nio.file.Path) ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) ArrayList(java.util.ArrayList) InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig)

Example 22 with Alpha

use of at.ac.tuwien.kr.alpha.api.Alpha in project Alpha by alpha-asp.

the class AlphaImplTest method basicUsage.

@Test
public void basicUsage() 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").symbolicInstance("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 23 with Alpha

use of at.ac.tuwien.kr.alpha.api.Alpha 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());
    });
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig) Test(org.junit.jupiter.api.Test)

Example 24 with Alpha

use of at.ac.tuwien.kr.alpha.api.Alpha 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);
}
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 25 with Alpha

use of at.ac.tuwien.kr.alpha.api.Alpha in project Alpha by alpha-asp.

the class AlphaImplTest method addsFacts.

@Test
public void addsFacts() {
    Alpha system = new AlphaImpl();
    Thingy a = new Thingy();
    Thingy b = new Thingy();
    List<Thingy> things = asList(a, b);
    InputProgram program = InputProgram.builder().addFacts(Externals.asFacts(Thingy.class, things)).build();
    Set<AnswerSet> actual = system.solve(program).collect(Collectors.toSet());
    Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("thingy").instance(a).instance(b).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) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram) 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