Search in sources :

Example 11 with AggregateLiteral

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

the class AggregateRewritingRuleAnalysisTest method bindingAggregateGlobalsNotIncluded.

@Test
public void bindingAggregateGlobalsNotIncluded() {
    AggregateRewritingRuleAnalysis analysis = analyze(BINDING_AGGREGATES_NO_GLOBALS_INCLUDED);
    assertEquals(2, analysis.globalVariablesPerAggregate.size());
    assertEquals(2, analysis.dependenciesPerAggregate.size());
    // Check that the #max aggregate does not include "not p(X)" as its dependency.
    for (Map.Entry<AggregateLiteral, Set<Literal>> aggregateDependencies : analysis.dependenciesPerAggregate.entrySet()) {
        if (aggregateDependencies.getKey().getAtom().getAggregateFunction() == AggregateFunctionSymbol.MAX) {
            for (Literal dependency : aggregateDependencies.getValue()) {
                assertFalse(dependency.isNegated());
            }
        }
    }
}
Also used : Set(java.util.Set) AggregateLiteral(at.ac.tuwien.kr.alpha.api.programs.literals.AggregateLiteral) Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) AggregateLiteral(at.ac.tuwien.kr.alpha.api.programs.literals.AggregateLiteral) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 12 with AggregateLiteral

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

the class AggregateRewritingRuleAnalysisTest method nonBindingAggregateNoGlobals1.

@Test
public void nonBindingAggregateNoGlobals1() {
    AggregateRewritingRuleAnalysis analysis = analyze(NONBINDING_AGGREGATE_NO_GLOBALS_1);
    assertEquals(1, analysis.globalVariablesPerAggregate.size());
    assertEquals(1, analysis.dependenciesPerAggregate.size());
    AggregateLiteral aggregate = new ArrayList<>(analysis.globalVariablesPerAggregate.keySet()).get(0);
    assertTrue(analysis.globalVariablesPerAggregate.get(aggregate).isEmpty());
    assertFalse(analysis.dependenciesPerAggregate.get(aggregate).isEmpty());
    Set<Literal> dependencies = analysis.dependenciesPerAggregate.get(aggregate);
    assertEquals(1, dependencies.size());
    Literal pXY = Literals.fromAtom(Atoms.newBasicAtom(Predicates.getPredicate("p", 2), Terms.newVariable("X"), Terms.newVariable("Y")), true);
    assertTrue(dependencies.contains(pXY));
}
Also used : AggregateLiteral(at.ac.tuwien.kr.alpha.api.programs.literals.AggregateLiteral) Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) AggregateLiteral(at.ac.tuwien.kr.alpha.api.programs.literals.AggregateLiteral) Test(org.junit.jupiter.api.Test)

Example 13 with AggregateLiteral

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

the class AggregateRewritingRuleAnalysisTest method nonBindingAggregateNoGlobals2.

@Test
public void nonBindingAggregateNoGlobals2() {
    AggregateRewritingRuleAnalysis analysis = analyze(NONBINDING_AGGREGATE_NO_GLOBALS_2);
    assertEquals(1, analysis.globalVariablesPerAggregate.size());
    assertEquals(1, analysis.dependenciesPerAggregate.size());
    AggregateLiteral aggregate = new ArrayList<>(analysis.globalVariablesPerAggregate.keySet()).get(0);
    assertTrue(analysis.globalVariablesPerAggregate.get(aggregate).isEmpty());
    assertFalse(analysis.dependenciesPerAggregate.get(aggregate).isEmpty());
    Set<Literal> dependencies = analysis.dependenciesPerAggregate.get(aggregate);
    assertEquals(3, dependencies.size());
    Literal threePlusY = Literals.fromAtom(Atoms.newComparisonAtom(Terms.newVariable("X"), Terms.newArithmeticTerm(Terms.newConstant(3), ArithmeticOperator.PLUS, Terms.newVariable("Y")), ComparisonOperators.EQ), true);
    assertTrue(dependencies.contains(threePlusY));
    Literal zPlusFour = Literals.fromAtom(Atoms.newComparisonAtom(Terms.newVariable("Y"), Terms.newArithmeticTerm(Terms.newVariable("Z"), ArithmeticOperator.PLUS, Terms.newConstant(4)), ComparisonOperators.EQ), true);
    assertTrue(dependencies.contains(zPlusFour));
    Literal rSZ = Literals.fromAtom(Atoms.newBasicAtom(Predicates.getPredicate("r", 2), Terms.newVariable("S"), Terms.newVariable("Z")), true);
    assertTrue(dependencies.contains(rSZ));
}
Also used : AggregateLiteral(at.ac.tuwien.kr.alpha.api.programs.literals.AggregateLiteral) Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) AggregateLiteral(at.ac.tuwien.kr.alpha.api.programs.literals.AggregateLiteral) Test(org.junit.jupiter.api.Test)

