ai.planning.propositional
Class WorldState

java.lang.Object
  extended by ai.planning.propositional.WorldState
All Implemented Interfaces:
WorldState<ai.krr.propositions.Atom>, java.lang.Iterable<ai.krr.propositions.Atom>

public class WorldState
extends java.lang.Object
implements WorldState<ai.krr.propositions.Atom>

A WorldState is a logical representation of all the facts that are true in the state of the world represented by this WorldState. In AI planning this is often called a situation. In the propositional representation a WorldState consists of the set of propositional Atoms that are true in the represented situation. Atoms not in the set are considered to be false, i.e. this representation assumes a closed world.

Author:
Gerhard Wickler
See Also:
Atom

Field Summary
protected  java.util.Set<ai.krr.propositions.Atom> holding
          the set of Atoms that hold in this state
 
Constructor Summary
WorldState()
           This constructor creates a new empty WorldState.
WorldState(ai.krr.propositions.Atom... atoms)
           This constructor creates a new WorldState in which exactly the given Atoms are true.
WorldState(java.util.Set<ai.krr.propositions.Atom> atoms)
           This constructor creates a new WorldState in which exactly the given Atoms are true.
 
Method Summary
 void add(ai.krr.propositions.Atom atom)
           This function asserts the given Atom in this WorldState.
 void addAll(ai.krr.propositions.Atom[] atoms)
           This function asserts all the given Atoms in this WorldState.
 WorldState clone()
           This function creates a copy of this WorldState.
 boolean entails(ai.krr.propositions.Atom atom)
           This function tests whether the given Atom holds in this WorldState.
 boolean entailsAll(ai.krr.propositions.Atom[] atoms)
           This function tests whether all the given Atoms hold in this WorldState.
 boolean equals(java.lang.Object obj)
           This function tests whether this and the given state are equal.
 boolean falsifies(ai.krr.propositions.Atom atom)
           This function tests whether the given Atom does not hold in this WorldState.
 int hashCode()
           This function returns a hash value for this state.
 java.util.Iterator<ai.krr.propositions.Atom> iterator()
           This function returns an Iterator over all the Atoms that are holding in this WorldState.
 void retract(ai.krr.propositions.Atom atom)
           This function deletes the given Atom from this WorldState.
 void retractAll(ai.krr.propositions.Atom[] atoms)
           This function deletes all the given Atoms from this WorldState.
 int size()
           This function returns the number of Atoms that are true in this state.
 java.lang.String toString()
           This function creates a String representation for this WorldState.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

holding

protected java.util.Set<ai.krr.propositions.Atom> holding
the set of Atoms that hold in this state

Constructor Detail

WorldState

public WorldState()

This constructor creates a new empty WorldState. Initially nothing holds in this state.


WorldState

public WorldState(java.util.Set<ai.krr.propositions.Atom> atoms)

This constructor creates a new WorldState in which exactly the given Atoms are true.

Parameters:
atoms - the Set of Atoms holding in this WorldState

WorldState

public WorldState(ai.krr.propositions.Atom... atoms)

This constructor creates a new WorldState in which exactly the given Atoms are true.

Parameters:
atoms - the Atoms holding in this WorldState
Method Detail

clone

public WorldState clone()

This function creates a copy of this WorldState. Subsequent modifications will not change the original state. Note that the time complexity of this function is in O(n) where n is the number of Atoms that hold in this state, i.e. this function is relatively expensive.

Overrides:
clone in class java.lang.Object
Returns:
a new WorldState in which the same Atoms hold (as in this state)

size

public int size()

This function returns the number of Atoms that are true in this state.

Specified by:
size in interface WorldState<ai.krr.propositions.Atom>
Returns:
the size of this state

add

public void add(ai.krr.propositions.Atom atom)

This function asserts the given Atom in this WorldState.

Specified by:
add in interface WorldState<ai.krr.propositions.Atom>
Parameters:
atom - the Atom that is to hold in this state

addAll

public void addAll(ai.krr.propositions.Atom[] atoms)

This function asserts all the given Atoms in this WorldState.

Specified by:
addAll in interface WorldState<ai.krr.propositions.Atom>
Parameters:
atoms - the Atoms that are to hold in this state

retract

public void retract(ai.krr.propositions.Atom atom)

This function deletes the given Atom from this WorldState.

Specified by:
retract in interface WorldState<ai.krr.propositions.Atom>
Parameters:
atom - the Atom that is not to hold in this state

retractAll

public void retractAll(ai.krr.propositions.Atom[] atoms)

This function deletes all the given Atoms from this WorldState.

Specified by:
retractAll in interface WorldState<ai.krr.propositions.Atom>
Parameters:
atoms - the Atoms that are not to hold in this state

entails

public boolean entails(ai.krr.propositions.Atom atom)

This function tests whether the given Atom holds in this WorldState.

Specified by:
entails in interface WorldState<ai.krr.propositions.Atom>
Parameters:
atom - the Atom that may or may not be true
Returns:
true iff the given Atom is a member of the set of Atoms representing this state

entailsAll

public boolean entailsAll(ai.krr.propositions.Atom[] atoms)

This function tests whether all the given Atoms hold in this WorldState.

Specified by:
entailsAll in interface WorldState<ai.krr.propositions.Atom>
Parameters:
atoms - the Atoms that may or may not be true
Returns:
true iff all the given Atoms are a member of the set of Atoms representing this state

falsifies

public boolean falsifies(ai.krr.propositions.Atom atom)

This function tests whether the given Atom does not hold in this WorldState.

Specified by:
falsifies in interface WorldState<ai.krr.propositions.Atom>
Parameters:
atom - the Atom that may or may not be true
Returns:
true iff the given Atom is not a member of the set of Atoms representing this state

iterator

public java.util.Iterator<ai.krr.propositions.Atom> iterator()

This function returns an Iterator over all the Atoms that are holding in this WorldState.

Specified by:
iterator in interface java.lang.Iterable<ai.krr.propositions.Atom>
Returns:
an Iterator over entailed Atoms

equals

public boolean equals(java.lang.Object obj)

This function tests whether this and the given state are equal. It returns true iff the two states contain equal Atoms.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the Object this WorldState is compared to
Returns:
whether the same Atoms hold in both states

hashCode

public int hashCode()

This function returns a hash value for this state.

Overrides:
hashCode in class java.lang.Object
Returns:
an integer that can be used for hashing

toString

public java.lang.String toString()

This function creates a String representation for this WorldState. This is simply the String representing the contained Set of Atoms.

Overrides:
toString in class java.lang.Object
Returns:
the String representing this WorldState