use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class FixedInterpretationLiteralsTest method negativeExternalWithOutput.
@Test
public void negativeExternalWithOutput() {
Optional<AnswerSet> answer = this.alpha.solve(this.alpha.readProgramString(TEST_PROG, this.externals)).findFirst();
assertTrue(answer.isPresent());
AnswerSet answerSet = answer.get();
assertTrue(answerSet.getPredicates().contains(Predicates.getPredicate("negative_external_with_output", 0)));
}
use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class FixedInterpretationLiteralsTest method positiveNumericComparison.
@Test
public void positiveNumericComparison() {
Optional<AnswerSet> answer = this.alpha.solve(this.alpha.readProgramString(TEST_PROG, this.externals)).findFirst();
assertTrue(answer.isPresent());
AnswerSet answerSet = answer.get();
assertTrue(answerSet.getPredicates().contains(Predicates.getPredicate("positive_numeric_comparison", 0)));
}
use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class SolverTests method instanceEnumerationMultipleIdentifiers.
@RegressionTest
public void instanceEnumerationMultipleIdentifiers(RegressionTestConfig cfg) {
Set<AnswerSet> answerSets = buildSolverForRegressionTest("# enumeration_predicate_is enum." + "dom(a). dom(b). dom(c). dom(d)." + "p(X) :- dom(X)." + "unique_position1(Term,Pos) :- p(Term), enum(id,Term,Pos)." + "unique_position2(Term,Pos) :- p(Term), enum(otherid,Term,Pos)." + "wrong_double_occurrence :- unique_position(T1,P), unique_position(T2,P), T1 != T2." + "wrong_double_occurrence :- unique_position2(T1,P), unique_position(T2,P), T1 != T2.", cfg).collectSet();
// Since enumeration depends on evaluation, we do not know which unique_position is actually assigned.
// Check manually that there is one answer set, wrong_double_occurrence has not been derived, and enum yielded a unique position for each term.
assertEquals(1, answerSets.size());
AnswerSet answerSet = answerSets.iterator().next();
assertPropositionalPredicateFalse(answerSet, Predicates.getPredicate("wrong_double_occurrence", 0));
SortedSet<Atom> positions = answerSet.getPredicateInstances(Predicates.getPredicate("unique_position1", 2));
assertEnumerationPositions(positions, 4);
SortedSet<Atom> positions2 = answerSet.getPredicateInstances(Predicates.getPredicate("unique_position2", 2));
assertEnumerationPositions(positions2, 4);
}
use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class SolverTests method doubleChoiceRule.
@RegressionTest
public void doubleChoiceRule(RegressionTestConfig cfg) {
Solver solver = buildSolverForRegressionTest("{ a }. { a }.", cfg);
// Make sure that no superfluous answer sets that only differ on hidden atoms occur.
List<AnswerSet> actual = solver.collectList();
assertEquals(2, actual.size());
assertEquals(AnswerSetsParser.parse("{} { a }"), new HashSet<>(actual));
}
use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class ThreeColouringWheelTest method testThreeColouring.
private void testThreeColouring(int n, RegressionTestConfig cfg) {
ASPCore2Program tmpPrg = new ProgramParserImpl().parse("col(V,C) :- v(V), c(C), not ncol(V,C)." + "ncol(V,C) :- col(V,D), c(C), C != D." + ":- e(V,U), col(V,C), col(U,C).");
InputProgram.Builder prgBuilder = InputProgram.builder(tmpPrg);
prgBuilder.addFacts(createColors("red", "blue", "green"));
prgBuilder.addFacts(createVertices(n));
prgBuilder.addFacts(createEdges(n));
InputProgram program = prgBuilder.build();
maybeShuffle(program);
Solver solver = buildSolverForRegressionTest(program, cfg);
@SuppressWarnings("unused") Optional<AnswerSet> answerSet = solver.stream().findAny();
// System.out.println(answerSet);
// TODO: check correctness of answer set
}
Aggregations