Search in sources :

Example 11 with NaiveGrounder

use of at.ac.tuwien.kr.alpha.grounder.NaiveGrounder 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 12 with NaiveGrounder

use of at.ac.tuwien.kr.alpha.grounder.NaiveGrounder 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 13 with NaiveGrounder

use of at.ac.tuwien.kr.alpha.grounder.NaiveGrounder 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 14 with NaiveGrounder

use of at.ac.tuwien.kr.alpha.grounder.NaiveGrounder 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)

Example 15 with NaiveGrounder

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

the class ThreeColouringRandomGraphTest method testThreeColouring.

private void testThreeColouring(int nVertices, int nEdges) throws IOException {
    ParsedProgram program = parseVisit("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).");
    Collection<ParsedFact> vertices = createVertices(nVertices);
    program.accumulate(new ParsedProgram(vertices));
    Collection<ParsedFact> edges = createEdges(nVertices, nEdges);
    program.accumulate(new ParsedProgram(edges));
    program = maybeShuffle(program);
    NaiveGrounder grounder = new NaiveGrounder(program);
    Solver solver = getInstance(grounder);
    Optional<AnswerSet> answerSet = solver.stream().findAny();
    System.out.println(answerSet);
// TODO: check correctness of answer set
}
Also used : NaiveGrounder(at.ac.tuwien.kr.alpha.grounder.NaiveGrounder) AnswerSet(at.ac.tuwien.kr.alpha.common.AnswerSet)

Aggregations

NaiveGrounder (at.ac.tuwien.kr.alpha.grounder.NaiveGrounder)34 AnswerSet (at.ac.tuwien.kr.alpha.common.AnswerSet)31 ParsedProgram (at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram)29 BasicAnswerSet (at.ac.tuwien.kr.alpha.common.BasicAnswerSet)24 Test (org.junit.Test)24 ChoiceGrounder (at.ac.tuwien.kr.alpha.grounder.ChoiceGrounder)6 DummyGrounder (at.ac.tuwien.kr.alpha.grounder.DummyGrounder)6 Grounder (at.ac.tuwien.kr.alpha.grounder.Grounder)6 ANTLRFileStream (org.antlr.v4.runtime.ANTLRFileStream)3 Before (org.junit.Before)2