Class Program

    • Constructor Summary

      Constructors 
      Constructor Description
      Program()
      Creates a new empty program.
      Program​(java.util.Collection<ASPRule> rules)
      Creates a new program with the given rules.
      Program​(ASPLiteral query, java.util.Set<ASPRule> rules)
      Creates a new program with the given query and rules.
      Program​(Program other)
      Copy-Constructor
    • Method Summary

      Modifier and Type Method Description
      void add​(Program other)
      Adds another program's content to the content of this program.
      void addAll​(java.util.List<ASPRule> rules)  
      void addFact​(ASPHead fact)
      Adds the given fact to the program
      void addFact​(ASPLiteral fact)  
      Program clone()  
      boolean contains​(ASPRule r)
      Returns true if the program contains a given rule.
      static Program defaultification​(Program p)
      Creates the defaultification p_d of a given program p.
      Program exchange​(Term<?> v, Term<?> t)
      Substitutes all occurrences of term "v" in this formula by term "t" and at the same time replaces all occurrences of term "t" by term "v" and eventually returns the new formula.
      FolSignature getMinimalSignature()
      Returns the signature of the language of this knowledge base.
      java.util.Set<Predicate> getOutputWhitelist()
      Returns the whitelist of predicates.
      private java.util.Set<Predicate> getPredicates()
      Processes the set of all predicates which appear in this program.
      ASPLiteral getQuery()
      Returns the query of the program, if there is one.
      java.util.Set<ASPRule> getRules()
      Returns all rules of the program.
      boolean hasQuery()
      Returns true if the program contains a query.
      boolean isExtendedProgram()
      Checks if the program is an extended program, meaning the heads of the literals do not have more than one literal.
      boolean isGround()  
      boolean isSafe()
      Returns true if the program is safe, i.e.
      Program reduct​(java.util.Set<ASPLiteral> state)
      Returns the reduct of this program wrt.
      void setOutputWhitelist​(java.util.Collection<Predicate> ps)
      Sets the whitelist of predicates.
      void setQuery​(ASPLiteral query)
      Sets the query of the program.
      Program substitute​(java.util.Map<? extends Term<?>,​? extends Term<?>> map)
      Substitutes all occurrences of all terms "v" in map.keyset() in this formula by map.get(v) and returns the new formula.
      Program substitute​(Term<?> v, Term<?> t)
      Substitutes all occurrences of term "v" in this formula by term "t" and returns the new formula.
      java.lang.String toString()  
      • Methods inherited from class java.util.HashSet

        add, clear, contains, isEmpty, iterator, remove, size, spliterator
      • Methods inherited from class java.util.AbstractSet

        equals, hashCode, removeAll
      • Methods inherited from class java.util.AbstractCollection

        addAll, containsAll, retainAll, toArray, toArray
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        addAll, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
    • Field Detail

      • rules

        private java.util.Set<ASPRule> rules
        The rules of the programs, including facts (rules with no body) and weak constraint (rules with no head).
      • output_predicate_whitelist

        private java.util.Set<Predicate> output_predicate_whitelist
        Optional field that can be used by some solvers. If used, all atoms will be hidden from the output of the solver except for those with whitelisted predicates. This corresponds to the #show statement of the clingo input language.
    • Constructor Detail

      • Program

        public Program()
        Creates a new empty program.
      • Program

        public Program​(java.util.Collection<ASPRule> rules)
        Creates a new program with the given rules.
        Parameters:
        rules - a set of rules
      • Program

        public Program​(ASPLiteral query,
                       java.util.Set<ASPRule> rules)
        Creates a new program with the given query and rules.
        Parameters:
        query - a query
        rules - a set of rules
      • Program

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

      • setQuery

        public void setQuery​(ASPLiteral query)
        Sets the query of the program.
        Parameters:
        query - a literal
      • substitute

        public Program substitute​(Term<?> v,
                                  Term<?> t)
                           throws java.lang.IllegalArgumentException
        Description copied from interface: LogicProgram
        Substitutes all occurrences of term "v" in this formula by term "t" and returns the new formula.
        Specified by:
        substitute in interface LogicProgram<ASPHead,​ASPBodyElement,​ASPRule>
        Parameters:
        v - the term to be substituted.
        t - the term to substitute.
        Returns:
        a formula where every occurrence of "v" is replaced by "t".
        Throws:
        java.lang.IllegalArgumentException - if "v" and "t" are of different sorts
      • substitute

        public Program substitute​(java.util.Map<? extends Term<?>,​? extends Term<?>> map)
                           throws java.lang.IllegalArgumentException
        Description copied from interface: LogicProgram
        Substitutes all occurrences of all terms "v" in map.keyset() in this formula by map.get(v) and returns the new formula.
        Specified by:
        substitute in interface LogicProgram<ASPHead,​ASPBodyElement,​ASPRule>
        Parameters:
        map - a mapping defining which terms to be substituted.
        Returns:
        a formula where every term in map.keyset() has been replaced by map.get(v).
        Throws:
        java.lang.IllegalArgumentException - if any term and its mapping are of different sorts
      • exchange

        public Program exchange​(Term<?> v,
                                Term<?> t)
                         throws java.lang.IllegalArgumentException
        Description copied from interface: LogicProgram
        Substitutes all occurrences of term "v" in this formula by term "t" and at the same time replaces all occurrences of term "t" by term "v" and eventually returns the new formula.
        Specified by:
        exchange in interface LogicProgram<ASPHead,​ASPBodyElement,​ASPRule>
        Parameters:
        v - a term.
        t - a term.
        Returns:
        a new logical formula with both "v" and "t" exchanged.
        Throws:
        java.lang.IllegalArgumentException - if "v" and "t" are of different sorts
      • isGround

        public boolean isGround()
      • clone

        public Program clone()
        Overrides:
        clone in class java.util.HashSet<ASPRule>
      • setOutputWhitelist

        public void setOutputWhitelist​(java.util.Collection<Predicate> ps)
        Sets the whitelist of predicates. Solvers that use this option will only show atoms over predicates in this set in their output.
        Parameters:
        ps - set of predicates
      • getOutputWhitelist

        public java.util.Set<Predicate> getOutputWhitelist()
        Returns the whitelist of predicates. Solvers that use this option will only show atoms over predicates in this set in their output.
        Returns:
        set of whitelisted predicates
      • getPredicates

        private java.util.Set<Predicate> getPredicates()
        Processes the set of all predicates which appear in this program.
        Returns:
        set of predicates
      • hasQuery

        public boolean hasQuery()
        Returns true if the program contains a query.
        Returns:
        true if the program has a query, false otherwise
      • getQuery

        public ASPLiteral getQuery()
        Returns the query of the program, if there is one.
        Returns:
        a literal, or null if the program has no query
      • getRules

        public java.util.Set<ASPRule> getRules()
        Returns all rules of the program.
        Returns:
        set of rules
      • reduct

        public Program reduct​(java.util.Set<ASPLiteral> state)
        Returns the reduct of this program wrt. the given state, i.e. a program that contains no default negation and only those rules of this program (without all default-negated literals in the body) that do not have a default-negated version of a literal in their body.
        Parameters:
        state - some set of literals
        Returns:
        the reduct of this program
      • defaultification

        public static Program defaultification​(Program p)
        Creates the defaultification p_d of a given program p. A defaultificated program p' of p adds for every Rule r in p a modified rule r_d of the form: 'H(r) :- B(r), not -H(r).' to the program p'.
        Parameters:
        p - The program which is not defaultificated yet
        Returns:
        a program p' which is the defaultificated version of p.
      • addFact

        public void addFact​(ASPLiteral fact)
      • isExtendedProgram

        public boolean isExtendedProgram()
        Checks if the program is an extended program, meaning the heads of the literals do not have more than one literal.
        Returns:
        True if the program is an extended program, false otherwise.
      • add

        public void add​(Program other)
        Adds another program's content to the content of this program.
        Parameters:
        other - Reference to the other program.
      • addAll

        public void addAll​(java.util.List<ASPRule> rules)
      • contains

        public boolean contains​(ASPRule r)
        Returns true if the program contains a given rule.
        Parameters:
        r - an ASP rule
        Returns:
        true if program contains r
      • isSafe

        public boolean isSafe()
        Returns true if the program is safe, i.e. if all of its rules and its query are safe.
        Returns:
        true if the program is safe, false otherwise