Search in sources :

Example 31 with ParsedProgram

use of at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram 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 32 with ParsedProgram

use of at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram 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);
}
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 33 with ParsedProgram

use of at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram 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);
}
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 34 with ParsedProgram

use of at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram 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);
}
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 35 with ParsedProgram

use of at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram 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());
}
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)

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