public abstract class CompositeBehaviour extends Behaviour
CompositeBehaviour
receives it execution quantum
from the agent scheduler, it executes one of its children according
to some policy. This class must be extended to provide the actual
scheduling policy to apply when running children behaviours.SequentialBehaviour
,
ParallelBehaviour
,
FSMBehaviour
,
Serialized FormModifier | Constructor and Description |
---|---|
protected |
CompositeBehaviour()
Default constructor, does not set the owner agent.
|
protected |
CompositeBehaviour(Agent a)
This constructor sets the owner agent.
|
Modifier and Type | Method and Description |
---|---|
void |
action()
Executes this
CompositeBehaviour . |
protected abstract boolean |
checkTermination(boolean currentDone,
int currentResult)
This methods is called after the execution of each child
in order to check whether the
CompositeBehaviour
should terminate. |
boolean |
done()
Checks whether this behaviour has terminated.
|
abstract Collection |
getChildren()
This method returns a Collection view of the children of
this
CompositeBehaviour |
protected abstract Behaviour |
getCurrent()
This method returns the child behaviour currently
scheduled for execution
|
void |
reset()
Puts a
CompositeBehaviour back in initial state. |
protected void |
resetChildren() |
protected abstract void |
scheduleFirst()
This method schedules the first child to be executed
|
protected abstract void |
scheduleNext(boolean currentDone,
int currentResult)
This method schedules the next child to be executed
|
void |
setAgent(Agent a)
Associates this behaviour with the agent it belongs to.
|
block, block, getAgent, getBehaviourName, getDataStore, getParent, isRunnable, onEnd, onStart, restart, root, setBehaviourName, setDataStore
protected CompositeBehaviour()
protected CompositeBehaviour(Agent a)
a
- The agent this behaviour belongs to.public final void action()
CompositeBehaviour
. This method
executes children according to the scheduling policy
defined by concrete subclasses that implements
the scheduleFirst()
and scheduleNext()
methods.action
in class Behaviour
CompositeBehaviour
public final boolean done()
protected abstract void scheduleFirst()
protected abstract void scheduleNext(boolean currentDone, int currentResult)
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)protected abstract boolean checkTermination(boolean currentDone, int currentResult)
CompositeBehaviour
should terminate.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
should terminate. false otherwise.protected abstract Behaviour getCurrent()
public abstract Collection getChildren()
CompositeBehaviour
public void reset()
CompositeBehaviour
back in initial state. The
internal state is cleaned up and reset()
is
recursively called for each child behaviour.protected void resetChildren()
public void setAgent(Agent a)
setAgent
in class Behaviour
a
- The agent this behaviour belongs to.Behaviour.setAgent(Agent a)