Search in sources :

Example 11 with ProgramParserImpl

use of at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl in project Alpha by alpha-asp.

the class HanoiTowerTest method testHanoiTower.

private void testHanoiTower(String instance, RegressionTestConfig cfg) throws IOException {
    ASPCore2Program prog = new ProgramParserImpl().parse(Paths.get("src", "test", "resources", "HanoiTower_Alpha.asp"), Paths.get("src", "test", "resources", "HanoiTower_instances", instance + ".asp"));
    Solver solver = TestUtils.buildSolverForRegressionTest(prog, cfg);
    Optional<AnswerSet> answerSet = solver.stream().findFirst();
    assertTrue(answerSet.isPresent());
    checkGoal(prog, answerSet.get());
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) Solver(at.ac.tuwien.kr.alpha.api.Solver) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)

Example 12 with ProgramParserImpl

use of at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl in project Alpha by alpha-asp.

the class ThreeColouringRandomGraphTest method testThreeColouring.

private void testThreeColouring(int nVertices, int nEdges, RegressionTestConfig cfg) {
    ASPCore2Program tmpPrg = new ProgramParserImpl().parse("blue(N) :- v(N), not red(N), not green(N)." + "red(N) :- v(N), not blue(N), not green(N)." + "green(N) :- v(N), not red(N), not blue(N)." + ":- e(N1,N2), blue(N1), blue(N2)." + ":- e(N1,N2), red(N1), red(N2)." + ":- e(N1,N2), green(N1), green(N2).");
    InputProgram.Builder prgBuilder = InputProgram.builder(tmpPrg);
    prgBuilder.addFacts(createVertices(nVertices));
    prgBuilder.addFacts(createEdges(nVertices, nEdges));
    InputProgram program = prgBuilder.build();
    maybeShuffle(program);
    @SuppressWarnings("unused") Optional<AnswerSet> answerSet = buildSolverForRegressionTest(program, cfg).stream().findAny();
// System.out.println(answerSet);
// TODO: check correctness of answer set
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram)

Example 13 with ProgramParserImpl

use of at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl in project Alpha by alpha-asp.

the class ProgramTest method testToString.

@Test
public void testToString() {
    ASPCore2Program parsedProgram = new ProgramParserImpl().parse("p(a)." + System.lineSeparator() + "q(X) :- p(X)." + System.lineSeparator() + "p(b).");
    assertEquals("p(a)." + System.lineSeparator() + "p(b)." + System.lineSeparator() + "q(X) :- p(X)." + System.lineSeparator(), parsedProgram.toString());
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) Test(org.junit.jupiter.api.Test)

Example 14 with ProgramParserImpl

use of at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl 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)

Aggregations

ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)14 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)11 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)8 Solver (at.ac.tuwien.kr.alpha.api.Solver)5 ProgramParser (at.ac.tuwien.kr.alpha.api.programs.ProgramParser)5 InputProgram (at.ac.tuwien.kr.alpha.core.programs.InputProgram)4 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)3 Test (org.junit.jupiter.api.Test)3 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)2 AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)2 AnalyzedProgram (at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram)2 Alpha (at.ac.tuwien.kr.alpha.api.Alpha)1 PredicateInterpretation (at.ac.tuwien.kr.alpha.api.common.fixedinterpretations.PredicateInterpretation)1 BasicAtom (at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom)1 Head (at.ac.tuwien.kr.alpha.api.rules.heads.Head)1 AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)1 Grounder (at.ac.tuwien.kr.alpha.core.grounder.Grounder)1 NaiveGrounder (at.ac.tuwien.kr.alpha.core.grounder.NaiveGrounder)1 NormalizeProgramTransformation (at.ac.tuwien.kr.alpha.core.programs.transformation.NormalizeProgramTransformation)1 HashMap (java.util.HashMap)1