Class NicePossibleWorld
- java.lang.Object
-
- net.sf.tweety.commons.AbstractInterpretation<B,S>
-
- net.sf.tweety.commons.InterpretationSet<Proposition,PlBeliefSet,PlFormula>
-
- net.sf.tweety.logics.pl.semantics.NicePossibleWorld
-
- All Implemented Interfaces:
java.lang.Iterable<Proposition>
,java.util.Collection<Proposition>
,java.util.Comparator<Pair<Proposition,java.lang.Boolean>>
,Interpretation<PlBeliefSet,PlFormula>
public class NicePossibleWorld extends InterpretationSet<Proposition,PlBeliefSet,PlFormula> implements java.util.Comparator<Pair<Proposition,java.lang.Boolean>>
Wrapper for the PossibleWorld providing better representation mechanisms, it knows all the possible propositions (the signature) and therefore provides a complete representation that maps a boolean to the Proposition. It also provides ordering of the (proposition, boolean) pairs in the enhanced representation. The default behavior is an alphabetically ordering of the Propositions but it can be changed by the user. Internally it uses the smaller and therefore faster implementation of PossibleWorld for satisfication test- Author:
- Tim Janus
-
-
Constructor Summary
Constructors Constructor Description NicePossibleWorld(java.util.Collection<Proposition> trueInWorld, java.util.Collection<Proposition> signature)
Ctor: Generates the possible world using the given set of true propositions and generated a representation of the possible world using the given signature.NicePossibleWorld(java.util.Collection<Proposition> trueInWorld, java.util.Collection<Proposition> signature, java.util.Comparator<Pair<Proposition,java.lang.Boolean>> comparator)
Ctor: Generates the possible world using the given set of true propositions and generated a representation of the possible world using the given signature.
-
Method Summary
Modifier and Type Method Description int
compare(Pair<Proposition,java.lang.Boolean> o1, Pair<Proposition,java.lang.Boolean> o2)
boolean
equals(java.lang.Object other)
static java.util.Set<NicePossibleWorld>
getAllPossibleWorlds(java.util.Collection<Proposition> signature)
PossibleWorld
getOptimizedWorld()
java.util.Set<Pair<Proposition,java.lang.Boolean>>
getRepresentationStructure()
int
hashCode()
boolean
satisfies(PlBeliefSet beliefBase)
Checks whether this interpretation satisfies the given knowledge base.boolean
satisfies(PlFormula formula)
Checks whether this interpretation satisfies the given formula.void
setComparator(java.util.Comparator<Pair<Proposition,java.lang.Boolean>> comparator)
Changes the used comparator to sort the representation structure and resorts the representation.boolean
setSignature(java.util.Collection<Proposition> signature)
Changes the signature of the world.java.lang.String
toString()
-
Methods inherited from class net.sf.tweety.commons.InterpretationSet
add, add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
-
Methods inherited from class net.sf.tweety.commons.AbstractInterpretation
satisfies
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
-
-
-
Constructor Detail
-
NicePossibleWorld
public NicePossibleWorld(java.util.Collection<Proposition> trueInWorld, java.util.Collection<Proposition> signature)
Ctor: Generates the possible world using the given set of true propositions and generated a representation of the possible world using the given signature. The default alphabetically sort behavior is used to order the representation.- Parameters:
trueInWorld
- A set of propositions describing those propositions that are true in this possible world. It has to be a subset of signature.signature
- A set of propositions describing all know propositions by the the problem, the signature. It has to be a super set of trueInWorld
-
NicePossibleWorld
public NicePossibleWorld(java.util.Collection<Proposition> trueInWorld, java.util.Collection<Proposition> signature, java.util.Comparator<Pair<Proposition,java.lang.Boolean>> comparator)
Ctor: Generates the possible world using the given set of true propositions and generated a representation of the possible world using the given signature. The sort behavior given in comparator is used to order the representation.- Parameters:
trueInWorld
- A set of propositions describing those propositions that are true in this possible world. It has to be a subset of signature.signature
- A set of propositions describing all know propositions by the the problem, the signature. It has to be a super set of trueInWorldcomparator
- The comparator
-
-
Method Detail
-
setSignature
public boolean setSignature(java.util.Collection<Proposition> signature)
Changes the signature of the world. That means the set of propositions has changed. The new set might contain new propositions and delete old propositions. The representation data structure is updated to reflect the new signature. There is a border case if a Proposition is deleted that is true in this world. Then the world is not representable with the given signature anymore, if this is the case then the representation data structure is cleared.- Parameters:
signature
- A collection of propositions defining the new signature.- Returns:
- true if representation is successfully updated and false if the world is not representable by the given signature anymore.
-
setComparator
public void setComparator(java.util.Comparator<Pair<Proposition,java.lang.Boolean>> comparator)
Changes the used comparator to sort the representation structure and resorts the representation. The default behavior is an alphabetically ordering. The default behavior is selected if null is given as argument or if an instance of the NicePossibleWorld is given as argument.- Parameters:
comparator
- The new comparator used to sort the representation. If a null is given the default alphabetically ordering is used.
-
getOptimizedWorld
public PossibleWorld getOptimizedWorld()
- Returns:
- The PossibleWorld instance that is used for satification tests etc.
-
getRepresentationStructure
public java.util.Set<Pair<Proposition,java.lang.Boolean>> getRepresentationStructure()
- Returns:
- The representation structure as a set of (proposition, boolean) pairs.
-
satisfies
public boolean satisfies(PlFormula formula) throws java.lang.IllegalArgumentException
Description copied from interface:Interpretation
Checks whether this interpretation satisfies the given formula.- Specified by:
satisfies
in interfaceInterpretation<PlBeliefSet,PlFormula>
- Parameters:
formula
- a formula .- Returns:
- "true" if this interpretation satisfies the given formula.
- Throws:
java.lang.IllegalArgumentException
- if the formula does not correspond to the expected language.
-
satisfies
public boolean satisfies(PlBeliefSet beliefBase) throws java.lang.IllegalArgumentException
Description copied from interface:Interpretation
Checks whether this interpretation satisfies the given knowledge base.- Specified by:
satisfies
in interfaceInterpretation<PlBeliefSet,PlFormula>
- Parameters:
beliefBase
- a knowledge base.- Returns:
- "true" if this interpretation satisfies the given knowledge base.
- Throws:
java.lang.IllegalArgumentException
- IllegalArgumentException if the knowledgebase does not correspond to the expected language.
-
equals
public boolean equals(java.lang.Object other)
- Specified by:
equals
in interfacejava.util.Collection<Proposition>
- Specified by:
equals
in interfacejava.util.Comparator<Pair<Proposition,java.lang.Boolean>>
- Overrides:
equals
in classInterpretationSet<Proposition,PlBeliefSet,PlFormula>
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfacejava.util.Collection<Proposition>
- Overrides:
hashCode
in classInterpretationSet<Proposition,PlBeliefSet,PlFormula>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classInterpretationSet<Proposition,PlBeliefSet,PlFormula>
-
compare
public int compare(Pair<Proposition,java.lang.Boolean> o1, Pair<Proposition,java.lang.Boolean> o2)
- Specified by:
compare
in interfacejava.util.Comparator<Pair<Proposition,java.lang.Boolean>>
-
getAllPossibleWorlds
public static java.util.Set<NicePossibleWorld> getAllPossibleWorlds(java.util.Collection<Proposition> signature)
-
-