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