Class ConditionalStructure
- java.lang.Object
-
- net.sf.tweety.logics.cl.semantics.ConditionalStructure
-
- All Implemented Interfaces:
java.util.Comparator<NicePossibleWorld>
public class ConditionalStructure extends java.lang.Object implements java.util.Comparator<NicePossibleWorld>
Represents a conditional structure as introduced in Section 3.5 "Conditionals in Nonmonotonic Reasoning and Belief Revision" of Gabrielle Kern-Isberner Internally it saves the data to two nested Maps. The first map maps to each PossibleWorld a map of Conditionals to Generators and the second map maps to each Conditional a map of PossibleWorlds to Generators. Those two maps allow fast access to the data of the ConditionalStructure. The first map can be used to support a nice representation of the ConditionalStructure and the second map can be used for further processing depending on the Conditionals (for Kappa values in C-Representation for example). To change the representation of the ConditionalStructure the user can provide a Comparator<NicePossibleWorld> implementation that changes the sort behavior of the world data map or he/she can provide a Comparator<Pair<Proposition, Boolean>> to change the ordering of the literals in the NicePossibleWorld representation. The later approach will fit for most situations. The default sorting behavior depends on the representation behavior of NicePossibleWorld that can also be adapt because it uses the toString method() and sorts this string alphabetically so that all possible worlds for a,b,c are represented in the following order: a b c a b-c a-b c a-b-c -a b c -a b-c -a-b c -a-b-c The default Sorting provides a clean binary switching of true/false like counting a bit string. If the user wants another ordering like c a b the Sorting behavior of the NicePossibleWorld shall be adapted by providing a Comparator<Pair<Proposition, Boolean>> implementation that implements the relation "c < a < b" by using the setWorldRepresentation() method. If the user wants to use a sorting depending on the Generator count for the worlds the setWorldSorting() method can be used to provide the correct sorting method.- Author:
- Tim Janus
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConditionalStructure.Generator
The possible values of a conditional for a possible world
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<Conditional,java.util.SortedMap<NicePossibleWorld,ConditionalStructure.Generator>>
conditionalData
This maps saves the same data as worldData but uses another mapping allowing fast access to the Generators using Conditionals.private java.util.Map<Conditional,java.util.List<NicePossibleWorld>>
falsifyingWorlds
private PlSignature
signature
the signature of the conditional structureprivate java.util.Map<Conditional,java.util.List<NicePossibleWorld>>
verifyingWorlds
private java.util.SortedMap<NicePossibleWorld,java.util.Map<Conditional,ConditionalStructure.Generator>>
worldData
The data of the conditional structure maps to every PossibleWorld a map of Conditionals and their Generators.private java.util.Comparator<Pair<Proposition,java.lang.Boolean>>
worldRepresentation
The object used to sort the literals in the PossibleWorldprivate java.util.Comparator<NicePossibleWorld>
worldSorting
The object used to sort the Nice Possible worlds
-
Constructor Summary
Constructors Constructor Description ConditionalStructure()
Default-Ctor generates empty Conditional structureConditionalStructure(java.util.Collection<Conditional> conditionals)
Ctor: generates a conditional structure containing the given conditionalsConditionalStructure(java.util.Collection<Conditional> conditionals, java.util.Comparator<NicePossibleWorld> comparator)
Ctor: Generates a ConditionalStructure containing the given conditionals and using the given comparator to sort the worldData map.ConditionalStructure(java.util.Comparator<NicePossibleWorld> comparator)
Ctor: Generates an empty ConditionalStructure that uses the given Comparator to sort its worldData map.
-
Method Summary
Modifier and Type Method Description boolean
addConditional(Conditional cond)
Adds the given Conditional to the ConditionalStructure and updates the structure.void
clear()
Clears the ConditionalStructure, after calling this method the Structure is empty.int
compare(NicePossibleWorld o1, NicePossibleWorld o2)
java.util.Map<NicePossibleWorld,ConditionalStructure.Generator>
getConditionalGenerators(Conditional conditional)
Processes the Map form PossibleWorlds to the Generators of the given Conditionaljava.util.Set<Conditional>
getConditionals()
java.util.List<NicePossibleWorld>
getFalsifiyingWorlds(Conditional cond)
java.util.Set<NicePossibleWorld>
getPossibleWorlds()
java.util.Collection<Proposition>
getSignature()
java.util.List<NicePossibleWorld>
getVerifyingWorlds(Conditional cond)
java.util.Map<Conditional,ConditionalStructure.Generator>
getWorldGenerators(NicePossibleWorld world)
Processes the map from Conditionals to Generators for a given PossibleWorldprivate boolean
putGenerator(NicePossibleWorld npw, Conditional cond)
Processes the generator of the given Conditional cond for the PossibleWorld npw and saves it in the worldData data structure if it is not equal CG_ONE.boolean
removeConditional(Conditional cond)
Removes the given Conditional from the ConditionalStructure and updates the structure.void
setWorldRepresentation(java.util.Comparator<Pair<Proposition,java.lang.Boolean>> comparator)
Changes the internal representations of the worlds, normally the propositions of a world are ordered alphabetically but this behavior can be changed using this method.void
setWorldSorting(java.util.Comparator<NicePossibleWorld> comparator)
Changes the ordering of the PossibleWorlds for representation purposes, before using this method proof if the goal can be easier achieved using the setWorldRepresentation() method that allows changing the ordering of the literals in the world representation.java.lang.String
toString()
private void
updateSignature(java.util.Collection<Proposition> signature)
Update the data structure worldData by removing worlds that are not representable by the given signature and adding worlds that are new with the new signature.
-
-
-
Field Detail
-
worldData
private java.util.SortedMap<NicePossibleWorld,java.util.Map<Conditional,ConditionalStructure.Generator>> worldData
The data of the conditional structure maps to every PossibleWorld a map of Conditionals and their Generators. The PossibleWorld is implemented as NicePossibleWorld and therefore stores a data structure for it's representation that is used by the ConditionalStructure to represent itself
-
conditionalData
private java.util.Map<Conditional,java.util.SortedMap<NicePossibleWorld,ConditionalStructure.Generator>> conditionalData
This maps saves the same data as worldData but uses another mapping allowing fast access to the Generators using Conditionals. This is important for processing semantics like C-representations because they mainly depend on these mapping.
-
verifyingWorlds
private java.util.Map<Conditional,java.util.List<NicePossibleWorld>> verifyingWorlds
-
falsifyingWorlds
private java.util.Map<Conditional,java.util.List<NicePossibleWorld>> falsifyingWorlds
-
worldSorting
private java.util.Comparator<NicePossibleWorld> worldSorting
The object used to sort the Nice Possible worlds
-
worldRepresentation
private java.util.Comparator<Pair<Proposition,java.lang.Boolean>> worldRepresentation
The object used to sort the literals in the PossibleWorld
-
signature
private PlSignature signature
the signature of the conditional structure
-
-
Constructor Detail
-
ConditionalStructure
public ConditionalStructure()
Default-Ctor generates empty Conditional structure
-
ConditionalStructure
public ConditionalStructure(java.util.Comparator<NicePossibleWorld> comparator)
Ctor: Generates an empty ConditionalStructure that uses the given Comparator to sort its worldData map.- Parameters:
comparator
- An implementation for sorting the world data if null is given the default sorting behavior is used.
-
ConditionalStructure
public ConditionalStructure(java.util.Collection<Conditional> conditionals)
Ctor: generates a conditional structure containing the given conditionals- Parameters:
conditionals
- A collection of conditionals that shall form the ConditionalStructure
-
ConditionalStructure
public ConditionalStructure(java.util.Collection<Conditional> conditionals, java.util.Comparator<NicePossibleWorld> comparator)
Ctor: Generates a ConditionalStructure containing the given conditionals and using the given comparator to sort the worldData map.- Parameters:
conditionals
- A collection of conditionals that shall form the ConditionalStructurecomparator
- An implementation for sorting the world data if null is given the default sorting behavior is used.
-
-
Method Detail
-
getConditionals
public java.util.Set<Conditional> getConditionals()
- Returns:
- An unmodifiable set of all conditionals in this ConditionalStructure
-
getPossibleWorlds
public java.util.Set<NicePossibleWorld> getPossibleWorlds()
- Returns:
- An unmodifiable set of all possible worlds in this ConditionalStructure
-
getFalsifiyingWorlds
public java.util.List<NicePossibleWorld> getFalsifiyingWorlds(Conditional cond)
-
getVerifyingWorlds
public java.util.List<NicePossibleWorld> getVerifyingWorlds(Conditional cond)
-
getWorldGenerators
public java.util.Map<Conditional,ConditionalStructure.Generator> getWorldGenerators(NicePossibleWorld world)
Processes the map from Conditionals to Generators for a given PossibleWorld- Parameters:
world
- The PossibleWorld thats Generators shall be returned- Returns:
- A map containing all Generators for the world as values and the associated conditionals as key.
-
getConditionalGenerators
public java.util.Map<NicePossibleWorld,ConditionalStructure.Generator> getConditionalGenerators(Conditional conditional)
Processes the Map form PossibleWorlds to the Generators of the given Conditional- Parameters:
conditional
- The Conditional- Returns:
- null if no such map exists or the map mapping the PossibleWorlds to Generators for the given Conditional
-
getSignature
public java.util.Collection<Proposition> getSignature()
- Returns:
- An unmodifiable Collection containing all propositions that altogether form the signature of the ConditionalStructure
-
setWorldSorting
public void setWorldSorting(java.util.Comparator<NicePossibleWorld> comparator)
Changes the ordering of the PossibleWorlds for representation purposes, before using this method proof if the goal can be easier achieved using the setWorldRepresentation() method that allows changing the ordering of the literals in the world representation.- Parameters:
comparator
- The implementation sorting the possible worlds
-
setWorldRepresentation
public void setWorldRepresentation(java.util.Comparator<Pair<Proposition,java.lang.Boolean>> comparator)
Changes the internal representations of the worlds, normally the propositions of a world are ordered alphabetically but this behavior can be changed using this method.- Parameters:
comparator
- The new implementation of a Comparator that provides the new sorting behavior for the Propositions in a PossibleWorld.
-
addConditional
public boolean addConditional(Conditional cond)
Adds the given Conditional to the ConditionalStructure and updates the structure.- Parameters:
cond
- The new Conditional- Returns:
- True if the conditional is added and ConditionalStructure is updated, false if the Conditional is already part of the ConditionalStructure
-
removeConditional
public boolean removeConditional(Conditional cond)
Removes the given Conditional from the ConditionalStructure and updates the structure.- Parameters:
cond
- The Conditional that shall be removed- Returns:
- True if the Conditional is part of the ConditionalStructure and was removed, false if the Conditional is not part of the ConditionalStructure and nothing happened.
-
clear
public void clear()
Clears the ConditionalStructure, after calling this method the Structure is empty.
-
updateSignature
private void updateSignature(java.util.Collection<Proposition> signature)
Update the data structure worldData by removing worlds that are not representable by the given signature and adding worlds that are new with the new signature.- Parameters:
signature
- The propositional signature representing the problem domain.
-
putGenerator
private boolean putGenerator(NicePossibleWorld npw, Conditional cond)
Processes the generator of the given Conditional cond for the PossibleWorld npw and saves it in the worldData data structure if it is not equal CG_ONE.- Parameters:
npw
- The PossibleWorldcond
- The Conditional- Returns:
- True if the Generator is not equal CG_ONe and is added to worldData or false if the Generator is CG_ONE and is not added to worldData.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
compare
public int compare(NicePossibleWorld o1, NicePossibleWorld o2)
- Specified by:
compare
in interfacejava.util.Comparator<NicePossibleWorld>
-
-