Search in sources :

Example 81 with ASPCore2Program

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

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

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

the class RuleParser method parse.

public static Rule<Head> parse(String str) {
    ProgramParser parser = new ProgramParserImpl();
    ASPCore2Program prog = parser.parse(str);
    if (!prog.getFacts().isEmpty()) {
        throw new IllegalArgumentException("Expected exactly one rule and no facts!");
    }
    if (prog.getRules().size() != 1) {
        throw new IllegalArgumentException("Expected exactly one rule");
    }
    return prog.getRules().get(0);
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) ProgramParser(at.ac.tuwien.kr.alpha.api.programs.ProgramParser) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)

Example 84 with ASPCore2Program

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

the class AlphaImplTest method disableStratifiedEvalTest.

/**
 * Verifies that no stratified evaluation is performed up-front when disabled in config.
 */
@Test
public void disableStratifiedEvalTest() {
    // Note: This might be cleaner if the test used the debugSolve method from the interface
    String progstr = "p(a). q(X) :- p(X).";
    SystemConfig cfg = new SystemConfig();
    cfg.setEvaluateStratifiedPart(false);
    AlphaImpl system = new AlphaImpl(cfg);
    ASPCore2Program input = system.readProgramString(progstr);
    NormalProgram normal = system.normalizeProgram(input);
    CompiledProgram preprocessed = system.performProgramPreprocessing(normal);
    assertFalse(preprocessed.getFacts().contains(Atoms.newBasicAtom(Predicates.getPredicate("q", 1), Terms.newSymbolicConstant("a"))), "Preprocessed program contains fact derived from stratifiable rule, but should not!");
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) NormalProgram(at.ac.tuwien.kr.alpha.api.programs.NormalProgram) CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) Test(org.junit.jupiter.api.Test)

Example 85 with ASPCore2Program

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

the class AlphaImplTest method enableStratifiedEvalTest.

/**
 * Verifies that stratified evaluation is performed up-front if not otherwise configured.
 */
@Test
public void enableStratifiedEvalTest() {
    // Note: This might be cleaner if the test used the debugSolve method from the interface
    String progstr = "p(a). q(X) :- p(X).";
    SystemConfig cfg = new SystemConfig();
    AlphaImpl system = new AlphaImpl(cfg);
    ASPCore2Program input = system.readProgramString(progstr);
    NormalProgram normal = system.normalizeProgram(input);
    CompiledProgram preprocessed = system.performProgramPreprocessing(normal);
    assertTrue(preprocessed.getFacts().contains(Atoms.newBasicAtom(Predicates.getPredicate("q", 1), Terms.newSymbolicConstant("a"))), "Preprocessed program does not contain fact derived from stratifiable rule, but should!");
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) NormalProgram(at.ac.tuwien.kr.alpha.api.programs.NormalProgram) CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) 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