ai.planning.strips
Class WorldState

java.lang.Object
  extended by ai.planning.strips.WorldState
All Implemented Interfaces:
WorldState<ai.krr.fol.Atom>, java.lang.Iterable<ai.krr.fol.Atom>
Direct Known Subclasses:
HashedSetState, ModelBasedState

public abstract class WorldState
extends java.lang.Object
implements WorldState<ai.krr.fol.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 STRIPS representation a WorldState consists of the set of function-free, ground first-order Atoms that are true in the state. Atoms not in the given set are considered to be false, i.e. this representation assumes a closed world.The relations used in these Atoms can be divided into static and dynamic (fluent) relations, which depends on the underlying Domain. This is why the constructor for this class requires a Domain to be specified.

Author:
Gerhard Wickler
See Also:
Atom

Nested Class Summary
protected static class WorldState.MetaIterator<E>
           
protected static class WorldState.NoElementIterator<E>
           
 
Field Summary
protected  Domain domain
          the Domain with respect to which this WorldState is defined
protected  int hashValue
          the cashed (positive) hash value of this state or -1 if not yet computed
 
Constructor Summary
WorldState(Domain domain)
           This constructor creates a new WorldState.
 
Method Summary
abstract  void add(ai.krr.fol.Atom atom)
           This function asserts the given Atom in this WorldState.
 void addAll(ai.krr.fol.Atom[] atoms)
           This function asserts all the given Atoms in this WorldState.
abstract  WorldState clone()
           This function creates a copy of this WorldState.
abstract  boolean entails(ai.krr.fol.Atom atom)
           This function tests whether the given Atom holds in this WorldState.
 boolean entailsAll(ai.krr.fol.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 equals(WorldState state)
           
abstract  boolean falsifies(ai.krr.fol.Atom atom)
           This function tests whether the given Atom does not hold in this WorldState.
 Domain getDomain()
           This function returns the Domain with which this WorldState is associated.
 int hashCode()
           This function returns a (cached) hash value for this state.
abstract  java.util.Iterator<ai.krr.fol.Atom> iterator()
           This function returns an Iterator that enumerates all the fluents that hold in this state.
abstract  java.util.Iterator<ai.krr.fol.Atom> iterator(ai.krr.NamedSymbol relation)
           This function returns an Iterator that enumerates some of the fluents that hold in this state.
abstract  void retract(ai.krr.fol.Atom atom)
           This function deletes the given Atom from this WorldState.
 void retractAll(ai.krr.fol.Atom[] atoms)
           This function deletes all the given Atoms from this WorldState.
abstract  int size()
           This function returns the number of Atoms (static and fluent) that are holding in this state.
abstract  int size(ai.krr.NamedSymbol relation)
           This function returns the number of atoms that are holding in this state for the given relation.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

domain

protected final Domain domain
the Domain with respect to which this WorldState is defined


hashValue

protected int hashValue
the cashed (positive) hash value of this state or -1 if not yet computed

Constructor Detail

WorldState

public WorldState(Domain domain)

This constructor creates a new WorldState. Static and dynamic relations are defined by the given Domain.

Parameters:
domain - the Domain to which this WorldState refers
Method Detail

clone

public abstract WorldState clone()

This function creates a copy of this WorldState. Subsequent modifications will not change the original state.

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

size

public abstract int size()

This function returns the number of Atoms (static and fluent) that are holding in this state.

Specified by:
size in interface WorldState<ai.krr.fol.Atom>
Returns:
number of true atoms

size

public abstract int size(ai.krr.NamedSymbol relation)

This function returns the number of atoms that are holding in this state for the given relation. The relation may be fluent or static.

Returns:
number of true fluent atoms

add

public abstract void add(ai.krr.fol.Atom atom)

This function asserts the given Atom in this WorldState. Note that all static relations must be defined in the constructor and thus this atom must be a fluent relation.

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

retract

public abstract void retract(ai.krr.fol.Atom atom)

This function deletes the given Atom from this WorldState. Note that the given Atom should be a fluent relation.

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

entails

public abstract boolean entails(ai.krr.fol.Atom atom)

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

Specified by:
entails in interface WorldState<ai.krr.fol.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

falsifies

public abstract boolean falsifies(ai.krr.fol.Atom atom)

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

Specified by:
falsifies in interface WorldState<ai.krr.fol.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 abstract java.util.Iterator<ai.krr.fol.Atom> iterator()

This function returns an Iterator that enumerates all the fluents that hold in this state.

Specified by:
iterator in interface java.lang.Iterable<ai.krr.fol.Atom>
Returns:
an Iterator for Atoms that are entailed by this state

iterator

public abstract java.util.Iterator<ai.krr.fol.Atom> iterator(ai.krr.NamedSymbol relation)

This function returns an Iterator that enumerates some of the fluents that hold in this state. The enumerated Atoms are exactly those that are related by the given relation.

Parameters:
relation - the relation for which Atoms should be enumerated
Returns:
an Iterator for Atoms that are entailed by this state

addAll

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

This function asserts all the given Atoms in this WorldState.

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

retractAll

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

This function deletes all the given Atoms from this WorldState.

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

entailsAll

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

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

Specified by:
entailsAll in interface WorldState<ai.krr.fol.Atom>
Parameters:
atoms - the Atoms that may or may not be true
Returns:
true iff all the given Atoms holds in this state

getDomain

public final Domain getDomain()

This function returns the Domain with which this WorldState is associated.

Returns:
the Domain for this state

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 exactly the same fluent Atoms. Static relations are ignored!

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

equals

public boolean equals(WorldState state)

hashCode

public int hashCode()

This function returns a (cached) hash value for this state.

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