Search in sources :

Example 11 with ParsedProgram

use of at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram in project Alpha by alpha-asp.

the class ParserTest method parseFactWithFunctionTerms.

@Test
public void parseFactWithFunctionTerms() throws IOException {
    ParsedProgram parsedProgram = parseVisit("p(f(a),g(h(Y))).");
    assertEquals("Program contains one fact.", 1, parsedProgram.facts.size());
    assertEquals("Predicate name of fact is p.", "p", parsedProgram.facts.get(0).getFact().getPredicate());
    assertEquals("Fact has two terms.", 2, parsedProgram.facts.get(0).getFact().getArity());
    assertEquals("First term is function term f.", "f", ((ParsedFunctionTerm) parsedProgram.facts.get(0).getFact().getTerms().get(0)).getFunctionName());
    assertEquals("Second term is function term g.", "g", ((ParsedFunctionTerm) parsedProgram.facts.get(0).getFact().getTerms().get(1)).getFunctionName());
}
Also used : ParsedProgram(at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram) Test(org.junit.Test)

Example 12 with ParsedProgram

use of at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram in project Alpha by alpha-asp.

the class ParserTest method parseSmallProgram.

@Test
public void parseSmallProgram() throws IOException {
    ParsedProgram parsedProgram = parseVisit("a :- b, not d.\n" + "c(X) :- p(X,a,_), q(Xaa,xaa). :- f(Y).");
    assertEquals("Program contains two rules.", 2, parsedProgram.rules.size());
    assertEquals("Program contains one constraint.", 1, parsedProgram.constraints.size());
}
Also used : ParsedProgram(at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram) Test(org.junit.Test)

Example 13 with ParsedProgram

use of at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram in project Alpha by alpha-asp.

the class ParserTest method parseBuiltinAtom.

@Test
public void parseBuiltinAtom() throws IOException {
    ParsedProgram parsedProgram = parseVisit("a :- p(X), X != Y, q(Y).");
    assertEquals(1, parsedProgram.rules.size());
    assertEquals(3, parsedProgram.rules.get(0).body.size());
}
Also used : ParsedProgram(at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram) Test(org.junit.Test)

Example 14 with ParsedProgram

use of at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram in project Alpha by alpha-asp.

the class ChoiceManagerTests method setUp.

@Before
public void setUp() throws IOException {
    String testProgram = "h :- b1, b2, not b3, not b4.";
    ParsedProgram parsedProgram = parseVisit(testProgram);
    this.grounder = new NaiveGrounder(parsedProgram);
    Assignment assignment = new ArrayAssignment();
    this.choiceManager = new ChoiceManager(assignment);
}
Also used : NaiveGrounder(at.ac.tuwien.kr.alpha.grounder.NaiveGrounder) ParsedProgram(at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram) Before(org.junit.Before)

Example 15 with ParsedProgram

use of at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram in project Alpha by alpha-asp.

the class OmigaBenchmarksTest method test.

private void test(String folder, String aspFileName) throws IOException {
    ANTLRFileStream programInputStream = new ANTLRFileStream(Paths.get("benchmarks", "omiga", "omiga-testcases", folder, aspFileName).toString());
    ParsedProgram parsedProgram = parseVisit(programInputStream);
    NaiveGrounder grounder = new NaiveGrounder(parsedProgram);
    Solver solver = getInstance(grounder);
    Optional<AnswerSet> answerSet = solver.stream().findFirst();
    System.out.println(answerSet);
// TODO: check correctness of answer set
}
Also used : ANTLRFileStream(org.antlr.v4.runtime.ANTLRFileStream) NaiveGrounder(at.ac.tuwien.kr.alpha.grounder.NaiveGrounder) ParsedProgram(at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram) AnswerSet(at.ac.tuwien.kr.alpha.common.AnswerSet)

Aggregations

ParsedProgram (at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram)35 NaiveGrounder (at.ac.tuwien.kr.alpha.grounder.NaiveGrounder)29 AnswerSet (at.ac.tuwien.kr.alpha.common.AnswerSet)28 Test (org.junit.Test)27 BasicAnswerSet (at.ac.tuwien.kr.alpha.common.BasicAnswerSet)23 Grounder (at.ac.tuwien.kr.alpha.grounder.Grounder)7 ChoiceGrounder (at.ac.tuwien.kr.alpha.grounder.ChoiceGrounder)6 DummyGrounder (at.ac.tuwien.kr.alpha.grounder.DummyGrounder)6 ASPCore2Lexer (at.ac.tuwien.kr.alpha.antlr.ASPCore2Lexer)2 ASPCore2Parser (at.ac.tuwien.kr.alpha.antlr.ASPCore2Parser)2 ParsedTreeVisitor (at.ac.tuwien.kr.alpha.grounder.parser.ParsedTreeVisitor)2 ANTLRFileStream (org.antlr.v4.runtime.ANTLRFileStream)2 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)2 Before (org.junit.Before)2 Predicate (at.ac.tuwien.kr.alpha.common.Predicate)1 GrounderFactory (at.ac.tuwien.kr.alpha.grounder.GrounderFactory)1 IdentityProgramTransformation (at.ac.tuwien.kr.alpha.grounder.transformation.IdentityProgramTransformation)1 Solver (at.ac.tuwien.kr.alpha.solver.Solver)1 SolverFactory (at.ac.tuwien.kr.alpha.solver.SolverFactory)1 Heuristic (at.ac.tuwien.kr.alpha.solver.heuristics.BranchingHeuristicFactory.Heuristic)1