Search in sources :

Example 46 with Predicate

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

the class ThreeColouringWheelTest method fact.

private Atom fact(String predicateName, int... iTerms) {
    List<Term> terms = new ArrayList<>(1);
    Predicate predicate = Predicates.getPredicate(predicateName, iTerms.length);
    for (int i : iTerms) {
        terms.add(Terms.newConstant(i));
    }
    return Atoms.newBasicAtom(predicate, terms);
}
Also used : ArrayList(java.util.ArrayList) Term(at.ac.tuwien.kr.alpha.api.terms.Term) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate)

Example 47 with Predicate

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

the class AggregateRewritingTest method graphVerticesOfMaxDegree.

@Test
public // Test "count eq" and "max eq" together with global vars
void graphVerticesOfMaxDegree() {
    List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(NUM_MAX_DEGREE_VERTICES_ASP);
    assertEquals(1, answerSets.size());
    AnswerSet answerSet = answerSets.get(0);
    Predicate maxDegreeVertices = Predicates.getPredicate("graph_max_degree_vertices", 3);
    // System.out.println(new SimpleAnswerSetFormatter("\n").format(answerSet));
    assertTrue(answerSet.getPredicates().contains(maxDegreeVertices));
    assertTrue(answerSet.getPredicateInstances(maxDegreeVertices).contains(Atoms.newBasicAtom(maxDegreeVertices, Terms.newSymbolicConstant("g1"), Terms.newConstant(2), Terms.newConstant(3))));
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate) Test(org.junit.jupiter.api.Test)

Example 48 with Predicate

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

the class AggregateRewritingTest method greaterMin.

@Test
public void greaterMin() {
    List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(MIN_GT1_ASP);
    assertEquals(1, answerSets.size());
    AnswerSet answerSet = answerSets.get(0);
    Predicate greaterMin = Predicates.getPredicate("greater_min_acceptable", 1);
    // System.out.println(new SimpleAnswerSetFormatter("\n").format(answerSet));
    assertTrue(answerSet.getPredicates().contains(greaterMin));
    assertTrue(answerSet.getPredicateInstances(greaterMin).contains(Atoms.newBasicAtom(greaterMin, Terms.newConstant(7))));
    assertTrue(answerSet.getPredicateInstances(greaterMin).contains(Atoms.newBasicAtom(greaterMin, Terms.newConstant(13))));
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate) Test(org.junit.jupiter.api.Test)

Example 49 with Predicate

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

the class AggregateRewritingTest method sumLessOrEqual1.

@Test
public void sumLessOrEqual1() {
    List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(SUM_LE1_ASP);
    assertEquals(1, answerSets.size());
    AnswerSet answerSet = answerSets.get(0);
    Predicate boundLe = Predicates.getPredicate("bound_le_sum", 1);
    // System.out.println(new SimpleAnswerSetFormatter("\n").format(answerSet));
    assertTrue(answerSet.getPredicates().contains(boundLe));
    assertTrue(answerSet.getPredicateInstances(boundLe).contains(Atoms.newBasicAtom(boundLe, Terms.newConstant(11))));
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate) Test(org.junit.jupiter.api.Test)

Example 50 with Predicate

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

the class AggregateRewritingTest method setComplexEqualityWithGlobals.

@Test
@Disabled("Open issue, as dependency analysis includes cyclic output-dependency, which it should not.")
public void setComplexEqualityWithGlobals() {
    List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(COMPLEX_EQUALITY_WITH_GLOBALS);
    assertEquals(1, answerSets.size());
    AnswerSet answerSet = answerSets.get(0);
    Predicate q = Predicates.getPredicate("q", 0);
    // System.out.println(new SimpleAnswerSetFormatter("\n").format(answerSet));
    assertTrue(answerSet.getPredicates().contains(q));
    assertTrue(answerSet.getPredicateInstances(q).contains(Atoms.newBasicAtom(q)));
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)69 Test (org.junit.jupiter.api.Test)37 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)27 BasicAtom (at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom)19 WorkingMemory (at.ac.tuwien.kr.alpha.core.grounder.WorkingMemory)15 Literal (at.ac.tuwien.kr.alpha.api.programs.literals.Literal)14 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)13 BasicSubstitution (at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution)13 LinkedHashSet (java.util.LinkedHashSet)13 Substitution (at.ac.tuwien.kr.alpha.api.grounder.Substitution)11 AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)10 ArrayList (java.util.ArrayList)10 DependencyGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph)9 ComponentGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph)8 Term (at.ac.tuwien.kr.alpha.api.terms.Term)8 AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)8 AnalyzedProgram (at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram)8 CompiledRule (at.ac.tuwien.kr.alpha.core.rules.CompiledRule)8 TrailAssignment (at.ac.tuwien.kr.alpha.core.solver.TrailAssignment)8 HashMap (java.util.HashMap)8