Search in sources :

Example 6 with Alpha

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

the class AlphaImplTest method smallGraphSingleNeighborNoTerm.

@Test
@Disabled("Test program is not safe (external lacking output variables). This should throw some exception.")
public void smallGraphSingleNeighborNoTerm() throws Exception {
    Alpha system = new AlphaImpl();
    InputConfig cfg = InputConfig.forString("success :- &neighbors[1], not &neighbors[2].");
    cfg.addPredicateMethod("neighbors", Externals.processPredicateMethod(this.getClass().getMethod("neighbors", int.class)));
    ASPCore2Program prog = system.readProgram(cfg);
    Set<AnswerSet> expected = AnswerSetsParser.parse("{ success }");
    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) Disabled(org.junit.jupiter.api.Disabled)

Example 7 with Alpha

use of at.ac.tuwien.kr.alpha.api.Alpha 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 8 with Alpha

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

the class AlphaImplTest method filterTest.

/**
 * Verifies that filters are handled correctly (regression test case introduced when fixing issue #189).
 */
@Test
public void filterTest() {
    String progstr = "a. b. c. d :- c. e(a, b) :- d.";
    Alpha system = new AlphaImpl();
    ASPCore2Program prog = system.readProgramString(progstr);
    Set<AnswerSet> actual = system.solve(prog, (p) -> p.equals(Predicates.getPredicate("a", 0)) || p.equals(Predicates.getPredicate("e", 2))).collect(Collectors.toSet());
    Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("a").predicate("e").symbolicInstance("a", "b").build()));
    assertEquals(expected, actual);
}
Also used : Arrays(java.util.Arrays) ProgramParser(at.ac.tuwien.kr.alpha.api.programs.ProgramParser) LoggerFactory(org.slf4j.LoggerFactory) Heads(at.ac.tuwien.kr.alpha.commons.rules.heads.Heads) Disabled(org.junit.jupiter.api.Disabled) InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig) Collections.singletonList(java.util.Collections.singletonList) Externals(at.ac.tuwien.kr.alpha.core.externals.Externals) Collections.singleton(java.util.Collections.singleton) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Arrays.asList(java.util.Arrays.asList) Literals(at.ac.tuwien.kr.alpha.commons.literals.Literals) Path(java.nio.file.Path) Collections.emptyList(java.util.Collections.emptyList) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) StandardOpenOption(java.nio.file.StandardOpenOption) Set(java.util.Set) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Atoms(at.ac.tuwien.kr.alpha.commons.atoms.Atoms) Collectors(java.util.stream.Collectors) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) Test(org.junit.jupiter.api.Test) List(java.util.List) AspStandardLibrary(at.ac.tuwien.kr.alpha.core.externals.AspStandardLibrary) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) Optional(java.util.Optional) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram) NormalProgram(at.ac.tuwien.kr.alpha.api.programs.NormalProgram) ArrayList(java.util.ArrayList) ConstantTerm(at.ac.tuwien.kr.alpha.api.terms.ConstantTerm) HashSet(java.util.HashSet) Terms(at.ac.tuwien.kr.alpha.commons.terms.Terms) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) Files(java.nio.file.Files) MethodPredicateInterpretation(at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.MethodPredicateInterpretation) Heuristic(at.ac.tuwien.kr.alpha.api.config.Heuristic) InlineDirectivesImpl(at.ac.tuwien.kr.alpha.core.parser.InlineDirectivesImpl) IOException(java.io.IOException) Predicates(at.ac.tuwien.kr.alpha.commons.Predicates) Paths(java.nio.file.Paths) SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) BasicRule(at.ac.tuwien.kr.alpha.core.rules.BasicRule) 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) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 9 with Alpha

use of at.ac.tuwien.kr.alpha.api.Alpha 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 10 with Alpha

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

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