use of at.ac.tuwien.kr.alpha.grounder.NaiveGrounder in project Alpha by alpha-asp.
the class SolverTests method guessingProgramConstraintPermutation.
@Test
public void guessingProgramConstraintPermutation() throws IOException {
String testProgram = "eq(1,1).\n" + "eq(2,2).\n" + "eq(3,3).\n" + "var(1).\n" + "var(2).\n" + "var(3).\n" + "val(VAR,1):-var(VAR),not val(VAR,2),not val(VAR,3).\n" + "val(VAR,2):-var(VAR),not val(VAR,1),not val(VAR,3).\n" + "val(VAR,3):-var(VAR),not val(VAR,1),not val(VAR,2).\n" + ":- val(VAR1,VAL1), val(VAR2,VAL2), eq(VAL1,VAL2), not eq(VAR1,VAR2).\n" + "%:- eq(VAL1,VAL2), not eq(VAR1,VAR2), val(VAR1,VAL1), val(VAR2,VAL2).";
ParsedProgram parsedProgram = parseVisit(testProgram);
NaiveGrounder grounder = new NaiveGrounder(parsedProgram);
Solver solver = getInstance(grounder);
final BasicAnswerSet.Builder base = new BasicAnswerSet.Builder().predicate("eq").instance("1", "1").instance("2", "2").instance("3", "3").predicate("var").instance("1").instance("2").instance("3");
Set<AnswerSet> expected = new HashSet<>(Arrays.asList(new BasicAnswerSet.Builder(base).predicate("val").instance("1", "1").instance("2", "2").instance("3", "3").build(), new BasicAnswerSet.Builder(base).predicate("val").instance("1", "1").instance("3", "2").instance("2", "3").build(), new BasicAnswerSet.Builder(base).predicate("val").instance("2", "1").instance("1", "2").instance("3", "3").build(), new BasicAnswerSet.Builder(base).predicate("val").instance("2", "1").instance("3", "2").instance("1", "3").build(), new BasicAnswerSet.Builder(base).predicate("val").instance("3", "1").instance("1", "2").instance("2", "3").build(), new BasicAnswerSet.Builder(base).predicate("val").instance("3", "1").instance("2", "2").instance("1", "3").build()));
Set<AnswerSet> answerSets = solver.collectSet();
assertEquals(expected, answerSets);
}
use of at.ac.tuwien.kr.alpha.grounder.NaiveGrounder in project Alpha by alpha-asp.
the class SolverTests method simpleNoPropagation.
@Test
public void simpleNoPropagation() throws IOException {
String testProgram = "val(1,1).\n" + "val(2,2).\n" + "something:- val(VAR1,VAL1), val(VAR2,VAL2), anything(VAL1,VAL2).";
ParsedProgram parsedProgram = parseVisit(testProgram);
NaiveGrounder grounder = new NaiveGrounder(parsedProgram);
Solver solver = getInstance(grounder);
Set<AnswerSet> expected = new HashSet<>(Collections.singletonList(new BasicAnswerSet.Builder().predicate("val").instance("1", "1").instance("2", "2").build()));
Set<AnswerSet> answerSets = solver.collectSet();
assertEquals(expected, answerSets);
}
use of at.ac.tuwien.kr.alpha.grounder.NaiveGrounder in project Alpha by alpha-asp.
the class SolverTests method builtinInequality.
@Test
public void builtinInequality() throws IOException {
String program = "location(a1).\n" + "region(r1).\n" + "region(r2).\n" + "\n" + "assign(L,R) :- location(L), region(R), not nassign(L,R).\n" + "nassign(L,R) :- location(L), region(R), not assign(L,R).\n" + "\n" + ":- assign(L,R1), assign(L,R2), R1 != R2.\n" + "\n" + "aux_ext_assign(a1,r1).\n" + "aux_ext_assign(a1,r2).\n" + "\n" + "aux_not_assign(L,R) :- aux_ext_assign(L,R), not assign(L,R).\n" + ":- aux_not_assign(L,R), assign(L,R).";
ParsedProgram parsedProgram = parseVisit(program);
NaiveGrounder grounder = new NaiveGrounder(parsedProgram);
Solver solver = getInstance(grounder);
final BasicAnswerSet.Builder base = new BasicAnswerSet.Builder().predicate("location").instance("a1").predicate("region").instance("r1").instance("r2").predicate("aux_ext_assign").instance("a1", "r1").instance("a1", "r2");
Set<AnswerSet> expected = new HashSet<>(Arrays.asList(new BasicAnswerSet.Builder(base).predicate("assign").instance("a1", "r2").predicate("nassign").instance("a1", "r1").predicate("aux_not_assign").instance("a1", "r1").build(), new BasicAnswerSet.Builder(base).predicate("assign").instance("a1", "r1").predicate("nassign").instance("a1", "r2").predicate("aux_not_assign").instance("a1", "r2").build(), new BasicAnswerSet.Builder(base).predicate("nassign").instance("a1", "r1").instance("a1", "r2").predicate("aux_not_assign").instance("a1", "r1").instance("a1", "r2").build()));
Set<AnswerSet> answerSets = solver.collectSet();
assertEquals(expected, answerSets);
}
use of at.ac.tuwien.kr.alpha.grounder.NaiveGrounder in project Alpha by alpha-asp.
the class SolverTests method noPositiveSelfFounding.
@Test
public void noPositiveSelfFounding() throws IOException {
String program = "a :- b.\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());
}
Aggregations