Search in sources :

Example 1 with ParsedProgram

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

the class SolverTests method testFunctionTermEquality.

@Test
public void testFunctionTermEquality() throws IOException {
    String testProgram = "r1(f(a,b)). r2(f(a,b)). a :- r1(X), r2(Y), X = Y.";
    ParsedProgram parsedProgram = parseVisit(testProgram);
    Grounder grounder = new NaiveGrounder(parsedProgram);
    Solver solver = getInstance(grounder);
    Set<AnswerSet> expected = new HashSet<>(Collections.singletonList(new BasicAnswerSet.Builder().predicate("r1").instance("f(a,b)").predicate("r2").instance("f(a,b)").predicate("a").build()));
    Set<AnswerSet> answerSets = solver.collectSet();
    assertEquals(expected, answerSets);
}
Also used : NaiveGrounder(at.ac.tuwien.kr.alpha.grounder.NaiveGrounder) ParsedProgram(at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram) BasicAnswerSet(at.ac.tuwien.kr.alpha.common.BasicAnswerSet) AnswerSet(at.ac.tuwien.kr.alpha.common.AnswerSet) ChoiceGrounder(at.ac.tuwien.kr.alpha.grounder.ChoiceGrounder) DummyGrounder(at.ac.tuwien.kr.alpha.grounder.DummyGrounder) Grounder(at.ac.tuwien.kr.alpha.grounder.Grounder) NaiveGrounder(at.ac.tuwien.kr.alpha.grounder.NaiveGrounder) Test(org.junit.Test)

Example 2 with ParsedProgram

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

the class SolverTests method testUnsatisfiableProgram.

@Test
public void testUnsatisfiableProgram() throws IOException {
    String testProgram = "p(a). p(b). :- p(a), p(b).";
    ParsedProgram parsedProgram = parseVisit(testProgram);
    Grounder grounder = new NaiveGrounder(parsedProgram);
    Solver solver = getInstance(grounder);
    List<AnswerSet> answerSets = solver.collectList();
    assertEquals(0, answerSets.size());
}
Also used : NaiveGrounder(at.ac.tuwien.kr.alpha.grounder.NaiveGrounder) ParsedProgram(at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram) BasicAnswerSet(at.ac.tuwien.kr.alpha.common.BasicAnswerSet) AnswerSet(at.ac.tuwien.kr.alpha.common.AnswerSet) ChoiceGrounder(at.ac.tuwien.kr.alpha.grounder.ChoiceGrounder) DummyGrounder(at.ac.tuwien.kr.alpha.grounder.DummyGrounder) Grounder(at.ac.tuwien.kr.alpha.grounder.Grounder) NaiveGrounder(at.ac.tuwien.kr.alpha.grounder.NaiveGrounder) Test(org.junit.Test)

Example 3 with ParsedProgram

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

the class SolverTests method testProgramZeroArityPredicates.

@Test
public void testProgramZeroArityPredicates() throws Exception {
    String testProgram = "a. p(X) :- b, r(X).";
    ParsedProgram parsedProgram = parseVisit(testProgram);
    Grounder grounder = new NaiveGrounder(parsedProgram);
    Solver solver = getInstance(grounder);
    List<AnswerSet> answerSets = solver.collectList();
    assertEquals(1, answerSets.size());
    AnswerSet expected = new BasicAnswerSet.Builder().predicate("a").build();
    assertEquals(expected, answerSets.get(0));
}
Also used : NaiveGrounder(at.ac.tuwien.kr.alpha.grounder.NaiveGrounder) ParsedProgram(at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram) BasicAnswerSet(at.ac.tuwien.kr.alpha.common.BasicAnswerSet) AnswerSet(at.ac.tuwien.kr.alpha.common.AnswerSet) ChoiceGrounder(at.ac.tuwien.kr.alpha.grounder.ChoiceGrounder) DummyGrounder(at.ac.tuwien.kr.alpha.grounder.DummyGrounder) Grounder(at.ac.tuwien.kr.alpha.grounder.Grounder) NaiveGrounder(at.ac.tuwien.kr.alpha.grounder.NaiveGrounder) Test(org.junit.Test)

Example 4 with ParsedProgram

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

the class SolverTests method testFactsOnlyProgram.

@Test
public void testFactsOnlyProgram() throws IOException {
    String testProgram = "p(a). p(b). foo(13). foo(16). q(a). q(c).";
    ParsedProgram parsedProgram = parseVisit(testProgram);
    Grounder grounder = new NaiveGrounder(parsedProgram);
    Solver solver = getInstance(grounder);
    List<AnswerSet> answerSets = solver.collectList();
    assertEquals(1, answerSets.size());
    AnswerSet expected = new BasicAnswerSet.Builder().predicate("q").instance("a").instance("c").predicate("p").instance("a").instance("b").predicate("foo").instance("13").instance("16").build();
    assertEquals(expected, answerSets.get(0));
}
Also used : NaiveGrounder(at.ac.tuwien.kr.alpha.grounder.NaiveGrounder) ParsedProgram(at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram) BasicAnswerSet(at.ac.tuwien.kr.alpha.common.BasicAnswerSet) AnswerSet(at.ac.tuwien.kr.alpha.common.AnswerSet) ChoiceGrounder(at.ac.tuwien.kr.alpha.grounder.ChoiceGrounder) DummyGrounder(at.ac.tuwien.kr.alpha.grounder.DummyGrounder) Grounder(at.ac.tuwien.kr.alpha.grounder.Grounder) NaiveGrounder(at.ac.tuwien.kr.alpha.grounder.NaiveGrounder) Test(org.junit.Test)

Example 5 with ParsedProgram

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

the class SolverTests method sameVariableTwiceInAtomConstraint.

@Test
public void sameVariableTwiceInAtomConstraint() throws IOException {
    String program = "p(a, a).\n" + ":- p(X, X).\n";
    ParsedProgram parsedProgram = parseVisit(program);
    NaiveGrounder grounder = new NaiveGrounder(parsedProgram);
    Solver solver = getInstance(grounder);
    Set<AnswerSet> answerSets = solver.collectSet();
    assertTrue(answerSets.isEmpty());
}
Also used : NaiveGrounder(at.ac.tuwien.kr.alpha.grounder.NaiveGrounder) ParsedProgram(at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram) BasicAnswerSet(at.ac.tuwien.kr.alpha.common.BasicAnswerSet) AnswerSet(at.ac.tuwien.kr.alpha.common.AnswerSet) Test(org.junit.Test)

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