Package org.tweetyproject.lp.asp.syntax
Class AggregateAtom
java.lang.Object
org.tweetyproject.lp.asp.syntax.ASPElement
org.tweetyproject.lp.asp.syntax.ASPBodyElement
org.tweetyproject.lp.asp.syntax.AggregateAtom
- All Implemented Interfaces:
Formula
,ComplexLogicalFormula
,LogicStructure
,SimpleLogicalFormula
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 can easily express "the number of employees of
a department has to be greater than 0".
An aggregate function together with the terms and literals it ranges over and a comparison (like >= 0) is called an aggregate atom and can appear in the body of a rule.
If you want to use an aggregate atom as the head of a rule (as is allowed in some standards like clingo), use
An aggregate function together with the terms and literals it ranges over and a comparison (like >= 0) is called an aggregate atom and can appear in the body of a rule.
If you want to use an aggregate atom as the head of a rule (as is allowed in some standards like clingo), use
AggregateHead
- Author:
- Tim Janus, Thomas Vengels, Anna Gessler
-
Constructor Summary
ConstructorDescriptionEmpty default constructor.AggregateAtom
(List<ASPBodyElement> literals, int leftBound, int rightBound) Creates a new cardinality rule, meaning an aggregate of the form "leftBound <= #count { elements } <= rightBound" with the given literals and the given integer bounds.AggregateAtom
(AggregateAtom other) Copy-ConstructorAggregateAtom
(ASPOperator.AggregateFunction function, List<AggregateElement> elements) Creates a new Aggregate with the given aggregate function and the given aggregate elements.AggregateAtom
(ASPOperator.AggregateFunction function, List<AggregateElement> elements, ASPOperator.BinaryOperator rightRelation, int rightBound) Creates a new Aggregate of the form "#func { elements } op rightBound" with the given aggregate function #func, the given aggregate elements, the given aggregate relation op and the given rightBound.AggregateAtom
(ASPOperator.AggregateFunction function, List<AggregateElement> elements, ASPOperator.BinaryOperator leftRelation, int leftBound, ASPOperator.BinaryOperator rightRelation, int rightBound) Creates a new Aggregate of the form "leftBound op #func { elements } op rightBound" with the given aggregate function, the given aggregate elements, and the given left and right aggregate relations and integer bounds.AggregateAtom
(ASPOperator.AggregateFunction function, List<AggregateElement> elements, ASPOperator.BinaryOperator rightRelation, Term<?> rightBound) Creates a new Aggregate of the form "#func { elements } op rightBound" with the given aggregate function #func, the given aggregate elements, the given aggregate relation op and the given rightBound.AggregateAtom
(ASPOperator.AggregateFunction function, List<AggregateElement> elements, ASPOperator.BinaryOperator leftRelation, Term<?> leftBound, ASPOperator.BinaryOperator rightRelation, Term<?> rightBound) Creates a new Aggregate of the form "leftBound leftOp #func { elements } rightOp rightBound" with the given aggregate function, the given aggregate elements, and the given left and right aggregate relations and bounds. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Creates a deep copy of this formulaboolean
getAtoms()
Processes the set of all atoms which appear in this formulaTerm<?>
Get the left relation term (left guard).Returns the operator of the left aggregate relation.Returns all literals in this element in form of a SortedSet.Processes the set of all predicates which appear in this formulaTerm<?>
Returns the operator of the right aggregate relation.Returns the signature of the language of this formula.getTerms()
Processes the set containing all terms of type C.int
hashCode()
boolean
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).boolean
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).boolean
Returns a representation of this ASP element in clingo (potassco) syntax.Returns a representation of this ASP element in DLV syntax.void
setAggregateElements
(List<AggregateElement> aggregateElements) Set the elements that the aggregate ranges over.void
setFunction
(ASPOperator.AggregateFunction function) Sets the aggregate function.void
setLeft
(int term, ASPOperator.BinaryOperator op) Set the left relation term and operator.void
setLeft
(Term<?> term, ASPOperator.BinaryOperator op) Set the left relation term and operator.void
setLeftGuard
(int relationTerm) Set the left relation term (left guard).void
setLeftGuard
(Term<?> relationTerm) Set the left relation term (left guard).void
Sets the operator of the left aggregate relation.void
setRight
(int term, ASPOperator.BinaryOperator op) Set the right relation term and operator.void
setRight
(Term<?> term, ASPOperator.BinaryOperator op) Set the right relation term and operator.void
setRightGuard
(int relationTerm) Set the right relation term (right guard).void
setRightGuard
(Term<?> relationTerm) Set the right relation term (right guard).void
Sets the operator of the right aggregate relation.substitute
(Term<?> t, Term<?> v) Substitutes all occurrences of term "v" in this formula by term "t" and returns the new formula.toString()
Methods inherited from class org.tweetyproject.lp.asp.syntax.ASPElement
containsTermsOfType, exchange, getPredicateCls, isGround, isWellFormed, substitute
-
Constructor Details
-
AggregateAtom
public AggregateAtom()Empty default constructor. -
AggregateAtom
Creates a new Aggregate with the given aggregate function and the given aggregate elements.- Parameters:
function
- an aggregate functionelements
- list of aggregate elements
-
AggregateAtom
public AggregateAtom(ASPOperator.AggregateFunction function, List<AggregateElement> elements, ASPOperator.BinaryOperator rightRelation, Term<?> rightBound) Creates a new Aggregate of the form "#func { elements } op rightBound" with the given aggregate function #func, the given aggregate elements, the given aggregate relation op and the given rightBound.- Parameters:
function
- an aggregate functionelements
- list of aggregate elementsrightRelation
- the relationrightBound
- some term
-
AggregateAtom
public AggregateAtom(ASPOperator.AggregateFunction function, List<AggregateElement> elements, ASPOperator.BinaryOperator rightRelation, int rightBound) Creates a new Aggregate of the form "#func { elements } op rightBound" with the given aggregate function #func, the given aggregate elements, the given aggregate relation op and the given rightBound.- Parameters:
function
- an aggregate functionelements
- list of aggregate elementsrightRelation
- the relationrightBound
- integer
-
AggregateAtom
public AggregateAtom(ASPOperator.AggregateFunction function, List<AggregateElement> elements, ASPOperator.BinaryOperator leftRelation, Term<?> leftBound, ASPOperator.BinaryOperator rightRelation, Term<?> rightBound) Creates a new Aggregate of the form "leftBound leftOp #func { elements } rightOp rightBound" with the given aggregate function, the given aggregate elements, and the given left and right aggregate relations and bounds.- Parameters:
function
- an aggregate functionelements
- list of aggregate elementsleftRelation
-leftBound
- termrightRelation
-rightBound
- term
-
AggregateAtom
public AggregateAtom(ASPOperator.AggregateFunction function, List<AggregateElement> elements, ASPOperator.BinaryOperator leftRelation, int leftBound, ASPOperator.BinaryOperator rightRelation, int rightBound) Creates a new Aggregate of the form "leftBound op #func { elements } op rightBound" with the given aggregate function, the given aggregate elements, and the given left and right aggregate relations and integer bounds.- Parameters:
function
- an aggregate functionelements
- list of aggregate elementsleftRelation
-leftBound
- integerrightRelation
-rightBound
- integer
-
AggregateAtom
Creates a new cardinality rule, meaning an aggregate of the form "leftBound <= #count { elements } <= rightBound" with the given literals and the given integer bounds.- Parameters:
literals
- of the cardinality ruleleftBound
- of the cardinality rulerightBound
- of the cardinality rule
-
AggregateAtom
Copy-Constructor- Parameters:
other
- another AggregateAtom
-
-
Method Details
-
getLiterals
Description copied from class:ASPBodyElement
Returns all literals in this element in form of a SortedSet. Literals are atoms or strict negations of atoms.- Specified by:
getLiterals
in classASPBodyElement
- Returns:
- all the literals used in the rule element
-
getPredicates
Description copied from interface:SimpleLogicalFormula
Processes the set of all predicates which appear in this formula- Specified by:
getPredicates
in interfaceSimpleLogicalFormula
- Specified by:
getPredicates
in classASPElement
- Returns:
- all predicates that appear in this formula
-
getAtoms
Description copied from interface:SimpleLogicalFormula
Processes the set of all atoms which appear in this formula- Specified by:
getAtoms
in interfaceSimpleLogicalFormula
- Specified by:
getAtoms
in classASPElement
- Returns:
- The set of all atoms
-
substitute
Description copied from interface:ComplexLogicalFormula
Substitutes all occurrences of term "v" in this formula by term "t" and returns the new formula.- Specified by:
substitute
in interfaceComplexLogicalFormula
- Specified by:
substitute
in 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
Description copied from interface:Formula
Returns the signature of the language of this formula.- Specified by:
getSignature
in interfaceFormula
- Specified by:
getSignature
in classASPElement
- Returns:
- the signature of the language of this formula.
-
clone
Description copied from interface:SimpleLogicalFormula
Creates a deep copy of this formula- Specified by:
clone
in interfaceComplexLogicalFormula
- Specified by:
clone
in interfaceSimpleLogicalFormula
- Specified by:
clone
in classASPElement
- Returns:
- the cloned formula
-
isLiteral
public boolean isLiteral()- Returns:
- true if the formula represents a literal in the language or false otherwise
-
getTerms
- Returns:
- a set containing all terms of this logical structure
-
getTerms
Description copied from interface:LogicStructure
Processes 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
- Returns:
- the elements that the aggregate ranges over.
-
setAggregateElements
Set the elements that the aggregate ranges over.- Parameters:
aggregateElements
-
-
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
- Returns:
- the aggregate function
-
setFunction
Sets the aggregate function.- Parameters:
function
- an aggregate function
-
getRightOperator
Returns the operator of the right aggregate relation.- Returns:
- comparative operator
-
setRightOperator
Sets the operator of the right aggregate relation.- Parameters:
op
- comparative operator
-
getRightGuard
- Returns:
- the right relation term (right guard).
-
setRightGuard
Set the right relation term (right guard).- Parameters:
relationTerm
- some term
-
setRightGuard
public void setRightGuard(int relationTerm) Set the right relation term (right guard).- Parameters:
relationTerm
- some integer
-
setRight
Set the right relation term and operator.- Parameters:
term
-op
-
-
setRight
Set the right relation term and operator.- Parameters:
term
- , an integerop
-
-
getLeftOperator
Returns the operator of the left aggregate relation.- Returns:
- comparative operator
-
setLeftOperator
Sets the operator of the left aggregate relation.- Parameters:
op
- comparative operator
-
getLeftGuard
Get the left relation term (left guard).- Returns:
- Term
-
setLeftGuard
Set the left relation term (left guard).- Parameters:
relationTerm
- some term
-
setLeftGuard
public void setLeftGuard(int relationTerm) Set the left relation term (left guard).- Parameters:
relationTerm
- some integer
-
setLeft
Set the left relation term and operator.- Parameters:
term
-op
-
-
setLeft
Set the left relation term and operator.- Parameters:
term
- , an integerop
-
-
toString
-
printToClingo
Description copied from class:ASPElement
Returns a representation of this ASP element in clingo (potassco) syntax. See https://potassco.org/ for more information.- Overrides:
printToClingo
in classASPElement
- Returns:
- String representation in clingo syntax
-
printToDLV
Description copied from class:ASPElement
Returns a representation of this ASP element in DLV syntax. See http://www.dlvsystem.com/html/DLV_User_Manual.html for more information.- Overrides:
printToDLV
in classASPElement
- Returns:
- String representation in DLV syntax
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceSimpleLogicalFormula
- Overrides:
hashCode
in classObject
-
equals
- Specified by:
equals
in interfaceSimpleLogicalFormula
- Overrides:
equals
in classObject
-