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);
}
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));
}
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);
}
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);
}
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);
}
Aggregations