Search in sources :

Example 26 with NaiveGrounder

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

the class SolverTests method noPositiveCycleSelfFoundingGuess.

@Test
public void noPositiveCycleSelfFoundingGuess() throws IOException {
    String program = "c :- not d.\n" + "d :- not c." + "a :- b, not c.\n" + "b:- a.\n" + ":- not b.";
    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 27 with NaiveGrounder

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

the class AlphaHeuristicTestAssumptions 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);
    this.assignment = new ArrayAssignment();
    this.choiceManager = new TestableChoiceManager(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 28 with NaiveGrounder

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

the class SolverTests method guessingAndPropagationAfterwards.

@Test
public void guessingAndPropagationAfterwards() throws IOException {
    String testProgram = "node(a).\n" + "node(b).\n" + "in(X) :- not out(X), node(X).\n" + "out(X) :- not in(X), node(X).\n" + "pair(X,Y) :- in(X), in(Y).";
    ParsedProgram parsedProgram = parseVisit(testProgram);
    NaiveGrounder grounder = new NaiveGrounder(parsedProgram);
    Solver solver = getInstance(grounder);
    final BasicAnswerSet.Builder base = new BasicAnswerSet.Builder().predicate("node").instance("a").instance("b");
    Set<AnswerSet> expected = new HashSet<>(Arrays.asList(new BasicAnswerSet.Builder(base).predicate("in").instance("a").instance("b").predicate("pair").instance("a", "a").instance("a", "b").instance("b", "a").instance("b", "b").build(), new BasicAnswerSet.Builder(base).predicate("in").instance("b").predicate("out").instance("a").predicate("pair").instance("b", "b").build(), new BasicAnswerSet.Builder(base).predicate("in").instance("a").predicate("out").instance("b").predicate("pair").instance("a", "a").build(), new BasicAnswerSet.Builder(base).predicate("out").instance("a").instance("b").build()));
    Set<AnswerSet> answerSets = solver.collectSet();
    assertEquals(expected, answerSets);
}
Also used : BasicAnswerSet(at.ac.tuwien.kr.alpha.common.BasicAnswerSet) 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 29 with NaiveGrounder

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

the class SolverTests method testGuessingProgramNonGround.

@Test
public void testGuessingProgramNonGround() throws Exception {
    String testProgram = "dom(1). dom(2). dom(3)." + "p(X) :- dom(X), not q(X)." + "q(X) :- dom(X), not p(X).";
    ParsedProgram parsedProgram = parseVisit(testProgram);
    NaiveGrounder grounder = new NaiveGrounder(parsedProgram);
    Solver solver = getInstance(grounder);
    final BasicAnswerSet.Builder base = new BasicAnswerSet.Builder().predicate("dom").instance("1").instance("2").instance("3");
    Set<AnswerSet> expected = new HashSet<>(Arrays.asList(new BasicAnswerSet.Builder(base).predicate("q").instance("1").instance("2").predicate("p").instance("3").build(), new BasicAnswerSet.Builder(base).predicate("q").instance("1").predicate("p").instance("2").instance("3").build(), new BasicAnswerSet.Builder(base).predicate("q").instance("2").predicate("p").instance("1").instance("3").build(), new BasicAnswerSet.Builder(base).predicate("p").instance("1").instance("2").instance("3").build(), new BasicAnswerSet.Builder(base).predicate("q").instance("1").instance("2").instance("3").build(), new BasicAnswerSet.Builder(base).predicate("q").instance("1").instance("3").predicate("p").instance("2").build(), new BasicAnswerSet.Builder(base).predicate("q").instance("2").instance("3").predicate("p").instance("1").build(), new BasicAnswerSet.Builder(base).predicate("q").instance("3").predicate("p").instance("1").instance("2").build()));
    assertEquals(expected, solver.collectSet());
}
Also used : BasicAnswerSet(at.ac.tuwien.kr.alpha.common.BasicAnswerSet) 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 30 with NaiveGrounder

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

the class ThreeColouringWheelTest method testThreeColouring.

private void testThreeColouring(int n) throws IOException {
    ParsedProgram program = parseVisit("col(V,C) :- v(V), c(C), not ncol(V,C)." + "ncol(V,C) :- col(V,D), c(C), C != D." + ":- e(V,U), col(V,C), col(U,C).");
    Collection<ParsedFact> colours = createColors("red", "blue", "green");
    program.accumulate(new ParsedProgram(colours));
    Collection<ParsedFact> vertices = createVertices(n);
    program.accumulate(new ParsedProgram(vertices));
    Collection<ParsedFact> edges = createEdges(n);
    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