Search in sources :

Example 46 with AnswerSet

use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.

the class AnswerSetQueryTest method matchString.

@Test
public void matchString() {
    AnswerSetBuilder bld = new AnswerSetBuilder();
    bld.predicate("p").symbolicInstance("a").instance("a");
    AnswerSet as = bld.build();
    AnswerSetQueryImpl stringQuery = AnswerSetQueryImpl.forPredicate(Predicates.getPredicate("p", 1)).withStringEquals(0, "a");
    List<Atom> queryResult = as.query(stringQuery);
    assertEquals(1, queryResult.size());
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Test(org.junit.jupiter.api.Test)

Example 47 with AnswerSet

use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.

the class BasicAnswerSetTest method areAnswerSetsEqual.

@Test
public void areAnswerSetsEqual() {
    Predicate a = Predicates.getPredicate("a", 0);
    Predicate foo = Predicates.getPredicate("foo", 1);
    SortedSet<Predicate> fooAndA = new TreeSet<>(asList(foo, a));
    Predicate q = Predicates.getPredicate("q", 0);
    Predicate p = Predicates.getPredicate("p", 1);
    SortedSet<Predicate> qAndP = new TreeSet<>(asList(q, p));
    ConstantTerm<?> bar = Terms.newConstant("bar");
    ConstantTerm<?> baz = Terms.newConstant("baz");
    Map<Predicate, SortedSet<Atom>> inst1 = new HashMap<>();
    inst1.put(a, new TreeSet<>(singleton(Atoms.newBasicAtom(a))));
    inst1.put(foo, new TreeSet<>(asList(Atoms.newBasicAtom(foo, bar), Atoms.newBasicAtom(foo, baz))));
    // as1 = { a, foo(bar), foo(baz) }
    Map<Predicate, SortedSet<Atom>> inst2 = new HashMap<>();
    inst2.put(a, new TreeSet<>(singleton(Atoms.newBasicAtom(a))));
    inst2.put(foo, new TreeSet<>(asList(Atoms.newBasicAtom(foo, baz), Atoms.newBasicAtom(foo, bar))));
    // as1 = { a, foo(baz), foo(bar) }
    Map<Predicate, SortedSet<Atom>> inst3 = new HashMap<>();
    inst3.put(q, new TreeSet<>(singleton(Atoms.newBasicAtom(q))));
    inst3.put(p, new TreeSet<>(asList(Atoms.newBasicAtom(p, bar), Atoms.newBasicAtom(p, baz))));
    // as3 = { q, p(bar), p(baz) }
    Map<Predicate, SortedSet<Atom>> inst4 = new HashMap<>();
    inst4.put(a, new TreeSet<>(singleton(Atoms.newBasicAtom(a))));
    inst4.put(foo, new TreeSet<>(asList(Atoms.newBasicAtom(foo, bar), Atoms.newBasicAtom(foo, baz), Atoms.newBasicAtom(foo, Terms.newConstant("batsinga")))));
    // as4 = { a, foo(bar), foo(baz), foo(batsinga) }
    final List<AnswerSet> answerSets = asList(new BasicAnswerSet(fooAndA, inst1), new BasicAnswerSet(fooAndA, inst2), new BasicAnswerSet(qAndP, inst3), new BasicAnswerSet(fooAndA, inst4));
    assertEquals(answerSets.get(0), answerSets.get(1));
    assertEquals(answerSets.get(1), answerSets.get(0));
    assertNotEquals(answerSets.get(0), answerSets.get(2));
    assertNotEquals(answerSets.get(0), answerSets.get(3));
}
Also used : HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) SortedSet(java.util.SortedSet) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate) Test(org.junit.jupiter.api.Test)

Example 48 with AnswerSet

use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.

the class AnswerSetQueryTest method matchSymbolicConstant.

@Test
public void matchSymbolicConstant() {
    AnswerSetBuilder bld = new AnswerSetBuilder();
    bld.predicate("p").symbolicInstance("a").instance("a");
    AnswerSet as = bld.build();
    AnswerSetQueryImpl constantQuery = AnswerSetQueryImpl.forPredicate(Predicates.getPredicate("p", 1)).withConstantEquals(0, "a");
    List<Atom> queryResult = as.query(constantQuery);
    assertEquals(1, queryResult.size());
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Test(org.junit.jupiter.api.Test)

Example 49 with AnswerSet

use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.

the class AnswerSetQueryTest method matchTerm.

@Test
public void matchTerm() {
    AnswerSetBuilder bld = new AnswerSetBuilder();
    bld.predicate("p").instance(1).instance(2).instance(3).instance(4).instance(5).instance("bla").symbolicInstance("blubb");
    AnswerSet as = bld.build();
    AnswerSetQueryImpl equalTerm = AnswerSetQueryImpl.forPredicate(Predicates.getPredicate("p", 1)).withTermEquals(0, Terms.newConstant(1));
    List<Atom> queryResult = as.query(equalTerm);
    assertEquals(1, queryResult.size());
    Atom retrievedAtom = queryResult.get(0);
    assertTrue(retrievedAtom.getTerms().get(0).equals(Terms.newConstant(1)));
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Test(org.junit.jupiter.api.Test)

Example 50 with AnswerSet

use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.

the class HanoiTowerTest method testHanoiTower.

private void testHanoiTower(String instance, RegressionTestConfig cfg) throws IOException {
    ASPCore2Program prog = new ProgramParserImpl().parse(Paths.get("src", "test", "resources", "HanoiTower_Alpha.asp"), Paths.get("src", "test", "resources", "HanoiTower_instances", instance + ".asp"));
    Solver solver = TestUtils.buildSolverForRegressionTest(prog, cfg);
    Optional<AnswerSet> answerSet = solver.stream().findFirst();
    assertTrue(answerSet.isPresent());
    checkGoal(prog, answerSet.get());
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) Solver(at.ac.tuwien.kr.alpha.api.Solver) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)

Aggregations

AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)80 Test (org.junit.jupiter.api.Test)64 Alpha (at.ac.tuwien.kr.alpha.api.Alpha)25 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)24 AnswerSetBuilder (at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder)20 InputConfig (at.ac.tuwien.kr.alpha.api.config.InputConfig)17 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)14 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)14 HashSet (java.util.HashSet)13 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)10 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)9 Solver (at.ac.tuwien.kr.alpha.api.Solver)8 InputProgram (at.ac.tuwien.kr.alpha.core.programs.InputProgram)7 Disabled (org.junit.jupiter.api.Disabled)7 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)4 ProgramParser (at.ac.tuwien.kr.alpha.api.programs.ProgramParser)4 ConstantTerm (at.ac.tuwien.kr.alpha.api.terms.ConstantTerm)4 TestUtils.assertRegressionTestAnswerSet (at.ac.tuwien.kr.alpha.core.test.util.TestUtils.assertRegressionTestAnswerSet)4 TestUtils.buildSolverForRegressionTest (at.ac.tuwien.kr.alpha.core.test.util.TestUtils.buildSolverForRegressionTest)4 HashMap (java.util.HashMap)4