Search in sources :

Example 6 with InputConfig

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

the class AlphaImplTest method problematicRun_3col_1119718541727902_sorted_400.

/**
 * Runs a test that formerly caused some sort of exception.
 */
@Test
public void problematicRun_3col_1119718541727902_sorted_400() throws IOException {
    /*
		 * NOTE: This was constructed from the following commandline invocation:
		 * -DebugEnableInternalChecks -q -g naive -s default -sort -n 400 -i 3col-20-38.txt
		 */
    SystemConfig cfg = new SystemConfig();
    cfg.setGrounderName("naive");
    cfg.setSolverName("default");
    cfg.setNogoodStoreName("alpharoaming");
    cfg.setDebugInternalChecks(true);
    cfg.setSeed(1119718541727902L);
    final Alpha system = new AlphaImpl(cfg);
    final Path path = Paths.get("src", "test", "resources", "PreviouslyProblematic").resolve("3col-20-38.txt");
    InputConfig inputCfg = new InputConfig();
    List<String> files = new ArrayList<>();
    files.add(path.toString());
    inputCfg.setFiles(files);
    ASPCore2Program prog = system.readProgram(inputCfg);
    assertFalse(system.solve(prog).sorted().limit(400).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) Test(org.junit.jupiter.api.Test)

Example 7 with InputConfig

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

the class AlphaImplTest method supplier.

@Test
public void supplier() throws Exception {
    Alpha system = new AlphaImpl();
    InputConfig cfg = InputConfig.forString("node(1). a :- &bestNode(X), node(X).");
    cfg.addPredicateMethod("bestNode", Externals.processPredicate(() -> singleton(singletonList(Terms.newConstant(1)))));
    ASPCore2Program prog = system.readProgram(cfg);
    Set<AnswerSet> expected = AnswerSetsParser.parse("{ node(1), a }");
    Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
    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)

Example 8 with InputConfig

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

the class AlphaImplTest method withExternalInvocationCounted1.

@Test
@Disabled("External atom has state, which is not allowed. Caching of calls makes the number of invocations wrong.")
public void withExternalInvocationCounted1() throws Exception {
    Alpha system = new AlphaImpl();
    InputConfig cfg = InputConfig.forString("a :- &isOne[1], &isOne[1].");
    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 9 with InputConfig

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

the class AlphaImplTest method errorDuplicateExternal.

/**
 * Externals may only be scanned once per implementation.
 * If at the time of a scan, the name of an external is already registered,
 * an exception is thrown.
 */
@Test
public void errorDuplicateExternal() {
    assertThrows(IllegalArgumentException.class, () -> {
        InputConfig cfg = InputConfig.forString("someString.");
        cfg.addPredicateMethods(Externals.scan(this.getClass()));
        cfg.addPredicateMethods(Externals.scan(this.getClass()));
    });
}
Also used : InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig) Test(org.junit.jupiter.api.Test)

Example 10 with InputConfig

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

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