Example 14 with AggregateLiteral

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

the class AggregateRewritingRuleAnalysisTest method bindingAggregateNoGlobals.

@Test
public void bindingAggregateNoGlobals() {
    AggregateRewritingRuleAnalysis analysis = analyze(BINDING_AGGREGATE_NO_GLOBALS);
    assertEquals(1, analysis.globalVariablesPerAggregate.size());
    assertEquals(1, analysis.dependenciesPerAggregate.size());
    AggregateLiteral aggregate = new ArrayList<>(analysis.globalVariablesPerAggregate.keySet()).get(0);
    assertTrue(analysis.globalVariablesPerAggregate.get(aggregate).isEmpty());
    assertEquals(0, analysis.dependenciesPerAggregate.get(aggregate).size());
}
Also used : AggregateLiteral(at.ac.tuwien.kr.alpha.api.programs.literals.AggregateLiteral) Test(org.junit.jupiter.api.Test)

Example 15 with AggregateLiteral

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

the class AggregateRewritingRuleAnalysisTest method bindingAggregateWithGlobals1.

@Test
public void bindingAggregateWithGlobals1() {
    AggregateRewritingRuleAnalysis analysis = analyze(BINDING_AGGREGATE_WITH_GLOBALS_1);
    assertEquals(1, analysis.globalVariablesPerAggregate.size());
    assertEquals(1, analysis.dependenciesPerAggregate.size());
    AggregateLiteral aggregate = new ArrayList<>(analysis.globalVariablesPerAggregate.keySet()).get(0);
    assertFalse(analysis.globalVariablesPerAggregate.get(aggregate).isEmpty());
    assertFalse(analysis.dependenciesPerAggregate.get(aggregate).isEmpty());
    Set<VariableTerm> globalVars = analysis.globalVariablesPerAggregate.get(aggregate);
    assertTrue(globalVars.contains(Terms.newVariable("G")));
    assertTrue(globalVars.contains(Terms.newVariable("V")));
    Set<Literal> dependencies = analysis.dependenciesPerAggregate.get(aggregate);
    assertEquals(2, dependencies.size());
    Literal graph = Literals.fromAtom(Atoms.newBasicAtom(Predicates.getPredicate("graph", 1), Terms.newVariable("G")), true);
    assertTrue(dependencies.contains(graph));
    Literal graphVertex = Literals.fromAtom(Atoms.newBasicAtom(Predicates.getPredicate("graph_vertex", 2), Terms.newVariable("G"), Terms.newVariable("V")), true);
    assertTrue(dependencies.contains(graphVertex));
}
Also used : AggregateLiteral(at.ac.tuwien.kr.alpha.api.programs.literals.AggregateLiteral) Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) AggregateLiteral(at.ac.tuwien.kr.alpha.api.programs.literals.AggregateLiteral) VariableTerm(at.ac.tuwien.kr.alpha.api.terms.VariableTerm) Test(org.junit.jupiter.api.Test)

Aggregations

AggregateLiteral (at.ac.tuwien.kr.alpha.api.programs.literals.AggregateLiteral)18 Literal (at.ac.tuwien.kr.alpha.api.programs.literals.Literal)15 VariableTerm (at.ac.tuwien.kr.alpha.api.terms.VariableTerm)7 Test (org.junit.jupiter.api.Test)7 AggregateAtom (at.ac.tuwien.kr.alpha.api.programs.atoms.AggregateAtom)4 Term (at.ac.tuwien.kr.alpha.api.terms.Term)4 ArrayList (java.util.ArrayList)4 Rule (at.ac.tuwien.kr.alpha.api.rules.Rule)3 BasicRule (at.ac.tuwien.kr.alpha.core.rules.BasicRule)3 HashSet (java.util.HashSet)3 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)2 AggregateElement (at.ac.tuwien.kr.alpha.api.programs.atoms.AggregateAtom.AggregateElement)2 ComparisonLiteral (at.ac.tuwien.kr.alpha.api.programs.literals.ComparisonLiteral)2 Head (at.ac.tuwien.kr.alpha.api.rules.heads.Head)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 ComparisonOperator (at.ac.tuwien.kr.alpha.api.ComparisonOperator)1 InlineDirectives (at.ac.tuwien.kr.alpha.api.programs.InlineDirectives)1 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)1