cz.cuni.amis.pogamut.sposh.executor
Class StateWorkExecutor

Package class diagram package StateWorkExecutor
java.lang.Object
  extended by cz.cuni.amis.pogamut.sposh.executor.StateWorkExecutor
All Implemented Interfaces:
IWorkExecutor

public class StateWorkExecutor
extends Object
implements IWorkExecutor

This class is an IWorkExecutor, that considers actions to be have state, in this executor, primitive is working in phases INIT, RUN*, DONE.

Thanks to state nature of primitive, primitive is far easier to program in discrete time-slice (time slice = primitive can be called multiple times consequentially) nature of Pogamut. If primitive wasn't notified that it is about to end, things like switching from primitive "walk" to "shoot" could be troublesome. Imagine it, "walk" primitive will compute path to destination and suddently new primitive "shoot" is now called. What about path the bot is following? It will still follow it, although it is supposed to stop and start shooting. To handle this correctlty is troublesome for few states, for many states, it is madness.

StateWorkExecutor would do this: ..., walk.INIT, walk.RUN*, walk.DONE, shoot.INIT, shoot.RUN*, shoot.DONE...., primitive walk would have DONE called before shoot.INIT would be called, allowing it to stop walking. Same thing is valid for state shoot too.

Since we have phase DONE to cleanup some stuff before we switch to another, where another can be nearly anything, what state bot should be in when DONE phase is DONE. In neutral bot state (precise neutral state is defined by programmer, in unreal, that would probably be standing, not shooting.).

What if we don't want to switch to neutral bot state after primitive is DONE? Don't, there is no explicit need, and in many situation it is meaningless (such as primtive "enter_ducts" where bot would entering INIT in standing state, but left DONE crouching).

Author:
Honza
See Also:
IAction

Field Summary
protected  HashMap<String,IAction> actions
          Map that maps primtive name to IAction.
protected  String currentActionName
          Primitive that is currently being executed.
protected  String currentVariableContext
          String representation of current variable context.
protected  Logger log
          Log where we put
protected  HashMap<String,ISense> senses
          Map that maps primitive name to its respective ISense.
 
Constructor Summary
StateWorkExecutor()
           
StateWorkExecutor(Logger log)
           
 
Method Summary
 void addAction(IAction action)
          Add primitive, use name from annotations.
 void addAction(String name, IAction action)
          Add new IAction with primitive name.
 void addSense(ISense sense)
          Add primitive, use name from annotations.
 void addSense(String name, ISense sense)
          Add new ISense with primtive name.
 ActionResult executeAction(String actionToExecuteName, VariableContext ctx)
          Execute action and get the result.
 Object executeSense(String primitive, VariableContext ctx)
          Execute sense and get the result.
 Logger getLogger()
          Get logger of this IWorkExecutor.
protected  boolean isAction(String name)
          Is there an action with the name.
 boolean isNameUsed(String name)
          Is name used in some primtive in this the work executor.
protected  boolean isSense(String name)
          Is there a sense with the name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

actions

protected final HashMap<String,IAction> actions
Map that maps primtive name to IAction.


senses

protected final HashMap<String,ISense> senses
Map that maps primitive name to its respective ISense.


currentActionName

protected String currentActionName
Primitive that is currently being executed. If no such primitive, null is used.


currentVariableContext

protected String currentVariableContext
String representation of current variable context. If ctx is changed, we have to do done and init phase for the action. e.g. GoToBase($target = "our") and GoToBase($target = "enemy") have same action name, but different target.


log

protected Logger log
Log where we put

Constructor Detail

StateWorkExecutor

public StateWorkExecutor()

StateWorkExecutor

public StateWorkExecutor(Logger log)
Method Detail

getLogger

public Logger getLogger()
Get logger of this IWorkExecutor.

Returns:

isNameUsed

public boolean isNameUsed(String name)
Is name used in some primtive in this the work executor.

Parameters:
name - queried name
Returns:
if the name is not yet used in the StateWorkExecutor.

isAction

protected boolean isAction(String name)
Is there an action with the name.

Parameters:
name - queries name

isSense

protected boolean isSense(String name)
Is there a sense with the name.

Parameters:
name - queries name

addAction

public void addAction(String name,
                      IAction action)
Add new IAction with primitive name.

Parameters:
name - name that will be used for this IAction in posh plan.
action - primitive that will be executed when executor will be asked to execute primtive with name.
Throws:
IllegalArgumentException - if primitive with name already exists in StateWorkExecutor.

addSense

public void addSense(String name,
                     ISense sense)
Add new ISense with primtive name.

Parameters:
name - name of primtive to be associated with passed sense object
sense - sense object to be used, when sense with name is supposed to execute.

addAction

public void addAction(IAction action)
Add primitive, use name from annotations.

Parameters:
action - primitive that will be added

addSense

public void addSense(ISense sense)
Add primitive, use name from annotations.

Parameters:
sense - primitive that will be added

executeSense

public Object executeSense(String primitive,
                           VariableContext ctx)
Description copied from interface: IWorkExecutor
Execute sense and get the result.

Specified by:
executeSense in interface IWorkExecutor
Parameters:
primitive - name of primitive
ctx - variable context for sense containing possible parameters
Returns:
result of executed primitive

executeAction

public ActionResult executeAction(String actionToExecuteName,
                                  VariableContext ctx)
Description copied from interface: IWorkExecutor
Execute action and get the result.

Specified by:
executeAction in interface IWorkExecutor
Parameters:
actionToExecuteName - name of primitive
ctx - variable context for action containing possible parameters
Returns:
result of executed primitive


Copyright © 2014 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.