ai.planning.strips
Class ModelBasedState

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

public class ModelBasedState
extends WorldState

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 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

Nested Class Summary
static interface ModelBasedState.RelationModel
           
protected static class ModelBasedState.SetModel
           
 
Nested classes/interfaces inherited from class ai.planning.strips.WorldState
WorldState.MetaIterator<E>, WorldState.NoElementIterator<E>
 
Field Summary
protected  ModelBasedState.RelationModel[] fluents
          the (fluent) relations that hold in this state (indexed by predicate)
protected  ai.krr.NamedSymbol[] fRelSys
          the array containing the fluent predicates (for indexing fluents)
protected  java.util.Map<ai.krr.NamedSymbol,ModelBasedState.RelationModel> statics
          the (static) relations that hold in all states (indexed by predicate)
 
Fields inherited from class ai.planning.strips.WorldState
domain, hashValue
 
Constructor Summary
ModelBasedState(java.util.Set<ai.krr.fol.Atom> atoms, Domain domain)
           This constructor creates a new WorldState in which the given Atoms are true.
 
Method Summary
 void add(ai.krr.fol.Atom atom)
           This function asserts the given Atom in this WorldState.
 ModelBasedState clone()
           This function creates a copy of this WorldState.
 boolean entails(ai.krr.fol.Atom atom)
           This function tests whether the given Atom holds in this WorldState.
 boolean equals(ModelBasedState state)
           
 boolean equals(WorldState state)
           This function tests whether this and the given state are equal.
 boolean falsifies(ai.krr.fol.Atom atom)
           This function tests whether the given Atom does not hold in this WorldState.
 ModelBasedState.RelationModel getModel(ai.krr.NamedSymbol relation)
           This function retrieves all those Atoms that are true for the given (static or fluent) relation in this state.
 java.util.Iterator<ai.krr.fol.Atom> iterator()
           This function returns an Iterator that enumerates all the fluents that hold in this state.
 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.
 void retract(ai.krr.fol.Atom atom)
           This function deletes the given Atom from this WorldState.
 int size()
           This function returns the number of different fluents that are holding in this state.
 int size(ai.krr.NamedSymbol relation)
           This function returns the number of atoms that are holding in this state for the given relation.
 java.lang.String toString()
           This function creates a String representation for this WorldState.
 
Methods inherited from class ai.planning.strips.WorldState
addAll, entailsAll, equals, getDomain, hashCode, retractAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

statics

protected java.util.Map<ai.krr.NamedSymbol,ModelBasedState.RelationModel> statics
the (static) relations that hold in all states (indexed by predicate)


fRelSys

protected ai.krr.NamedSymbol[] fRelSys
the array containing the fluent predicates (for indexing fluents)


fluents

protected ModelBasedState.RelationModel[] fluents
the (fluent) relations that hold in this state (indexed by predicate)

Constructor Detail

ModelBasedState

public ModelBasedState(java.util.Set<ai.krr.fol.Atom> atoms,
                       Domain domain)

This constructor creates a new WorldState in which the given Atoms are true. Static relations that hold must be added in this constructor.

Parameters:
atoms - the Atoms holding in this WorldState
domain - the Domain to which this WorldState refers
Method Detail

clone

public ModelBasedState clone()

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

Specified by:
clone in class WorldState
Returns:
a new WorldState in which the same Atoms hold (as in this state)

size

public int size()

This function returns the number of different fluents that are holding in this state.

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

size

public 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.

Specified by:
size in class WorldState
Returns:
number of true fluent atoms

add

public 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 the given atom must be a fluent relation.

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

retract

public 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>
Specified by:
retract in class WorldState
Parameters:
atom - the Atom that is not to hold in this state

entails

public 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>
Specified by:
entails in class WorldState
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 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>
Specified by:
falsifies in class WorldState
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.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>
Specified by:
iterator in class WorldState
Returns:
an Iterator for Atoms that are entailed by this state

iterator

public 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.

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

getModel

public ModelBasedState.RelationModel getModel(ai.krr.NamedSymbol relation)

This function retrieves all those Atoms that are true for the given (static or fluent) relation in this state.

Parameters:
relation - the relation that is sought
Returns:
all currently true Atoms for the given relation

equals

public boolean equals(WorldState state)

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

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

equals

public boolean equals(ModelBasedState state)

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