public abstract class Action
extends java.lang.Object
getTransitions(burlap.oomdp.core.State, String[])
is what defines the transition dynamics of the MDP for this action. If this method is not overridden by subclasses, then an
UnsupportedOperation exception is thrown . If the domain being created is only
going to be used planning/learning algorithms that require a generative model, rather than the fully enumerated transition
dynamics, then the getTransitions(burlap.oomdp.core.State, String[])
does not need to be implemented, but for full robustness it should be.
If your domain is deterministic, you can trivially implement it by having it return a call to the deterministicTransition(burlap.oomdp.core.State, String[])
method, which will wrap the result of a performAction(burlap.oomdp.core.State, String[])
} method with a 1.0 outcome probability
TransitionProbability
object and insert it in a list containing just that element.
Action objects may also be defined to require object parameters (which must adhere to a type). Parameters can also have parameter order groups specified if
there is effect symmetry when changing the order of the parameters. That is, if you swapped the parameter assignments for parameters in the same order group, the action would have
the same effect. However, if you swapped the parameter assignments of two parameters in different order groups, the action would have a different effect.
For more information on parameter order groups, see its discussion
in the PropositionalFunction
class description.Modifier and Type | Field and Description |
---|---|
protected java.util.List<ActionObserver> |
actionObservers
An observer that will be notified of an actions results every time it is executed.
|
protected Domain |
domain
The domain with which this action is associated
|
protected java.lang.String |
name
The name of the action that can uniquely identify it
|
protected java.lang.String[] |
parameterClasses
The object classes each parameter of this action can accept; empty list for a parameter-less action (which is the default)
|
protected java.lang.String[] |
parameterOrderGroup
Specifies the parameter order group each parameter.
|
Constructor and Description |
---|
Action() |
Action(java.lang.String name,
Domain domain,
java.lang.String parameterClasses)
Initializes the action with the name of the action, the domain to which it belongs, and the parameters it takes.
|
Action(java.lang.String name,
Domain domain,
java.lang.String[] parameterClasses)
Initializes the action with the name of the action, the domain to which it belongs, and the parameters it takes.
|
Action(java.lang.String name,
Domain domain,
java.lang.String[] parameterClasses,
java.lang.String[] parameterOrderGroups)
Initializes the action with the name of the action, the domain to which it belongs, the parameters it takes, and the parameter order groups.
|
Modifier and Type | Method and Description |
---|---|
void |
addActionObserver(ActionObserver observer)
Sets an action observer for this action.
|
boolean |
applicableInState(State s,
java.lang.String params)
Returns true if this action can be applied in this specified state with the specified parameters.
|
boolean |
applicableInState(State s,
java.lang.String[] params)
Returns true if this action can be applied in this specified state with the specified parameters.
|
void |
clearAllActionsObservers()
Clears all action observers associated with this action
|
protected java.util.List<TransitionProbability> |
deterministicTransition(State s,
java.lang.String[] params)
Returns the transition dynamics by assuming the action to be deterministic and wrapping the result of a
performAction(burlap.oomdp.core.State, String[]) method with a 1.0 probable TransitionProbability
object and inserting it in the returned list. |
boolean |
equals(java.lang.Object obj) |
java.util.List<GroundedAction> |
getAllApplicableGroundedActions(State s)
Returns all possible groundings of this action that can be applied in the provided
State . |
static java.util.List<GroundedAction> |
getAllApplicableGroundedActionsFromActionList(java.util.List<Action> actions,
State s)
Returns all
GroundedAction s that are applicable in the given State for all Action objects in the provided list. |
Domain |
getDomain()
Returns the domain to which this action belongs.
|
java.lang.String |
getName()
Returns the name of the action
|
java.lang.String[] |
getParameterClasses()
Returns a String array of the names of of the object classes to which bound parameters must belong
|
java.lang.String[] |
getParameterOrderGroups()
Returns the a String array specifying the parameter order group of each parameter.
|
java.util.List<TransitionProbability> |
getTransitions(State s,
java.lang.String params)
Returns the transition probabilities for applying this action in the given state with the given set of parameters.
|
java.util.List<TransitionProbability> |
getTransitions(State s,
java.lang.String[] params)
Returns the transition probabilities for applying this action in the given state with the given set of parameters.
|
int |
hashCode() |
protected void |
init(java.lang.String name,
Domain domain,
java.lang.String[] parameterClasses,
java.lang.String[] parameterOrderGroups) |
boolean |
isPrimitive()
Returns whether this action is a primitive action of the domain or not.
|
boolean |
parametersAreObjects()
Returns true if all parameters (if any) for this action represent OO-MDP objects in a state; false otherwise.
|
State |
performAction(State s,
java.lang.String params)
Performs this action in the specified state using the specified parameters and returns the resulting state.
|
State |
performAction(State s,
java.lang.String[] params)
Performs this action in the specified state using the specified parameters and returns the resulting state.
|
protected abstract State |
performActionHelper(State s,
java.lang.String[] params)
This method determines what happens when an action is applied in the given state with the given parameters.
|
protected java.lang.String name
protected Domain domain
protected java.lang.String[] parameterClasses
protected java.lang.String[] parameterOrderGroup
protected java.util.List<ActionObserver> actionObservers
public Action()
public Action(java.lang.String name, Domain domain, java.lang.String parameterClasses)
name
- the name of the actiondomain
- the domain to which the action belongsparameterClasses
- a comma delineated String of the names of the object classes to which bound parameters must belongpublic Action(java.lang.String name, Domain domain, java.lang.String[] parameterClasses)
name
- the name of the actiondomain
- the domain to which the action belongsparameterClasses
- a String array of the names of the object classes to which bound parameters must belongpublic Action(java.lang.String name, Domain domain, java.lang.String[] parameterClasses, java.lang.String[] parameterOrderGroups)
name
- the name of the actiondomain
- the domain to which the action belongsparameterClasses
- a String array of the names of the object classes to which bound parameters must belongparameterOrderGroups
- the order group assignments for each of the parameters.protected void init(java.lang.String name, Domain domain, java.lang.String[] parameterClasses, java.lang.String[] parameterOrderGroups)
public final java.lang.String getName()
public final java.lang.String[] getParameterClasses()
public final java.lang.String[] getParameterOrderGroups()
public boolean parametersAreObjects()
public final Domain getDomain()
public void addActionObserver(ActionObserver observer)
observer
- the observer that will be told of each event when this action is executed.public void clearAllActionsObservers()
public final boolean applicableInState(State s, java.lang.String params)
applicableInState(State, String [])
method will need to be override if this is not the case.s
- the state in which to check if this action can be appliedparams
- a comma delineated String specifying the action object parameterspublic boolean applicableInState(State s, java.lang.String[] params)
s
- the state to perform the action onparams
- a String array specifying the action object parameterspublic final State performAction(State s, java.lang.String params)
s
- the state in which the action is to be performed.params
- a comma delineated String specifying the action object parameterspublic State performAction(State s, java.lang.String[] params)
performActionHelper(State, String[])
method.
Only override this method if you are seeking to perform memory optimization with semi-shallow copies of states and know what you're doing.s
- the state in which the action is to be performed.params
- a String array specifying the action object parameterspublic boolean isPrimitive()
public final java.util.List<TransitionProbability> getTransitions(State s, java.lang.String params)
TransitionProbability
objects. The list
is only required to contain transitions with non-zero probability. By default, this method assumes that transition
dynamics are deterministic and it returns a list with a single TransitionProbability with probability 1 whose
state is determined by querying the performAction(State, String [])
method. If the transition dynamics
are stochastic, then the analogous method getTransitions(State, String [])
needs to be overridden.s
- the state from which the transition probabilities when applying this action will be returned.params
- a comma delineated String specifying the action object parameterspublic java.util.List<TransitionProbability> getTransitions(State s, java.lang.String[] params)
TransitionProbability
objects. The list
is only required to contain transitions with non-zero probability. Since not all planning algorithms require
the full transition dynamics (and since it's impossible to enumerate them in some infinite state space domains),
this method is not requried to be implemented. However, it will throw an UnsupportedOperationException
if it is not overriden by the Action subclass if it is called by an algorithm that requires it.s
- the state from which the transition probabilities when applying this action will be returned.params
- a String array specifying the action object parametersprotected java.util.List<TransitionProbability> deterministicTransition(State s, java.lang.String[] params)
performAction(burlap.oomdp.core.State, String[])
method with a 1.0 probable TransitionProbability
object and inserting it in the returned list.s
- the state from which the transition probabilities when applying this action will be returned.params
- a String array specifying the action object parametersTransitionProbability
whose state is the outcome of the performAction(burlap.oomdp.core.State, String[])
method.public java.util.List<GroundedAction> getAllApplicableGroundedActions(State s)
State
. To check if a grounded
action is applicable in the state, the applicableInState(State, String[])
method is checked.
The default behavior of this method is to treat the parameters as possible object bindings, finding all bindings
that satisfy the object class typing specified and then checking them against the applicableInState(State, String[])
method. However, this class can also be overridden to provide custom
grounding behavior or non-object based parameterizations.s
- the State
in which all applicable grounded actions of this Action
object should be returned.GroundedAction
s of this Action
object in in the given State
public static java.util.List<GroundedAction> getAllApplicableGroundedActionsFromActionList(java.util.List<Action> actions, State s)
GroundedAction
s that are applicable in the given State
for all Action
objects in the provided list. This method
operates by calling the getAllApplicableGroundedActions(State)
method on each action and adding all the results
to a list that is then returned.actions
- The list of all actions for which grounded actions should be returned.s
- the stateList
of all the GroundedAction
s for all Action
in the list that are applicable in the given State
protected abstract State performActionHelper(State s, java.lang.String[] params)
s
- the state to perform the action onparams
- a String array specifying the action object parameterspublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object