|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectsema.Agent.Action
Basic action of an agent. It provides a simple way to spread the execution of an action during simulated time.
In fact, the execution of a method is instantanious in the virtual world (necessary to disconnect virtual and real time, and to
allow agents to evolve simultanely). However, to be coherent from the point of view of the simulation, an action must so be divided into shorter steps.
The event is the smallest possible action to be executed by the engine.
An Action is a super event repeting itself, but before every call to an action method
(that is: step(), resumedStep() or firstStep()),
it checks whether it can execute. If not, the whenRefused() method will be called,
and the action will end (no more event will be executed from this action).
When an action is executing, the corresponding method will be called: firstStep() if it is the first event of the action,
step() if we are in the normal loop, and resumedStep() if it wakes up from a paused state.
You can pause (means: not executing any events or methods for this action) an action at anytime with pause(), but before pausing,
the action will call whenPaused() to prepare the pause.
You can resume an action with resume(). It will return false if failed to resume, that is if the action is ended after the resume attempt.
If a resume is done when the action was paused, resumedStep() is executed.
This encapsulation of actions provides an easy way to define behaviours.
The advantages of the action are the possibility to easily undertake several actions at the same time
for each agent and the automatic management of the parrallelism and steps.
Agent.registerAction(sema.Agent.Action),
Agent.unregisterAction(sema.Agent.Action)| Constructor Summary | |
Agent.Action()
|
|
Agent.Action(double t)
Creates a new action that will begin in t simulated units. |
|
| Method Summary | |
protected void |
close()
Closing method, always executed as the last code of an action that has begun. |
protected float |
firstStep()
Called at the begin of the action. |
boolean |
hasBegun()
Returns true if the action has begun. |
boolean |
isDisabled()
Returns true if the action has been definitively disabled, by the stop() method, because the action ended normally, or because it was refused by @link accepAction(Agent.Action). |
boolean |
isPaused()
Returns true if the action is currently paused. |
void |
pause()
Pauses the action, which can be resumed with resume().
|
void |
pause(double maxWaiting)
Pauses the action for at most the given delay. |
boolean |
resume()
Resumes an action previously paused. |
protected float |
resumedStep()
Called when the action is resumed. |
boolean |
start()
Starts the action 'immediatly' (from the agent point of view). |
boolean |
start(double t)
Starts the action in t simulated unit. |
protected float |
step()
Body of the action. |
void |
stop()
Stops the action and disables it. |
protected void |
whenEnd()
Called when a negative value has been returned by one of the step methods. |
protected void |
whenPaused()
Called when the action is paused. |
protected void |
whenRefused()
Called before stopping the action because it has been refused by Agent.acceptAction(Agent.Action). |
protected void |
whenStartInPause()
Called when the action is started with the start method, but was previously paused. |
protected void |
whenStopped()
Called when the action is going to be stopped, because of a call to the stop() method. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Agent.Action()
public Agent.Action(double t)
| Method Detail |
public final boolean start()
public final boolean start(double t)
public final boolean isDisabled()
public final boolean isPaused()
public final boolean hasBegun()
public final void pause()
resume().
The whenPaused() method is called before it is effectively paused.
public final void pause(double maxWaiting)
pause().public final void stop()
whenStopped() method is called.
public final boolean resume()
protected float firstStep()
step().
protected float resumedStep()
step().
protected void whenStartInPause()
protected void whenPaused()
protected void whenStopped()
close() method will be called after this one.
protected void whenRefused()
Agent.acceptAction(Agent.Action).
protected void whenEnd()
protected void close()
protected float step()
Typically, a moving agent that is walking would make a step towards a direction then another, and theses steps would be differents calls to step(). Internal variables should be stocked in the action to allow a good step by step execution.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||