ai.planning.strips
Class ActionType.ArrayGrounding

java.lang.Object
  extended by ai.planning.strips.Grounding
      extended by ai.planning.strips.ActionType.ArrayGrounding
All Implemented Interfaces:
ai.krr.fol.Substitution
Enclosing class:
ActionType

public static class ActionType.ArrayGrounding
extends Grounding

A Substitution maps a set of Variables to a set of Terms. In the case of a Grounding the Terms must be Constants and no Variables can be unified with other Variables.

This implementation maintains two arrays where a variable at one index in the first array is mapped to a value at the same index in the second array. The biggest disadvantage of this implementation is that access takes linear time for most operations, which is why this class should only be used if the number of variables to be grounded is small. This number is limited at construction time. The advantage of this implementation is that it provides a function revertTo(int) which can be used to backtrack to a previous version of this Grounding. This is very useful when searching for a Grounding.

Author:
Gerhard Wickler

Field Summary
protected  int nextIdx
          the index of the next free position in the arrays
protected  ai.krr.fol.Constant[] terms
          the Constants to which the Variables are mapped
protected  ai.krr.fol.Variable[] vars
          the Variables that are grounded by this Grounding
 
Constructor Summary
ActionType.ArrayGrounding(int maxVars)
           This constructor creates a new Grounding with no associations.
 
Method Summary
 ActionType.ArrayGrounding clone()
           This function creates a shallow copy of this Grounding which consists of a shallow copy of the contained map.
 boolean contains(ai.krr.fol.Variable var)
           This function tests whether this Substitution maps the given Variable to a new Term.
 boolean equals(Grounding s)
           This function compares this and the given Grounding.
 ai.krr.fol.Constant getValue(ai.krr.fol.Variable var)
           This function returns the Term the given Variable is mapped to.
 java.util.Set<ai.krr.fol.Variable> getVars()
           This function returns a Set of all the Variables that are unified in this Substitution.
 int hashCode()
           
 void revertTo(int nrVars)
           This function reverts this Grounding to an earlier version in which only the given number of Variables are unified.
 int size()
           This function returns the number of variables bound by this Grounding.
 java.lang.String toString()
           
 boolean unify(ai.krr.fol.Variable var, ai.krr.fol.Term term)
           This function attempts to extend this Substitution such that the given Variable (from the "left" expression) and the given Term (from the "right") are unified and returns whether this succeeded.
 
Methods inherited from class ai.planning.strips.Grounding
unify, unify
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

vars

protected ai.krr.fol.Variable[] vars
the Variables that are grounded by this Grounding


terms

protected ai.krr.fol.Constant[] terms
the Constants to which the Variables are mapped


nextIdx

protected int nextIdx
the index of the next free position in the arrays

Constructor Detail

ActionType.ArrayGrounding

public ActionType.ArrayGrounding(int maxVars)

This constructor creates a new Grounding with no associations. The given integer specifies the maximal number of Variables that can be grounded here. An attempt to add more Variables will result in an Exception.

Parameters:
size - the maximal number of Variables to be grounded
Method Detail

clone

public ActionType.ArrayGrounding clone()

This function creates a shallow copy of this Grounding which consists of a shallow copy of the contained map. Thus, modifications to the map of the copy will not modify the original, modifications to the key or value objects will.

Overrides:
clone in class java.lang.Object
Returns:
a shallow copy of this ArrayGrounding

size

public int size()

This function returns the number of variables bound by this Grounding.

Specified by:
size in class Grounding
Returns:
the number of mappings in this Grounding

unify

public boolean unify(ai.krr.fol.Variable var,
                     ai.krr.fol.Term term)

This function attempts to extend this Substitution such that the given Variable (from the "left" expression) and the given Term (from the "right") are unified and returns whether this succeeded.

Parameters:
aVar - the Variable the given Term is to be unified with
aTerm - the Term the given Variable will be mapped to
Returns:
whether successful extension of this Substitution was possible

contains

public boolean contains(ai.krr.fol.Variable var)

This function tests whether this Substitution maps the given Variable to a new Term.

Parameters:
var - the Variable the Term is being sought for
Returns:
whether an associated Term exists in this Substitution

getValue

public ai.krr.fol.Constant getValue(ai.krr.fol.Variable var)

This function returns the Term the given Variable is mapped to. More specifically, it returns:

Specified by:
getValue in interface ai.krr.fol.Substitution
Specified by:
getValue in class Grounding
Parameters:
aVar - the Variable the Term is being sought for
Returns:
the instantiated Term the given Variable is mapped to

getVars

public java.util.Set<ai.krr.fol.Variable> getVars()

This function returns a Set of all the Variables that are unified in this Substitution. To find out whether a specific Variable is instantiated by this ArrayGrounding, it is more efficient to use #getTerm(Variable) which should return null iff the Variable is not instantiated.

Specified by:
getVars in class Grounding
Returns:
a Set of all the Variables that are unified in this Substitution

revertTo

public void revertTo(int nrVars)

This function reverts this Grounding to an earlier version in which only the given number of Variables are unified.

Parameters:
nrVars - the number of Variables in the earlier version

equals

public boolean equals(Grounding s)
Description copied from class: Grounding

This function compares this and the given Grounding. Two Groundings are equal if they map the same Variables to the same Constants.

Specified by:
equals in class Grounding
Parameters:
s - the Grounding this one is to be compared to
Returns:
whether the two Groundings are equivalent

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object