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