Package org.tweetyproject.lp.asp.syntax
Class Program
java.lang.Object
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<ASPRule>
,Collection<ASPRule>
,Set<ASPRule>
,BeliefBase
,LogicProgram<ClassicalHead,
ASPBodyElement, ASPRule>
public class Program
extends RuleSet<ASPRule>
implements LogicProgram<ClassicalHead,ASPBodyElement,ASPRule>
This class models an ASP-Core-2 program, meaning a set of rules and
optionally a query. A program is ground if it contains no variables. The
rules are ordered alphabetically.
- Author:
- Tim Janus, Thomas Vengels, Anna Gessler
- See Also:
-
Constructor Summary
ConstructorDescriptionProgram()
Creates a new empty program.Program
(Collection<ASPRule> rules) Creates a new program with the given rules.Program
(ASPLiteral query, Set<ASPRule> rules) Creates a new program with the given query and rules.Creates a new program with the given rules.Copy-Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds another program's content to the content of this program.void
addFact
(ASPLiteral fact) Adds a fact to this program.void
addFact
(ClassicalHead fact) Adds the given fact to the programvoid
addFacts
(ClassicalHead... fact) Adds the given facts to the programboolean
Adds the given predicate to the whitelist of predicates.clone()
boolean
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.static Program
Creates the defaultification p_d of a given program p.Returns the signature of the language of this knowledge base.Returns the whitelist of predicates.getQuery()
Returns the query of the program, if there is one.getReduct
(Set<ASPLiteral> state) Returns the reduct of this program wrt.int
hashCode()
boolean
hasQuery()
Returns true if the program contains a query.boolean
Checks if the program is an extended program, meaning the heads of the literals do not have more than one literal.boolean
isGround()
Checks if the program is ground, meaning if it contains no rules with variables.boolean
isSafe()
Returns true if the program is safe, i.e.void
setAdditionalOptions
(Set<String> additionalOptions) Set additional options for solvers.void
Sets the whitelist of predicates.void
setQuery
(ASPLiteral query) Sets the query of the program.substitute
(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.substitute
(Term<?> v, Term<?> t) Substitutes all occurrences of term "v" in this formula by term "t" and returns the new formula.toString()
Methods inherited from class org.tweetyproject.commons.util.rules.RuleSet
getConclusions, getPremises, getRulesWithConclusion, getSyntacticModule
Methods inherited from class java.util.HashSet
add, clear, contains, isEmpty, iterator, newHashSet, remove, size, spliterator, toArray, toArray
Methods inherited from class java.util.AbstractSet
removeAll
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.Set
addAll, containsAll, removeAll, retainAll
-
Constructor Details
-
Program
public Program()Creates a new empty program. -
Program
Creates a new program with the given rules.- Parameters:
rules
- a set of rules
-
Program
Creates a new program with the given rules.- Parameters:
rules
- a set of rules
-
Program
Creates a new program with the given query and rules.- Parameters:
query
- a queryrules
- a set of rules
-
Program
-
-
Method Details
-
setQuery
-
addFact
Description copied from interface:LogicProgram
Adds the given fact to the program- Specified by:
addFact
in interfaceLogicProgram<ClassicalHead,
ASPBodyElement, ASPRule> - Parameters:
fact
- a fact
-
addFacts
Description copied from interface:LogicProgram
Adds the given facts to the program- Specified by:
addFacts
in interfaceLogicProgram<ClassicalHead,
ASPBodyElement, ASPRule> - Parameters:
fact
- some facts
-
setOutputWhitelist
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
-
addToOutputWhitelist
Adds the given predicate to the whitelist of predicates. Solvers that use this option will only show atoms over predicates in this set in their output.- Parameters:
p
- a Predicate- Returns:
- if the whitelist did not already contain the specified element
-
getOutputWhitelist
-
hasQuery
public boolean hasQuery()Returns true if the program contains a query.- Returns:
- true if the program has a query, false otherwise
-
getQuery
Returns the query of the program, if there is one.- Returns:
- a literal, or null if the program has no query
-
addFact
-
add
Adds another program's content to the content of this program.- Parameters:
other
- Reference to the other program.
-
getAdditionalOptions
-
setAdditionalOptions
-
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.
-
isSafe
public boolean isSafe()Returns true if the program is safe, i.e. if all of its rules and its query are safe according to the definition of safety given in the ASP-Core-2 standard.- Returns:
- true if the program is safe, false otherwise
-
isGround
public boolean isGround()Checks if the program is ground, meaning if it contains no rules with variables.- Returns:
- true if the program is ground, false otherwise
-
getMinimalSignature
Description copied from interface:BeliefBase
Returns the signature of the language of this knowledge base.- Specified by:
getMinimalSignature
in interfaceBeliefBase
- Specified by:
getMinimalSignature
in interfaceLogicProgram<ClassicalHead,
ASPBodyElement, ASPRule> - Returns:
- the signature of the language of this knowledge base.
-
substitute
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 interfaceLogicProgram<ClassicalHead,
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:
IllegalArgumentException
- if "v" and "t" are of different sorts
-
substitute
public Program substitute(Map<? extends Term<?>, ? extends Term<?>> map) throws IllegalArgumentExceptionDescription 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 interfaceLogicProgram<ClassicalHead,
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:
IllegalArgumentException
- if any term and its mapping are of different sorts
-
exchange
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 interfaceLogicProgram<ClassicalHead,
ASPBodyElement, ASPRule> - Parameters:
v
- a term.t
- a term.- Returns:
- a new logical formula with both "v" and "t" exchanged.
- Throws:
IllegalArgumentException
- if "v" and "t" are of different sorts
-
clone
-
getReduct
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
-
getDefaultification
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.
-
toString
- Specified by:
toString
in interfaceBeliefBase
- Specified by:
toString
in interfaceLogicProgram<ClassicalHead,
ASPBodyElement, ASPRule> - Overrides:
toString
in classAbstractCollection<ASPRule>
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<ASPRule>
- Specified by:
hashCode
in interfaceSet<ASPRule>
- Overrides:
hashCode
in classAbstractSet<ASPRule>
-
equals
- Specified by:
equals
in interfaceCollection<ASPRule>
- Specified by:
equals
in interfaceSet<ASPRule>
- Overrides:
equals
in classAbstractSet<ASPRule>
-