Search in sources :

Example 16 with ParsedProgram

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

the class SolverTests method guessingMultipleAnswerSets.

@Test
public void guessingMultipleAnswerSets() throws IOException {
    String testProgram = "a :- not nota.\n" + "nota :- not a.\n" + "b :- not notb.\n" + "notb :- not b.\n" + "c :- not notc.\n" + "notc :- not c.\n" + ":- nota,notb,notc.";
    ParsedProgram parsedProgram = parseVisit(testProgram);
    NaiveGrounder grounder = new NaiveGrounder(parsedProgram);
    Solver solver = getInstance(grounder);
    Set<AnswerSet> expected = new HashSet<>(Arrays.asList(new BasicAnswerSet.Builder().predicate("a").predicate("b").predicate("c").build(), new BasicAnswerSet.Builder().predicate("nota").predicate("b").predicate("c").build(), new BasicAnswerSet.Builder().predicate("a").predicate("notb").predicate("c").build(), new BasicAnswerSet.Builder().predicate("nota").predicate("notb").predicate("c").build(), new BasicAnswerSet.Builder().predicate("a").predicate("b").predicate("notc").build(), new BasicAnswerSet.Builder().predicate("nota").predicate("b").predicate("notc").build(), new BasicAnswerSet.Builder().predicate("a").predicate("notb").predicate("notc").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) Test(org.junit.Test)

Example 17 with ParsedProgram

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

the class SolverTests method emptyProgramYieldsEmptyAnswerSet.

@Test
public void emptyProgramYieldsEmptyAnswerSet() throws IOException {
    ParsedProgram parsedProgram = parseVisit("");
    NaiveGrounder grounder = new NaiveGrounder(parsedProgram);
    List<AnswerSet> answerSets = getInstance(grounder).collectList();
    assertEquals(1, answerSets.size());
    assertEquals(BasicAnswerSet.EMPTY, 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) Test(org.junit.Test)

Example 18 with ParsedProgram

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

the class SolverTests method guessingAndConstraints.

@Test
public void guessingAndConstraints() throws IOException {
    String testProgram = "node(a).\n" + "node(b).\n" + "edge(b,a).\n" + "in(X) :- not out(X), node(X).\n" + "out(X) :- not in(X), node(X).\n" + ":- in(X), in(Y), edge(X,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("b").predicate("out").instance("a").predicate("edge").instance("b", "a").build(), new BasicAnswerSet.Builder(base).predicate("in").instance("a").predicate("out").instance("b").predicate("edge").instance("b", "a").build(), new BasicAnswerSet.Builder(base).predicate("out").instance("a").instance("b").predicate("edge").instance("b", "a").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 19 with ParsedProgram

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

the class SolverTests method builtinAtoms.

@Test
public void builtinAtoms() throws IOException {
    String testProgram = "dom(1). dom(2). dom(3). dom(4). dom(5)." + "p(X) :- dom(X), X = 4." + "r(Y) :- dom(Y), Y <= 2.";
    ParsedProgram parsedProgram = parseVisit(testProgram);
    NaiveGrounder grounder = new NaiveGrounder(parsedProgram);
    Solver solver = getInstance(grounder);
    Set<AnswerSet> expected = new HashSet<>(Collections.singletonList(new BasicAnswerSet.Builder().predicate("dom").instance("1").instance("2").instance("3").instance("4").instance("5").predicate("p").instance("4").predicate("r").instance("1").instance("2").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) Test(org.junit.Test)

Example 20 with ParsedProgram

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

the class SolverTests method guessingConstraintsInequality.

@Test
public void guessingConstraintsInequality() throws IOException {
    String program = "assign(L, R) :- not nassign(L, R), possible(L, R).\n" + "nassign(L, R) :- not assign(L, R), possible(L, R).\n" + "\n" + "assigned(L) :- assign(L, R).\n" + ":- possible(L,_), not assigned(L).\n" + ":- assign(L, R1), assign(L, R2), R1 != R2.\n" + "\n" + "possible(l1, r1). possible(l3, r3). possible(l4, r1). possible(l4, r3). possible(l5, r4). possible(l6, r2). possible(l7, r3). possible(l8, r2). possible(l9, r1). possible(l9, r4).\n";
    ParsedProgram parsedProgram = parseVisit(program);
    NaiveGrounder grounder = new NaiveGrounder(parsedProgram);
    Solver solver = getInstance(grounder);
    final BasicAnswerSet.Builder base = new BasicAnswerSet.Builder().predicate("possible").instance("l1", "r1").instance("l3", "r3").instance("l4", "r1").instance("l4", "r3").instance("l5", "r4").instance("l6", "r2").instance("l7", "r3").instance("l8", "r2").instance("l9", "r1").instance("l9", "r4").predicate("assign").instance("l1", "r1").instance("l3", "r3").instance("l5", "r4").instance("l6", "r2").instance("l7", "r3").instance("l8", "r2").predicate("assigned").instance("l1").instance("l3").instance("l4").instance("l5").instance("l6").instance("l7").instance("l8").instance("l9");
    Set<AnswerSet> expected = new HashSet<>(Arrays.asList(new BasicAnswerSet.Builder(base).predicate("assign").instance("l4", "r1").instance("l9", "r4").predicate("nassign").instance("l4", "r3").instance("l9", "r1").build(), new BasicAnswerSet.Builder(base).predicate("assign").instance("l4", "r1").instance("l9", "r1").predicate("nassign").instance("l4", "r3").instance("l9", "r4").build(), new BasicAnswerSet.Builder(base).predicate("assign").instance("l4", "r3").instance("l9", "r4").predicate("nassign").instance("l4", "r1").instance("l9", "r1").build(), new BasicAnswerSet.Builder(base).predicate("assign").instance("l4", "r3").instance("l9", "r1").predicate("nassign").instance("l4", "r1").instance("l9", "r4").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)

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