Search in sources :

Example 21 with ASPCore2Program

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

the class AlphaImplTest method programWithExternalStringStuff.

@Test
@SuppressWarnings("unchecked")
public void programWithExternalStringStuff() throws IOException {
    Alpha alpha = new AlphaImpl();
    ASPCore2Program prog = alpha.readProgram(InputConfig.forString(STRINGSTUFF_ASP));
    Set<AnswerSet> answerSets = alpha.solve(prog).collect(Collectors.toSet());
    // Verify every result string has length 6 and contains "foo"
    for (AnswerSet as : answerSets) {
        for (Atom atom : as.getPredicateInstances(Predicates.getPredicate("resultstring", 1))) {
            String resultstring = ((ConstantTerm<String>) atom.getTerms().get(0)).getObject();
            assertEquals(6, resultstring.length());
            assertTrue(resultstring.contains("foo"));
        }
    }
}
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) ConstantTerm(at.ac.tuwien.kr.alpha.api.terms.ConstantTerm) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Test(org.junit.jupiter.api.Test)

Example 22 with ASPCore2Program

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

the class AlphaImplTest method withExternalViaAnnotation.

@Test
public void withExternalViaAnnotation() throws Exception {
    Alpha system = new AlphaImpl();
    InputConfig cfg = InputConfig.forString("a :- &isOne[1].");
    cfg.addPredicateMethods(Externals.scan(this.getClass()));
    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)

Example 23 with ASPCore2Program

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

the class AlphaImplTest method smallGraphSingleNeighbor.

@Test
public void smallGraphSingleNeighbor() throws Exception {
    Alpha system = new AlphaImpl();
    InputConfig cfg = InputConfig.forString("node(1..3). in(1,X) :- &neighbors[1](X), node(X).");
    cfg.addPredicateMethod("neighbors", Externals.processPredicateMethod(this.getClass().getMethod("neighbors", int.class)));
    ASPCore2Program prog = system.readProgram(cfg);
    Set<AnswerSet> expected = AnswerSetsParser.parse("{ in(1,2), in(1,3), node(1), node(2), node(3) }");
    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 24 with ASPCore2Program

use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program 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 25 with ASPCore2Program

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

Aggregations

ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)89 Test (org.junit.jupiter.api.Test)70 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)23 NormalProgram (at.ac.tuwien.kr.alpha.api.programs.NormalProgram)22 Alpha (at.ac.tuwien.kr.alpha.api.Alpha)21 InputConfig (at.ac.tuwien.kr.alpha.api.config.InputConfig)19 AnalyzedProgram (at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram)15 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)14 DependencyGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph)12 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)11 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)10 Disabled (org.junit.jupiter.api.Disabled)9 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)8 AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)8 InputProgram (at.ac.tuwien.kr.alpha.core.programs.InputProgram)8 HashSet (java.util.HashSet)8 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)7 ComponentGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph)7 SCComponent (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph.SCComponent)7 AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)7