Package net.sf.tweety.lp.asp.syntax
Class Program
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- java.util.HashSet<T>
-
- net.sf.tweety.commons.util.rules.RuleSet<ASPRule>
-
- net.sf.tweety.lp.asp.syntax.Program
-
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<ASPRule>,Collection<ASPRule>,Set<ASPRule>,net.sf.tweety.commons.BeliefBase,net.sf.tweety.logics.commons.syntax.interfaces.LogicProgram<ASPHead,ASPBodyElement,ASPRule>
public class Program extends net.sf.tweety.commons.util.rules.RuleSet<ASPRule> implements net.sf.tweety.logics.commons.syntax.interfaces.LogicProgram<ASPHead,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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Program()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.Program(Program other)Copy-Constructor
-
Method Summary
Modifier and Type Method Description voidadd(Program other)Adds another program's content to the content of this program.voidaddAll(List<ASPRule> rules)voidaddFact(ASPHead fact)voidaddFact(ASPLiteral fact)Programclone()booleancontains(ASPRule r)Returns true if the program contains a given rule.static Programdefaultification(Program p)Creates the defaultification p_d of a given program p.Programexchange(net.sf.tweety.logics.commons.syntax.interfaces.Term<?> v, net.sf.tweety.logics.commons.syntax.interfaces.Term<?> t)net.sf.tweety.logics.fol.syntax.FolSignaturegetMinimalSignature()Set<net.sf.tweety.logics.commons.syntax.Predicate>getOutputWhitelist()Returns the whitelist of predicates.ASPLiteralgetQuery()Returns the query of the program, if there is one.Set<ASPRule>getRules()Returns all rules of the program.booleanhasQuery()Returns true if the program contains a query.booleanisExtendedProgram()Checks if the program is an extended program, meaning the heads of the literals do not have more than one literal.booleanisGround()booleanisSafe()Returns true if the program is safe, i.e.Programreduct(Set<ASPLiteral> state)Returns the reduct of this program wrt.voidsetOutputWhitelist(Collection<net.sf.tweety.logics.commons.syntax.Predicate> ps)Sets the whitelist of predicates.voidsetQuery(ASPLiteral query)Sets the query of the program.Programsubstitute(Map<? extends net.sf.tweety.logics.commons.syntax.interfaces.Term<?>,? extends net.sf.tweety.logics.commons.syntax.interfaces.Term<?>> map)Programsubstitute(net.sf.tweety.logics.commons.syntax.interfaces.Term<?> v, net.sf.tweety.logics.commons.syntax.interfaces.Term<?> t)StringtoString()-
Methods inherited from class net.sf.tweety.commons.util.rules.RuleSet
getConclusions, getPremises, getRulesWithConclusion, getSyntacticModule
-
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
-
-
-
-
Constructor Detail
-
Program
public Program()
Creates a new empty program.
-
Program
public Program(Collection<ASPRule> rules)
Creates a new program with the given rules.- Parameters:
rules- a set of rules
-
Program
public Program(ASPLiteral query, Set<ASPRule> rules)
Creates a new program with the given query and rules.- Parameters:
query- a queryrules- 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
-
addFact
public void addFact(ASPHead fact)
- Specified by:
addFactin interfacenet.sf.tweety.logics.commons.syntax.interfaces.LogicProgram<ASPHead,ASPBodyElement,ASPRule>
-
getMinimalSignature
public net.sf.tweety.logics.fol.syntax.FolSignature getMinimalSignature()
- Specified by:
getMinimalSignaturein interfacenet.sf.tweety.commons.BeliefBase- Specified by:
getMinimalSignaturein interfacenet.sf.tweety.logics.commons.syntax.interfaces.LogicProgram<ASPHead,ASPBodyElement,ASPRule>
-
substitute
public Program substitute(net.sf.tweety.logics.commons.syntax.interfaces.Term<?> v, net.sf.tweety.logics.commons.syntax.interfaces.Term<?> t) throws IllegalArgumentException
- Specified by:
substitutein interfacenet.sf.tweety.logics.commons.syntax.interfaces.LogicProgram<ASPHead,ASPBodyElement,ASPRule>- Throws:
IllegalArgumentException
-
substitute
public Program substitute(Map<? extends net.sf.tweety.logics.commons.syntax.interfaces.Term<?>,? extends net.sf.tweety.logics.commons.syntax.interfaces.Term<?>> map) throws IllegalArgumentException
- Specified by:
substitutein interfacenet.sf.tweety.logics.commons.syntax.interfaces.LogicProgram<ASPHead,ASPBodyElement,ASPRule>- Throws:
IllegalArgumentException
-
exchange
public Program exchange(net.sf.tweety.logics.commons.syntax.interfaces.Term<?> v, net.sf.tweety.logics.commons.syntax.interfaces.Term<?> t) throws IllegalArgumentException
- Specified by:
exchangein interfacenet.sf.tweety.logics.commons.syntax.interfaces.LogicProgram<ASPHead,ASPBodyElement,ASPRule>- Throws:
IllegalArgumentException
-
toString
public String toString()
- Specified by:
toStringin interfacenet.sf.tweety.commons.BeliefBase- Specified by:
toStringin interfacenet.sf.tweety.logics.commons.syntax.interfaces.LogicProgram<ASPHead,ASPBodyElement,ASPRule>- Overrides:
toStringin classAbstractCollection<ASPRule>
-
isGround
public boolean isGround()
-
setOutputWhitelist
public void setOutputWhitelist(Collection<net.sf.tweety.logics.commons.syntax.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 Set<net.sf.tweety.logics.commons.syntax.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
-
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
-
reduct
public Program reduct(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.
-
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
-
-