|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--jade.core.behaviours.Behaviour | +--jade.core.behaviours.CompositeBehaviour | +--jade.core.behaviours.SerialBehaviour | +--jade.core.behaviours.FSMBehaviour
Composite behaviour with Finite State Machine based children scheduling.
It is a CompositeBehaviour
that executes its children
behaviours according to a FSM defined by the user. More specifically
each child represents a state in the FSM.
The class provides methods to register states (sub-behaviours) and
transitions that defines how sub-behaviours will be scheduled.
At a minimum, the following steps are needed in order to properly
define a FSMBehaviour
:
registerFirstState
;
registerLastState
;
registerState
;
registerTransition
;
registerDefaultTransition
is also useful
in order to register a default transition from a state to another state
independently on the termination event of the source state.
SequentialBehaviour
,
ParallelBehaviour
,
Serialized FormField Summary | |
protected java.lang.String |
currentName
|
protected List |
lastStates
|
Fields inherited from class jade.core.behaviours.Behaviour |
myAgent |
Constructor Summary | |
FSMBehaviour()
Default constructor, does not set the owner agent. |
|
FSMBehaviour(Agent a)
This constructor sets the owner agent. |
Method Summary | |
protected boolean |
checkTermination(boolean currentDone,
int currentResult)
Check whether this FSMBehaviour must terminate. |
Behaviour |
deregisterState(java.lang.String name)
Deregister a state of this FSMBehaviour . |
protected void |
forceTransitionTo(java.lang.String next)
Temporarily disregards the FSM structure, and jumps to the given state. |
Collection |
getChildren()
Return a Collection view of the children of this SequentialBehaviour |
protected Behaviour |
getCurrent()
Get the current child |
int |
getLastExitValue()
Retrieve the exit value of the most recently executed child. |
java.lang.String |
getName(Behaviour state)
Retrieve the name of the FSM state associated to the given child behaviour. |
protected Behaviour |
getPrevious()
Get the previously executed child |
Behaviour |
getState(java.lang.String name)
Retrieve the child behaviour associated to the FSM state with the given name. |
protected void |
handleInconsistentFSM(java.lang.String current,
int event)
|
protected void |
handleStateEntered(Behaviour state)
|
int |
onEnd()
Override the onEnd() method to return the exit value of the last executed state. |
void |
registerDefaultTransition(java.lang.String s1,
java.lang.String s2)
Register a default transition in the FSM defining the policy for children scheduling of this FSMBehaviour .
|
void |
registerDefaultTransition(java.lang.String s1,
java.lang.String s2,
java.lang.String[] toBeReset)
Register a default transition in the FSM defining the policy for children scheduling of this FSMBehaviour .
|
void |
registerFirstState(Behaviour state,
java.lang.String name)
Register a Behaviour as the initial state of this
FSMBehaviour . |
void |
registerLastState(Behaviour state,
java.lang.String name)
Register a Behaviour as a final state of this
FSMBehaviour . |
void |
registerState(Behaviour state,
java.lang.String name)
Register a Behaviour as a state of this
FSMBehaviour . |
void |
registerTransition(java.lang.String s1,
java.lang.String s2,
int event)
Register a transition in the FSM defining the policy for children scheduling of this FSMBehaviour . |
void |
registerTransition(java.lang.String s1,
java.lang.String s2,
int event,
java.lang.String[] toBeReset)
Register a transition in the FSM defining the policy for children scheduling of this FSMBehaviour .
|
void |
reset()
Put this FSMBehaviour back in the initial condition. |
void |
resetStates(java.lang.String[] states)
Reset the children behaviours registered in the states indicated in the states parameter. |
protected void |
scheduleFirst()
Prepare the first child for execution. |
protected void |
scheduleNext(boolean currentDone,
int currentResult)
This method schedules the next child to be executed. |
Methods inherited from class jade.core.behaviours.CompositeBehaviour |
action, block, done, resetChildren, restart, setAgent |
Methods inherited from class jade.core.behaviours.Behaviour |
block, getBehaviourName, getDataStore, getParent, isRunnable, onStart, root, setBehaviourName, setDataStore |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected List lastStates
protected java.lang.String currentName
Constructor Detail |
public FSMBehaviour()
public FSMBehaviour(Agent a)
a
- The agent this behaviour belongs to.Method Detail |
public void registerState(Behaviour state, java.lang.String name)
Behaviour
as a state of this
FSMBehaviour
. When the FSM reaches this state
the registered Behaviour
will be executed.
state
- The Behaviour
representing the statename
- The name identifying the state.public void registerFirstState(Behaviour state, java.lang.String name)
Behaviour
as the initial state of this
FSMBehaviour
.
state
- The Behaviour
representing the statename
- The name identifying the state.public void registerLastState(Behaviour state, java.lang.String name)
Behaviour
as a final state of this
FSMBehaviour
. When the FSM reaches this state
the registered Behaviour
will be executed and,
when completed, the FSMBehaviour
will terminate too.
state
- The Behaviour
representing the statename
- The name identifying the state.public Behaviour deregisterState(java.lang.String name)
FSMBehaviour
.
name
- The name of the state to be deregistered.
public void registerTransition(java.lang.String s1, java.lang.String s2, int event)
FSMBehaviour
.
s1
- The name of the state this transition starts froms2
- The name of the state this transition leads toevent
- The termination event that fires this transition
as returned by the onEnd()
method of the
Behaviour
representing state s1.Behaviour.onEnd()
public void registerTransition(java.lang.String s1, java.lang.String s2, int event, java.lang.String[] toBeReset)
FSMBehaviour
.
When this transition is fired the states indicated in the
toBeReset
parameter are reset. This is
particularly useful for transitions that lead to states that
have already been visited.
s1
- The name of the state this transition starts froms2
- The name of the state this transition leads toevent
- The termination event that fires this transition
as returned by the onEnd()
method of the
Behaviour
representing state s1.toBeReset
- An array of strings including the names of
the states to be reset.Behaviour.onEnd()
public void registerDefaultTransition(java.lang.String s1, java.lang.String s2)
FSMBehaviour
.
This transition will be fired when state s1 terminates with
an event that is not explicitly associated to any transition.
s1
- The name of the state this transition starts froms2
- The name of the state this transition leads topublic void registerDefaultTransition(java.lang.String s1, java.lang.String s2, java.lang.String[] toBeReset)
FSMBehaviour
.
This transition will be fired when state s1 terminates with
an event that is not explicitly associated to any transition.
When this transition is fired the states indicated in the
toBeReset
parameter are reset. This is
particularly useful for transitions that lead to states that
have already been visited.
s1
- The name of the state this transition starts froms2
- The name of the state this transition leads totoBeReset
- An array of strings including the names of
the states to be reset.public Behaviour getState(java.lang.String name)
Behaviour
representing the state whose
name is name
, or null
if no such
behaviour exists.public java.lang.String getName(Behaviour state)
Behaviour
state, or null
if the given
behaviour is not a child of this FSM behaviour.public int getLastExitValue()
public int onEnd()
onEnd
in class Behaviour
protected void scheduleFirst()
Behaviour
registered as the first state of this
FSMBehaviour
scheduleFirst
in class CompositeBehaviour
CompositeBehaviour.scheduleFirst()
protected void scheduleNext(boolean currentDone, int currentResult)
scheduleNext
in class CompositeBehaviour
currentDone
- a flag indicating whether the just executed
child has completed or not.currentResult
- the termination value (as returned by
onEnd()
) of the just executed child in the case this
child has completed (otherwise this parameter is meaningless)CompositeBehaviour.scheduleNext(boolean, int)
protected void handleInconsistentFSM(java.lang.String current, int event)
protected void handleStateEntered(Behaviour state)
protected boolean checkTermination(boolean currentDone, int currentResult)
FSMBehaviour
must terminate.
checkTermination
in class CompositeBehaviour
currentDone
- a flag indicating whether the just executed
child has completed or not.currentResult
- the termination value (as returned by
onEnd()
) of the just executed child in the case this
child has completed (otherwise this parameter is meaningless)
CompositeBehaviour.checkTermination(boolean, int)
protected Behaviour getCurrent()
getCurrent
in class CompositeBehaviour
CompositeBehaviour.getCurrent()
public Collection getChildren()
SequentialBehaviour
getChildren
in class CompositeBehaviour
CompositeBehaviour.getChildren()
protected void forceTransitionTo(java.lang.String next)
GOTO
statement
between states, and replaces the currently active state without
considering the trigger event or whether a transition was
registered. It should be used only to handle exceptional
conditions, if default transitions are not effective enough.
next
- The name of the state to jump to at the next FSM
cheduling quantum. If the FSM has no state with the given name,
this method does nothing.protected Behaviour getPrevious()
CompositeBehaviour.getCurrent()
public void reset()
reset
in class CompositeBehaviour
public void resetStates(java.lang.String[] states)
states
parameter.
states
- the names of the states that have to be reset
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |