public class ParallelBehaviour extends CompositeBehaviour
CompositeBehaviour that executes its children
behaviours concurrently, and it terminates when a
particular condition on its sub-behaviours is met i.e. when
all children are done, N children are done or any
child is done.| Modifier and Type | Field and Description |
|---|---|
static int |
WHEN_ALL
Predefined constant to be used in the constructor to create
a
ParallelBehaviour that terminates when all its
children are done. |
static int |
WHEN_ANY
Predefined constant to be used in the constructor to create
a
ParallelBehaviour that terminates when any of
its child is done. |
| Constructor and Description |
|---|
ParallelBehaviour()
Construct a
ParallelBehaviour without setting the
owner agent, and using the default termination condition
(i.e. the parallel behaviour terminates as soon as all its
children behaviours terminate. |
ParallelBehaviour(Agent a,
int endCondition)
Construct a
ParallelBehaviour setting the
owner agent. |
ParallelBehaviour(int endCondition)
Construct a
ParallelBehaviour without setting the
owner agent. |
| Modifier and Type | Method and Description |
|---|---|
void |
addSubBehaviour(Behaviour b)
Add a sub behaviour to this
ParallelBehaviour |
protected boolean |
checkTermination(boolean currentDone,
int currentResult)
Check whether this
ParallelBehaviour must terminate. |
Collection |
getChildren()
Return a Collection view of the children of
this
ParallelBehaviour |
protected Behaviour |
getCurrent()
Get the current child
|
Collection |
getTerminatedChildren()
Return a Collection view of the children of
this
ParallelBehaviour that have already completed. |
void |
removeSubBehaviour(Behaviour b)
Remove a sub behaviour from this
ParallelBehaviour |
void |
reset()
Resets this behaviour.
|
protected void |
scheduleFirst()
Prepare the first child for execution
|
protected void |
scheduleNext(boolean currentDone,
int currentResult)
This method
schedules children behaviours one at a time, in a round robin
fashion.
|
action, done, resetChildren, setAgentblock, block, getAgent, getBehaviourName, getDataStore, getParent, isRunnable, onEnd, onStart, restart, root, setBehaviourName, setDataStorepublic static final int WHEN_ALL
ParallelBehaviour that terminates when all its
children are done.public static final int WHEN_ANY
ParallelBehaviour that terminates when any of
its child is done.public ParallelBehaviour()
ParallelBehaviour without setting the
owner agent, and using the default termination condition
(i.e. the parallel behaviour terminates as soon as all its
children behaviours terminate.public ParallelBehaviour(int endCondition)
ParallelBehaviour without setting the
owner agent.endCondition - this value defines the termination condition
for this ParallelBehaviour. Use
WHEN_ALL to terminate this ParallelBehaviour
when all its children are done.
WHEN_ANY to terminate this ParallelBehaviour
when any of its child is done.
int value n to terminate this
ParallelBehaviour when n of its children are done.
public ParallelBehaviour(Agent a, int endCondition)
ParallelBehaviour setting the
owner agent.a - the agent this ParallelBehaviour
belongs to.endCondition - this value defines the termination condition
for this ParallelBehaviour. Use
WHEN_ALL to terminate this ParallelBehaviour
when all its children are done.
WHEN_ANY to terminate this ParallelBehaviour
when any of its child is done.
int value n to terminate this
ParallelBehaviour when n of its children are done.
protected void scheduleFirst()
scheduleFirst in class CompositeBehaviourCompositeBehaviour.scheduleFirst()protected void scheduleNext(boolean currentDone,
int currentResult)
scheduleNext in class CompositeBehaviourcurrentDone - 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 boolean checkTermination(boolean currentDone,
int currentResult)
ParallelBehaviour must terminate.checkTermination in class CompositeBehaviourcurrentDone - 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.CompositeBehaviour.checkTermination(boolean, int)protected Behaviour getCurrent()
getCurrent in class CompositeBehaviourCompositeBehaviour.getCurrent()public Collection getChildren()
ParallelBehaviourgetChildren in class CompositeBehaviourCompositeBehaviour.getChildren()public Collection getTerminatedChildren()
ParallelBehaviour that have already completed.public void addSubBehaviour(Behaviour b)
ParallelBehaviourpublic void removeSubBehaviour(Behaviour b)
ParallelBehaviourpublic void reset()
ParallelBehaviour back in initial state,
besides calling reset() on each child behaviour
recursively.reset in class CompositeBehaviour