Class 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 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 AggregateHead
    Author:
    Tim Janus, Thomas Vengels, Anna Gessler
    • Constructor Detail

      • AggregateAtom

        public AggregateAtom()
        Empty default constructor.
      • AggregateAtom

        public AggregateAtom​(ASPOperator.AggregateFunction function,
                             java.util.List<AggregateElement> elements)
        Creates a new Aggregate with the given aggregate function and the given aggregate elements.
        Parameters:
        function - an aggregate function
        elements - list of aggregate elements
      • AggregateAtom

        public AggregateAtom​(ASPOperator.AggregateFunction function,
                             java.util.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 function
        elements - list of aggregate elements
        rightRelation - the relation
        rightBound - some term
      • AggregateAtom

        public AggregateAtom​(ASPOperator.AggregateFunction function,
                             java.util.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 function
        elements - list of aggregate elements
        rightRelation - the relation
        rightBound - integer
      • AggregateAtom

        public AggregateAtom​(ASPOperator.AggregateFunction function,
                             java.util.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 function
        elements - list of aggregate elements
        leftRelation -
        leftBound - term
        rightRelation -
        rightBound - term
      • AggregateAtom

        public AggregateAtom​(ASPOperator.AggregateFunction function,
                             java.util.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 function
        elements - list of aggregate elements
        leftRelation -
        leftBound - integer
        rightRelation -
        rightBound - integer
      • AggregateAtom

        public AggregateAtom​(java.util.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.
        Parameters:
        literals - of the cardinality rule
        leftBound - of the cardinality rule
        rightBound - of the cardinality rule
      • AggregateAtom

        public AggregateAtom​(AggregateAtom other)
        Copy-Constructor
        Parameters:
        other - another AggregateAtom
    • Method Detail

      • getLiterals

        public java.util.SortedSet<ASPLiteral> 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 class ASPBodyElement
        Returns:
        all the literals used in the rule element
      • getSignature

        public FolSignature getSignature()
        Description copied from interface: Formula
        Returns the signature of the language of this formula.
        Specified by:
        getSignature in interface Formula
        Specified by:
        getSignature in class ASPElement
        Returns:
        the signature of the language of this 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: 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

        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
      • 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).
      • 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
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • printToClingo

        public java.lang.String 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 class ASPElement
        Returns:
        String representation in clingo syntax