Package net.sf.tweety.lp.asp.syntax
Class AggregateAtom
- java.lang.Object
-
- net.sf.tweety.lp.asp.syntax.ASPElement
-
- net.sf.tweety.lp.asp.syntax.ASPBodyElement
-
- net.sf.tweety.lp.asp.syntax.AggregateAtom
-
- All Implemented Interfaces:
Formula,ComplexLogicalFormula,LogicStructure,SimpleLogicalFormula
public class AggregateAtom extends ASPBodyElement
This class represents an aggregate. Aggregates are functions that range over sets of terms and literals and evaluate to some value. For example, using the aggregate function #count one could obtain the number of employees of one department. Normally, this value is then compared to another value with a comparative operator like "=" to produce a truth value (also known as 'aggregate relation'). For example, this could be used to express the condition that the number of employees in one department has to be greater than 0.
An aggregate that contains such a comparison is also referred to as an aggregate atom and can appear in the body of a rule.- Author:
- Tim Janus, Thomas Vengels, Anna Gessler
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<AggregateElement>aggregateElementsThe elements that the aggregate ranges over.private ASPOperator.AggregateFunctionfunctionThe aggregate function of this aggregate.private Term<?>leftGuardA term that the aggregate's resulting value will be compared to using the comparative operator.private ASPOperator.BinaryOperatorleftOpA comparative operator that will be used to compare the aggregate's resulting value with the another value (leftGuard) to produce a truth value.private Term<?>rightGuardA term that the aggregate's resulting value will be compared to using the comparative operator.private ASPOperator.BinaryOperatorrightOpA comparative operator that will be used to compare the aggregate's resulting value with the another value (rightGuard) to produce a truth value.
-
Constructor Summary
Constructors Constructor Description AggregateAtom()Empty default constructor.AggregateAtom(AggregateAtom other)Copy-ConstructorAggregateAtom(ASPOperator.AggregateFunction func, java.util.List<AggregateElement> elements)Creates a new Aggregate with the given aggregate function and the given aggregate elements.AggregateAtom(ASPOperator.AggregateFunction func, java.util.List<AggregateElement> elements, ASPOperator.BinaryOperator relation, Term<?> t)Creates a new Aggregate with the given aggregate function, the given aggregate elements, and the given aggregate relation.AggregateAtom(ASPOperator.AggregateFunction func, java.util.List<AggregateElement> elements, ASPOperator.BinaryOperator relation, Term<?> t, ASPOperator.BinaryOperator relation2, Term<?> t2)Creates a new Aggregate with the given aggregate function, the given aggregate elements, and the given left and right aggregate relations.
-
Method Summary
Modifier and Type Method Description AggregateAtomclone()Creates a deep copy of this formulajava.util.List<AggregateElement>getAggregateElements()java.util.Set<ASPAtom>getAtoms()Processes the set of all atoms which appear in this formulaASPOperator.AggregateFunctiongetFunction()Returns the aggregate function.Term<?>getLeftGuard()Get the left relation term (right guard).ASPOperator.BinaryOperatorgetLeftOperator()Returns the operator of the left aggregate relation.java.util.SortedSet<ASPLiteral>getLiterals()Returns all literals in this element in form of a SortedSet.java.util.Set<Predicate>getPredicates()Processes the set of all predicates which appear in this formulaTerm<?>getRightGuard()Returns the right relation term (right guard).ASPOperator.BinaryOperatorgetRightOperator()Returns the operator of the right aggregate relation.FolSignaturegetSignature()Returns the signature of the language of this formula.java.util.Set<Term<?>>getTerms()<C extends Term<?>>
java.util.Set<C>getTerms(java.lang.Class<C> cls)Processes the set containing all terms of type C.booleanhasLeftRelation()Returns true if the aggregate has a left aggregate relation (meaning a term that the aggregate's resulting value will be compared to using a comparative operator).booleanhasRightRelation()Returns true if the aggregate has a right aggregate relation (meaning a term that the aggregate's resulting value will be compared to using a comparative operator).booleanisLiteral()voidsetFunction(ASPOperator.AggregateFunction function)Sets the aggregate function.voidsetLeftGuard(Term<?> relationTerm)Set the left relation term (right guard).voidsetLeftOperator(ASPOperator.BinaryOperator op)Sets the operator of the left aggregate relation.voidsetRightGuard(Term<?> relationTerm)Set the right relation term (right guard).voidsetRightOperator(ASPOperator.BinaryOperator op)Sets the operator of the right aggregate relation.AggregateAtomsubstitute(Term<?> t, Term<?> v)Substitutes all occurrences of term "v" in this formula by term "t" and returns the new formula.java.lang.StringtoString()-
Methods inherited from class net.sf.tweety.lp.asp.syntax.ASPElement
containsTermsOfType, exchange, getPredicateCls, isGround, isWellFormed, substitute
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.tweety.logics.commons.syntax.interfaces.SimpleLogicalFormula
equals, hashCode
-
-
-
-
Field Detail
-
function
private ASPOperator.AggregateFunction function
The aggregate function of this aggregate.- See Also:
ASPOperator.AggregateFunction
-
aggregateElements
private java.util.List<AggregateElement> aggregateElements
The elements that the aggregate ranges over.- See Also:
AggregateElement
-
rightOp
private ASPOperator.BinaryOperator rightOp
A comparative operator that will be used to compare the aggregate's resulting value with the another value (rightGuard) to produce a truth value.
-
rightGuard
private Term<?> rightGuard
A term that the aggregate's resulting value will be compared to using the comparative operator.
-
leftOp
private ASPOperator.BinaryOperator leftOp
A comparative operator that will be used to compare the aggregate's resulting value with the another value (leftGuard) to produce a truth value.
-
leftGuard
private Term<?> leftGuard
A term that the aggregate's resulting value will be compared to using the comparative operator.
-
-
Constructor Detail
-
AggregateAtom
public AggregateAtom()
Empty default constructor.
-
AggregateAtom
public AggregateAtom(ASPOperator.AggregateFunction func, java.util.List<AggregateElement> elements)
Creates a new Aggregate with the given aggregate function and the given aggregate elements.- Parameters:
func- an aggregate functionelements- list of aggregate elements
-
AggregateAtom
public AggregateAtom(ASPOperator.AggregateFunction func, java.util.List<AggregateElement> elements, ASPOperator.BinaryOperator relation, Term<?> t)
Creates a new Aggregate with the given aggregate function, the given aggregate elements, and the given aggregate relation.- Parameters:
func- an aggregate functionelements- list of aggregate elementsrelation- the relationt- some term
-
AggregateAtom
public AggregateAtom(ASPOperator.AggregateFunction func, java.util.List<AggregateElement> elements, ASPOperator.BinaryOperator relation, Term<?> t, ASPOperator.BinaryOperator relation2, Term<?> t2)
Creates a new Aggregate with the given aggregate function, the given aggregate elements, and the given left and right aggregate relations.- Parameters:
func- an aggregate functionelements- list of aggregate elementsrelation- the relationt- some termrelation2- the relationt2- some term
-
AggregateAtom
public AggregateAtom(AggregateAtom other)
Copy-Constructor- Parameters:
other- another AggregateAtom
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getLiterals
public java.util.SortedSet<ASPLiteral> getLiterals()
Description copied from class:ASPBodyElementReturns all literals in this element in form of a SortedSet. Literals are atoms or strict negations of atoms.- Specified by:
getLiteralsin classASPBodyElement- Returns:
- all the literals used in the rule element
-
getPredicates
public java.util.Set<Predicate> getPredicates()
Description copied from interface:SimpleLogicalFormulaProcesses the set of all predicates which appear in this formula- Specified by:
getPredicatesin interfaceSimpleLogicalFormula- Specified by:
getPredicatesin classASPElement- Returns:
- all predicates that appear in this formula
-
getAtoms
public java.util.Set<ASPAtom> getAtoms()
Description copied from interface:SimpleLogicalFormulaProcesses the set of all atoms which appear in this formula- Specified by:
getAtomsin interfaceSimpleLogicalFormula- Specified by:
getAtomsin classASPElement- Returns:
- The set of all atoms
-
substitute
public AggregateAtom substitute(Term<?> t, Term<?> v)
Description copied from interface:ComplexLogicalFormulaSubstitutes all occurrences of term "v" in this formula by term "t" and returns the new formula.- Specified by:
substitutein interfaceComplexLogicalFormula- Specified by:
substitutein classASPBodyElement- Parameters:
t- the term to be substituted.v- the term to substitute.- Returns:
- a formula where every occurrence of "v" is replaced by "t".
-
getSignature
public FolSignature getSignature()
Description copied from interface:FormulaReturns the signature of the language of this formula.- Specified by:
getSignaturein interfaceFormula- Specified by:
getSignaturein classASPElement- Returns:
- the signature of the language of this formula.
-
clone
public AggregateAtom clone()
Description copied from interface:SimpleLogicalFormulaCreates a deep copy of this formula- Specified by:
clonein interfaceComplexLogicalFormula- Specified by:
clonein interfaceSimpleLogicalFormula- Specified by:
clonein classASPElement- Returns:
- the cloned formula
-
isLiteral
public boolean isLiteral()
- Returns:
- true if the formula represents a literal in the language or false otherwise
-
getTerms
public java.util.Set<Term<?>> getTerms()
- Returns:
- a set containing all terms of this logical structure
-
getTerms
public <C extends Term<?>> java.util.Set<C> getTerms(java.lang.Class<C> cls)
Description copied from interface:LogicStructureProcesses the set containing all terms of type C. This method uses the equals method of the given Class and therefore does not add terms which are sub classes of type C to the set.- Type Parameters:
C- the type of terms- Parameters:
cls- The Class structure containing type information about the searched term- Returns:
- A set containing all terms of type C of this logical structure
-
getAggregateElements
public java.util.List<AggregateElement> getAggregateElements()
-
hasLeftRelation
public boolean hasLeftRelation()
Returns true if the aggregate has a left aggregate relation (meaning a term that the aggregate's resulting value will be compared to using a comparative operator).- Returns:
- true if aggregate has left aggregate relation
-
hasRightRelation
public boolean hasRightRelation()
Returns true if the aggregate has a right aggregate relation (meaning a term that the aggregate's resulting value will be compared to using a comparative operator).- Returns:
- true if aggregate has right aggregate relation
-
getFunction
public ASPOperator.AggregateFunction getFunction()
Returns the aggregate function.- Returns:
- an aggregate function
-
setFunction
public void setFunction(ASPOperator.AggregateFunction function)
Sets the aggregate function.- Parameters:
function- an aggregate function
-
getRightOperator
public ASPOperator.BinaryOperator getRightOperator()
Returns the operator of the right aggregate relation.- Returns:
- comparative operator
-
setRightOperator
public void setRightOperator(ASPOperator.BinaryOperator op)
Sets the operator of the right aggregate relation.- Parameters:
op- comparative operator
-
getRightGuard
public Term<?> getRightGuard()
Returns the right relation term (right guard).- Returns:
- Term
-
setRightGuard
public void setRightGuard(Term<?> relationTerm)
Set the right relation term (right guard).- Parameters:
relationTerm- some term
-
getLeftOperator
public ASPOperator.BinaryOperator getLeftOperator()
Returns the operator of the left aggregate relation.- Returns:
- comparative operator
-
setLeftOperator
public void setLeftOperator(ASPOperator.BinaryOperator op)
Sets the operator of the left aggregate relation.- Parameters:
op- comparative operator
-
getLeftGuard
public Term<?> getLeftGuard()
Get the left relation term (right guard).- Returns:
- Term
-
setLeftGuard
public void setLeftGuard(Term<?> relationTerm)
Set the left relation term (right guard).- Parameters:
relationTerm- some term
-
-