Search in sources :

Example 16 with InputConfig

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

the class AlphaImplTest method filterOutput.

@Test
public void filterOutput() throws Exception {
    Alpha system = new AlphaImpl();
    InputConfig inputCfg = InputConfig.forString("node(1). node(2). outgoing13(X) :- node(X), &getLargeGraphEdges(13,X).");
    inputCfg.addPredicateMethod("getLargeGraphEdges", Externals.processPredicate(() -> new HashSet<>(asList(asList(Terms.newConstant(1), Terms.newConstant(2)), asList(Terms.newConstant(2), Terms.newConstant(1)), asList(Terms.newConstant(13), Terms.newConstant(1))))));
    ASPCore2Program program = system.readProgram(inputCfg);
    Set<AnswerSet> actual = system.solve(program).collect(Collectors.toSet());
    Set<AnswerSet> expected = AnswerSetsParser.parse("{ node(1), node(2), outgoing13(1) }");
    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) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 17 with InputConfig

use of at.ac.tuwien.kr.alpha.api.config.InputConfig 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 18 with InputConfig

use of at.ac.tuwien.kr.alpha.api.config.InputConfig 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 19 with InputConfig

use of at.ac.tuwien.kr.alpha.api.config.InputConfig 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 20 with InputConfig

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

the class AlphaImplTest method smallGraphCoolNode.

@Test
public void smallGraphCoolNode() throws Exception {
    Alpha system = new AlphaImpl();
    InputConfig cfg = InputConfig.forString("node(1..2). in(X) :- node(X), &coolNode[X].");
    cfg.addPredicateMethod("coolNode", Externals.processPredicateMethod(this.getClass().getMethod("coolNode", int.class)));
    ASPCore2Program prog = system.readProgram(cfg);
    Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
    Set<AnswerSet> expected = AnswerSetsParser.parse("{ in(1), node(1), node(2) }");
    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) Test(org.junit.jupiter.api.Test)

Aggregations

InputConfig (at.ac.tuwien.kr.alpha.api.config.InputConfig)22 Alpha (at.ac.tuwien.kr.alpha.api.Alpha)20 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)19 Test (org.junit.jupiter.api.Test)18 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)16 HashSet (java.util.HashSet)8 AnswerSetBuilder (at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder)7 Disabled (org.junit.jupiter.api.Disabled)5 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)4 AlphaConfig (at.ac.tuwien.kr.alpha.api.config.AlphaConfig)3 ParseException (org.apache.commons.cli.ParseException)3 DebugSolvingContext (at.ac.tuwien.kr.alpha.api.DebugSolvingContext)2 Solver (at.ac.tuwien.kr.alpha.api.Solver)2 StatisticsReportingSolver (at.ac.tuwien.kr.alpha.api.StatisticsReportingSolver)2 AlphaImpl (at.ac.tuwien.kr.alpha.api.impl.AlphaImpl)2 CommandLineParser (at.ac.tuwien.kr.alpha.app.config.CommandLineParser)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2