Search in sources :

Example 36 with AnswerSet

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)));
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Test(org.junit.jupiter.api.Test)

Example 37 with AnswerSet

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)));
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Test(org.junit.jupiter.api.Test)

Example 38 with AnswerSet

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);
}
Also used : TestUtils.assertRegressionTestAnswerSet(at.ac.tuwien.kr.alpha.core.test.util.TestUtils.assertRegressionTestAnswerSet) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) TestUtils.buildSolverForRegressionTest(at.ac.tuwien.kr.alpha.core.test.util.TestUtils.buildSolverForRegressionTest)

Example 39 with AnswerSet

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));
}
Also used : Solver(at.ac.tuwien.kr.alpha.api.Solver) TestUtils.assertRegressionTestAnswerSet(at.ac.tuwien.kr.alpha.core.test.util.TestUtils.assertRegressionTestAnswerSet) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) TestUtils.buildSolverForRegressionTest(at.ac.tuwien.kr.alpha.core.test.util.TestUtils.buildSolverForRegressionTest)

Example 40 with AnswerSet

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
}
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) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram)

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